aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Compress/PpmdZip.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Compress/PpmdZip.cpp')
-rw-r--r--CPP/7zip/Compress/PpmdZip.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/CPP/7zip/Compress/PpmdZip.cpp b/CPP/7zip/Compress/PpmdZip.cpp
index 434e143..5039131 100644
--- a/CPP/7zip/Compress/PpmdZip.cpp
+++ b/CPP/7zip/Compress/PpmdZip.cpp
@@ -24,8 +24,8 @@ CDecoder::~CDecoder()
24 Ppmd8_Free(&_ppmd, &g_BigAlloc); 24 Ppmd8_Free(&_ppmd, &g_BigAlloc);
25} 25}
26 26
27STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, 27Z7_COM7F_IMF(CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
28 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress) 28 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress))
29{ 29{
30 // try { 30 // try {
31 31
@@ -44,10 +44,10 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
44 if (_inStream.Extra) 44 if (_inStream.Extra)
45 return S_FALSE; 45 return S_FALSE;
46 46
47 UInt32 val = GetUi16(buf); 47 const UInt32 val = GetUi16(buf);
48 unsigned order = (val & 0xF) + 1; 48 const unsigned order = (val & 0xF) + 1;
49 UInt32 mem = ((val >> 4) & 0xFF) + 1; 49 const UInt32 mem = ((val >> 4) & 0xFF) + 1;
50 unsigned restor = (val >> 12); 50 const unsigned restor = (val >> 12);
51 if (order < 2 || restor > 2) 51 if (order < 2 || restor > 2)
52 return S_FALSE; 52 return S_FALSE;
53 53
@@ -94,12 +94,12 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
94 } 94 }
95 while (buf != lim); 95 while (buf != lim);
96 96
97 size_t cur = (size_t)(buf - _outStream.Buf); 97 const size_t cur = (size_t)(buf - _outStream.Buf);
98 processedSize += cur; 98 processedSize += cur;
99 99
100 RINOK(WriteStream(outStream, _outStream.Buf, cur)); 100 RINOK(WriteStream(outStream, _outStream.Buf, cur))
101 101
102 RINOK(_inStream.Res); 102 RINOK(_inStream.Res)
103 if (_inStream.Extra) 103 if (_inStream.Extra)
104 return S_FALSE; 104 return S_FALSE;
105 105
@@ -114,18 +114,18 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
114 if (progress) 114 if (progress)
115 { 115 {
116 const UInt64 inProccessed = _inStream.GetProcessed(); 116 const UInt64 inProccessed = _inStream.GetProcessed();
117 RINOK(progress->SetRatioInfo(&inProccessed, &processedSize)); 117 RINOK(progress->SetRatioInfo(&inProccessed, &processedSize))
118 } 118 }
119 } 119 }
120 120
121 RINOK(_inStream.Res); 121 RINOK(_inStream.Res)
122 122
123 if (_fullFileMode) 123 if (_fullFileMode)
124 { 124 {
125 if (!wasFinished) 125 if (!wasFinished)
126 { 126 {
127 int res = Ppmd8_DecodeSymbol(&_ppmd); 127 const int res = Ppmd8_DecodeSymbol(&_ppmd);
128 RINOK(_inStream.Res); 128 RINOK(_inStream.Res)
129 if (_inStream.Extra || res != -1) 129 if (_inStream.Extra || res != -1)
130 return S_FALSE; 130 return S_FALSE;
131 } 131 }
@@ -142,13 +142,13 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
142} 142}
143 143
144 144
145STDMETHODIMP CDecoder::SetFinishMode(UInt32 finishMode) 145Z7_COM7F_IMF(CDecoder::SetFinishMode(UInt32 finishMode))
146{ 146{
147 _fullFileMode = (finishMode != 0); 147 _fullFileMode = (finishMode != 0);
148 return S_OK; 148 return S_OK;
149} 149}
150 150
151STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) 151Z7_COM7F_IMF(CDecoder::GetInStreamProcessedSize(UInt64 *value))
152{ 152{
153 *value = _inStream.GetProcessed(); 153 *value = _inStream.GetProcessed();
154 return S_OK; 154 return S_OK;
@@ -184,14 +184,14 @@ CEncoder::~CEncoder()
184 Ppmd8_Free(&_ppmd, &g_BigAlloc); 184 Ppmd8_Free(&_ppmd, &g_BigAlloc);
185} 185}
186 186
187STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps) 187Z7_COM7F_IMF(CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps))
188{ 188{
189 int level = -1; 189 int level = -1;
190 CEncProps props; 190 CEncProps props;
191 for (UInt32 i = 0; i < numProps; i++) 191 for (UInt32 i = 0; i < numProps; i++)
192 { 192 {
193 const PROPVARIANT &prop = coderProps[i]; 193 const PROPVARIANT &prop = coderProps[i];
194 PROPID propID = propIDs[i]; 194 const PROPID propID = propIDs[i];
195 if (propID > NCoderPropID::kReduceSize) 195 if (propID > NCoderPropID::kReduceSize)
196 continue; 196 continue;
197 if (propID == NCoderPropID::kReduceSize) 197 if (propID == NCoderPropID::kReduceSize)
@@ -203,7 +203,7 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIA
203 } 203 }
204 if (prop.vt != VT_UI4) 204 if (prop.vt != VT_UI4)
205 return E_INVALIDARG; 205 return E_INVALIDARG;
206 UInt32 v = (UInt32)prop.ulVal; 206 const UInt32 v = (UInt32)prop.ulVal;
207 switch (propID) 207 switch (propID)
208 { 208 {
209 case NCoderPropID::kUsedMemorySize: 209 case NCoderPropID::kUsedMemorySize:
@@ -238,8 +238,8 @@ CEncoder::CEncoder()
238 Ppmd8_Construct(&_ppmd); 238 Ppmd8_Construct(&_ppmd);
239} 239}
240 240
241STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, 241Z7_COM7F_IMF(CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
242 const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress) 242 const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress))
243{ 243{
244 if (!_inStream.Alloc()) 244 if (!_inStream.Alloc())
245 return E_OUTOFMEMORY; 245 return E_OUTOFMEMORY;
@@ -251,21 +251,21 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream
251 _outStream.Stream = outStream; 251 _outStream.Stream = outStream;
252 _outStream.Init(); 252 _outStream.Init();
253 253
254 Ppmd8_Init_RangeEnc(&_ppmd); 254 Ppmd8_Init_RangeEnc(&_ppmd)
255 Ppmd8_Init(&_ppmd, (unsigned)_props.Order, (unsigned)_props.Restor); 255 Ppmd8_Init(&_ppmd, (unsigned)_props.Order, (unsigned)_props.Restor);
256 256
257 { 257 {
258 UInt32 val = (UInt32)(((unsigned)_props.Order - 1) + ((_props.MemSizeMB - 1) << 4) + ((unsigned)_props.Restor << 12)); 258 const UInt32 val = (UInt32)(((unsigned)_props.Order - 1) + ((_props.MemSizeMB - 1) << 4) + ((unsigned)_props.Restor << 12));
259 _outStream.WriteByte((Byte)(val & 0xFF)); 259 _outStream.WriteByte((Byte)(val & 0xFF));
260 _outStream.WriteByte((Byte)(val >> 8)); 260 _outStream.WriteByte((Byte)(val >> 8));
261 } 261 }
262 RINOK(_outStream.Res); 262 RINOK(_outStream.Res)
263 263
264 UInt64 processed = 0; 264 UInt64 processed = 0;
265 for (;;) 265 for (;;)
266 { 266 {
267 UInt32 size; 267 UInt32 size;
268 RINOK(inStream->Read(_inStream.Buf, kBufSize, &size)); 268 RINOK(inStream->Read(_inStream.Buf, kBufSize, &size))
269 if (size == 0) 269 if (size == 0)
270 { 270 {
271 Ppmd8_EncodeSymbol(&_ppmd, -1); 271 Ppmd8_EncodeSymbol(&_ppmd, -1);
@@ -284,12 +284,12 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream
284 } 284 }
285 while (++buf != lim); 285 while (++buf != lim);
286 286
287 RINOK(_outStream.Res); 287 RINOK(_outStream.Res)
288 288
289 if (progress) 289 if (progress)
290 { 290 {
291 const UInt64 outProccessed = _outStream.GetProcessed(); 291 const UInt64 outProccessed = _outStream.GetProcessed();
292 RINOK(progress->SetRatioInfo(&processed, &outProccessed)); 292 RINOK(progress->SetRatioInfo(&processed, &outProccessed))
293 } 293 }
294 } 294 }
295} 295}