aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Compress/PpmdDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Compress/PpmdDecoder.cpp46
1 files changed, 22 insertions, 24 deletions
diff --git a/CPP/7zip/Compress/PpmdDecoder.cpp b/CPP/7zip/Compress/PpmdDecoder.cpp
index 7f54ec3..1238df6 100644
--- a/CPP/7zip/Compress/PpmdDecoder.cpp
+++ b/CPP/7zip/Compress/PpmdDecoder.cpp
@@ -1,5 +1,4 @@
1// PpmdDecoder.cpp 1// PpmdDecoder.cpp
2// 2020-07-03 : Igor Pavlov : Public domain
3 2
4#include "StdAfx.h" 3#include "StdAfx.h"
5 4
@@ -29,14 +28,13 @@ CDecoder::~CDecoder()
29 Ppmd7_Free(&_ppmd, &g_BigAlloc); 28 Ppmd7_Free(&_ppmd, &g_BigAlloc);
30} 29}
31 30
32STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *props, UInt32 size) 31Z7_COM7F_IMF(CDecoder::SetDecoderProperties2(const Byte *props, UInt32 size))
33{ 32{
34 if (size < 5) 33 if (size < 5)
35 return E_INVALIDARG; 34 return E_INVALIDARG;
36 _order = props[0]; 35 _order = props[0];
37 UInt32 memSize = GetUi32(props + 1); 36 const UInt32 memSize = GetUi32(props + 1);
38 if ( 37 if (_order < PPMD7_MIN_ORDER ||
39 // _order < PPMD7_MIN_ORDER ||
40 _order > PPMD7_MAX_ORDER || 38 _order > PPMD7_MAX_ORDER ||
41 memSize < PPMD7_MIN_MEM_SIZE || 39 memSize < PPMD7_MIN_MEM_SIZE ||
42 memSize > PPMD7_MAX_MEM_SIZE) 40 memSize > PPMD7_MAX_MEM_SIZE)
@@ -48,7 +46,7 @@ STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *props, UInt32 size)
48 return S_OK; 46 return S_OK;
49} 47}
50 48
51#define _rangeDec _ppmd.rc.dec 49#define MY_rangeDec _ppmd.rc.dec
52 50
53#define CHECK_EXTRA_ERROR \ 51#define CHECK_EXTRA_ERROR \
54 if (_inStream.Extra) { \ 52 if (_inStream.Extra) { \
@@ -67,7 +65,7 @@ HRESULT CDecoder::CodeSpec(Byte *memStream, UInt32 size)
67 case kStatus_Error: return S_FALSE; 65 case kStatus_Error: return S_FALSE;
68 case kStatus_NeedInit: 66 case kStatus_NeedInit:
69 _inStream.Init(); 67 _inStream.Init();
70 if (!Ppmd7z_RangeDec_Init(&_rangeDec)) 68 if (!Ppmd7z_RangeDec_Init(&MY_rangeDec))
71 { 69 {
72 _status = kStatus_Error; 70 _status = kStatus_Error;
73 return (_res = S_FALSE); 71 return (_res = S_FALSE);
@@ -110,7 +108,7 @@ HRESULT CDecoder::CodeSpec(Byte *memStream, UInt32 size)
110 if (!FinishStream 108 if (!FinishStream
111 || !_outSizeDefined 109 || !_outSizeDefined
112 || _outSize != _processedSize 110 || _outSize != _processedSize
113 || _rangeDec.Code == 0) 111 || MY_rangeDec.Code == 0)
114 return S_OK; 112 return S_OK;
115 /* 113 /*
116 // We can decode additional End Marker here: 114 // We can decode additional End Marker here:
@@ -119,7 +117,7 @@ HRESULT CDecoder::CodeSpec(Byte *memStream, UInt32 size)
119 */ 117 */
120 } 118 }
121 119
122 if (sym != PPMD7_SYM_END || _rangeDec.Code != 0) 120 if (sym != PPMD7_SYM_END || MY_rangeDec.Code != 0)
123 { 121 {
124 _status = kStatus_Error; 122 _status = kStatus_Error;
125 return (_res = S_FALSE); 123 return (_res = S_FALSE);
@@ -131,8 +129,8 @@ HRESULT CDecoder::CodeSpec(Byte *memStream, UInt32 size)
131 129
132 130
133 131
134STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, 132Z7_COM7F_IMF(CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
135 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress) 133 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress))
136{ 134{
137 if (!_outBuf) 135 if (!_outBuf)
138 { 136 {
@@ -147,16 +145,16 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
147 do 145 do
148 { 146 {
149 const UInt64 startPos = _processedSize; 147 const UInt64 startPos = _processedSize;
150 HRESULT res = CodeSpec(_outBuf, kBufSize); 148 const HRESULT res = CodeSpec(_outBuf, kBufSize);
151 size_t processed = (size_t)(_processedSize - startPos); 149 const size_t processed = (size_t)(_processedSize - startPos);
152 RINOK(WriteStream(outStream, _outBuf, processed)); 150 RINOK(WriteStream(outStream, _outBuf, processed))
153 RINOK(res); 151 RINOK(res)
154 if (_status == kStatus_Finished_With_Mark) 152 if (_status == kStatus_Finished_With_Mark)
155 break; 153 break;
156 if (progress) 154 if (progress)
157 { 155 {
158 const UInt64 inProcessed = _inStream.GetProcessed(); 156 const UInt64 inProcessed = _inStream.GetProcessed();
159 RINOK(progress->SetRatioInfo(&inProcessed, &_processedSize)); 157 RINOK(progress->SetRatioInfo(&inProcessed, &_processedSize))
160 } 158 }
161 } 159 }
162 while (!_outSizeDefined || _processedSize < _outSize); 160 while (!_outSizeDefined || _processedSize < _outSize);
@@ -168,7 +166,7 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
168} 166}
169 167
170 168
171STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize) 169Z7_COM7F_IMF(CDecoder::SetOutStreamSize(const UInt64 *outSize))
172{ 170{
173 _outSizeDefined = (outSize != NULL); 171 _outSizeDefined = (outSize != NULL);
174 if (_outSizeDefined) 172 if (_outSizeDefined)
@@ -179,37 +177,37 @@ STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
179 return S_OK; 177 return S_OK;
180} 178}
181 179
182STDMETHODIMP CDecoder::SetFinishMode(UInt32 finishMode) 180Z7_COM7F_IMF(CDecoder::SetFinishMode(UInt32 finishMode))
183{ 181{
184 FinishStream = (finishMode != 0); 182 FinishStream = (finishMode != 0);
185 return S_OK; 183 return S_OK;
186} 184}
187 185
188STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) 186Z7_COM7F_IMF(CDecoder::GetInStreamProcessedSize(UInt64 *value))
189{ 187{
190 *value = _inStream.GetProcessed(); 188 *value = _inStream.GetProcessed();
191 return S_OK; 189 return S_OK;
192} 190}
193 191
194#ifndef NO_READ_FROM_CODER 192#ifndef Z7_NO_READ_FROM_CODER
195 193
196STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) 194Z7_COM7F_IMF(CDecoder::SetInStream(ISequentialInStream *inStream))
197{ 195{
198 InSeqStream = inStream; 196 InSeqStream = inStream;
199 _inStream.Stream = inStream; 197 _inStream.Stream = inStream;
200 return S_OK; 198 return S_OK;
201} 199}
202 200
203STDMETHODIMP CDecoder::ReleaseInStream() 201Z7_COM7F_IMF(CDecoder::ReleaseInStream())
204{ 202{
205 InSeqStream.Release(); 203 InSeqStream.Release();
206 return S_OK; 204 return S_OK;
207} 205}
208 206
209STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize) 207Z7_COM7F_IMF(CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize))
210{ 208{
211 const UInt64 startPos = _processedSize; 209 const UInt64 startPos = _processedSize;
212 HRESULT res = CodeSpec((Byte *)data, size); 210 const HRESULT res = CodeSpec((Byte *)data, size);
213 if (processedSize) 211 if (processedSize)
214 *processedSize = (UInt32)(_processedSize - startPos); 212 *processedSize = (UInt32)(_processedSize - startPos);
215 return res; 213 return res;