aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Compress/Rar3Decoder.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Compress/Rar3Decoder.h66
1 files changed, 37 insertions, 29 deletions
diff --git a/CPP/7zip/Compress/Rar3Decoder.h b/CPP/7zip/Compress/Rar3Decoder.h
index 4711052..48fc212 100644
--- a/CPP/7zip/Compress/Rar3Decoder.h
+++ b/CPP/7zip/Compress/Rar3Decoder.h
@@ -22,21 +22,21 @@
22namespace NCompress { 22namespace NCompress {
23namespace NRar3 { 23namespace NRar3 {
24 24
25const unsigned kNumHuffmanBits = 15;
26
25const UInt32 kWindowSize = 1 << 22; 27const UInt32 kWindowSize = 1 << 22;
26const UInt32 kWindowMask = (kWindowSize - 1); 28const UInt32 kWindowMask = kWindowSize - 1;
27 29
28const UInt32 kNumReps = 4; 30const unsigned kNumReps = 4;
29const UInt32 kNumLen2Symbols = 8; 31const unsigned kNumLen2Symbols = 8;
30const UInt32 kLenTableSize = 28; 32const unsigned kLenTableSize = 28;
31const UInt32 kMainTableSize = 256 + 1 + 1 + 1 + kNumReps + kNumLen2Symbols + kLenTableSize; 33const unsigned kMainTableSize = 256 + 3 + kNumReps + kNumLen2Symbols + kLenTableSize;
32const UInt32 kDistTableSize = 60; 34const unsigned kDistTableSize = 60;
33 35
34const unsigned kNumAlignBits = 4; 36const unsigned kNumAlignBits = 4;
35const UInt32 kAlignTableSize = (1 << kNumAlignBits) + 1; 37const unsigned kAlignTableSize = (1 << kNumAlignBits) + 1;
36 38
37const UInt32 kLevelTableSize = 20; 39const unsigned kTablesSizesSum = kMainTableSize + kDistTableSize + kAlignTableSize + kLenTableSize;
38
39const UInt32 kTablesSizesSum = kMainTableSize + kDistTableSize + kAlignTableSize + kLenTableSize;
40 40
41class CBitDecoder 41class CBitDecoder
42{ 42{
@@ -68,6 +68,7 @@ public:
68 _value = _value & ((1 << _bitPos) - 1); 68 _value = _value & ((1 << _bitPos) - 1);
69 } 69 }
70 70
71 Z7_FORCE_INLINE
71 UInt32 GetValue(unsigned numBits) 72 UInt32 GetValue(unsigned numBits)
72 { 73 {
73 if (_bitPos < numBits) 74 if (_bitPos < numBits)
@@ -82,7 +83,15 @@ public:
82 } 83 }
83 return _value >> (_bitPos - numBits); 84 return _value >> (_bitPos - numBits);
84 } 85 }
86
87 Z7_FORCE_INLINE
88 UInt32 GetValue_InHigh32bits()
89 {
90 return GetValue(kNumHuffmanBits) << (32 - kNumHuffmanBits);
91 }
92
85 93
94 Z7_FORCE_INLINE
86 void MovePos(unsigned numBits) 95 void MovePos(unsigned numBits)
87 { 96 {
88 _bitPos -= numBits; 97 _bitPos -= numBits;
@@ -91,7 +100,7 @@ public:
91 100
92 UInt32 ReadBits(unsigned numBits) 101 UInt32 ReadBits(unsigned numBits)
93 { 102 {
94 UInt32 res = GetValue(numBits); 103 const UInt32 res = GetValue(numBits);
95 MovePos(numBits); 104 MovePos(numBits);
96 return res; 105 return res;
97 } 106 }
@@ -104,7 +113,7 @@ public:
104 _value = (_value << 8) | Stream.ReadByte(); 113 _value = (_value << 8) | Stream.ReadByte();
105 } 114 }
106 _bitPos -= numBits; 115 _bitPos -= numBits;
107 UInt32 res = _value >> _bitPos; 116 const UInt32 res = _value >> _bitPos;
108 _value = _value & ((1 << _bitPos) - 1); 117 _value = _value & ((1 << _bitPos) - 1);
109 return res; 118 return res;
110 } 119 }
@@ -113,8 +122,8 @@ public:
113 { 122 {
114 if (_bitPos == 0) 123 if (_bitPos == 0)
115 return Stream.ReadByte(); 124 return Stream.ReadByte();
116 unsigned bitsPos = _bitPos - 8; 125 const unsigned bitsPos = _bitPos - 8;
117 Byte b = (Byte)(_value >> bitsPos); 126 const Byte b = (Byte)(_value >> bitsPos);
118 _value = _value & ((1 << bitsPos) - 1); 127 _value = _value & ((1 << bitsPos) - 1);
119 _bitPos = bitsPos; 128 _bitPos = bitsPos;
120 return b; 129 return b;
@@ -154,13 +163,19 @@ struct CTempFilter: public NVm::CProgramInitState
154 } 163 }
155}; 164};
156 165
157const unsigned kNumHuffmanBits = 15;
158 166
159Z7_CLASS_IMP_NOQIB_2( 167Z7_CLASS_IMP_NOQIB_2(
160 CDecoder 168 CDecoder
161 , ICompressCoder 169 , ICompressCoder
162 , ICompressSetDecoderProperties2 170 , ICompressSetDecoderProperties2
163) 171)
172 bool _isSolid;
173 bool _solidAllowed;
174 // bool _errorMode;
175
176 bool _lzMode;
177 bool _unsupportedFilter;
178
164 CByteIn m_InBitStream; 179 CByteIn m_InBitStream;
165 Byte *_window; 180 Byte *_window;
166 UInt32 _winPos; 181 UInt32 _winPos;
@@ -169,12 +184,12 @@ Z7_CLASS_IMP_NOQIB_2(
169 UInt64 _unpackSize; 184 UInt64 _unpackSize;
170 UInt64 _writtenFileSize; // if it's > _unpackSize, then _unpackSize only written 185 UInt64 _writtenFileSize; // if it's > _unpackSize, then _unpackSize only written
171 ISequentialOutStream *_outStream; 186 ISequentialOutStream *_outStream;
172 NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder; 187
188 NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize, 9> m_MainDecoder;
173 UInt32 kDistStart[kDistTableSize]; 189 UInt32 kDistStart[kDistTableSize];
174 NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder; 190 NHuffman::CDecoder256<kNumHuffmanBits, kDistTableSize, 7> m_DistDecoder;
175 NHuffman::CDecoder<kNumHuffmanBits, kAlignTableSize> m_AlignDecoder; 191 NHuffman::CDecoder256<kNumHuffmanBits, kAlignTableSize, 6> m_AlignDecoder;
176 NHuffman::CDecoder<kNumHuffmanBits, kLenTableSize> m_LenDecoder; 192 NHuffman::CDecoder256<kNumHuffmanBits, kLenTableSize, 7> m_LenDecoder;
177 NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
178 193
179 UInt32 _reps[kNumReps]; 194 UInt32 _reps[kNumReps];
180 UInt32 _lastLength; 195 UInt32 _lastLength;
@@ -189,22 +204,15 @@ Z7_CLASS_IMP_NOQIB_2(
189 unsigned _numEmptyTempFilters; 204 unsigned _numEmptyTempFilters;
190 UInt32 _lastFilter; 205 UInt32 _lastFilter;
191 206
192 bool _isSolid;
193 bool _solidAllowed;
194 // bool _errorMode;
195
196 bool _lzMode;
197 bool _unsupportedFilter;
198
199 UInt32 PrevAlignBits; 207 UInt32 PrevAlignBits;
200 UInt32 PrevAlignCount; 208 UInt32 PrevAlignCount;
201 209
202 bool TablesRead; 210 bool TablesRead;
203 bool TablesOK; 211 bool TablesOK;
212 bool PpmError;
204 213
205 CPpmd7 _ppmd;
206 int PpmEscChar; 214 int PpmEscChar;
207 bool PpmError; 215 CPpmd7 _ppmd;
208 216
209 HRESULT WriteDataToStream(const Byte *data, UInt32 size); 217 HRESULT WriteDataToStream(const Byte *data, UInt32 size);
210 HRESULT WriteData(const Byte *data, UInt32 size); 218 HRESULT WriteData(const Byte *data, UInt32 size);