aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Compress/Rar2Decoder.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Compress/Rar2Decoder.h103
1 files changed, 25 insertions, 78 deletions
diff --git a/CPP/7zip/Compress/Rar2Decoder.h b/CPP/7zip/Compress/Rar2Decoder.h
index d77bfc1..c9ddedb 100644
--- a/CPP/7zip/Compress/Rar2Decoder.h
+++ b/CPP/7zip/Compress/Rar2Decoder.h
@@ -18,59 +18,16 @@
18namespace NCompress { 18namespace NCompress {
19namespace NRar2 { 19namespace NRar2 {
20 20
21const unsigned kNumRepDists = 4; 21const unsigned kNumReps = 4;
22const unsigned kDistTableSize = 48; 22const unsigned kDistTableSize = 48;
23 23const unsigned kNumLen2Symbols = 8;
24const unsigned kMMTableSize = 256 + 1; 24const unsigned kLenTableSize = 28;
25 25const unsigned kMainTableSize = 256 + 2 + kNumReps + kNumLen2Symbols + kLenTableSize;
26const UInt32 kMainTableSize = 298; 26const unsigned kHeapTablesSizesSum = kMainTableSize + kDistTableSize + kLenTableSize;
27const UInt32 kLenTableSize = 28; 27const unsigned k_MM_TableSize = 256 + 1;
28 28const unsigned k_MM_NumChanelsMax = 4;
29const UInt32 kDistTableStart = kMainTableSize; 29const unsigned k_MM_TablesSizesSum = k_MM_TableSize * k_MM_NumChanelsMax;
30const UInt32 kLenTableStart = kDistTableStart + kDistTableSize; 30const unsigned kMaxTableSize = k_MM_TablesSizesSum;
31
32const UInt32 kHeapTablesSizesSum = kMainTableSize + kDistTableSize + kLenTableSize;
33
34const UInt32 kLevelTableSize = 19;
35
36const UInt32 kMMTablesSizesSum = kMMTableSize * 4;
37
38const UInt32 kMaxTableSize = kMMTablesSizesSum;
39
40const UInt32 kTableDirectLevels = 16;
41const UInt32 kTableLevelRepNumber = kTableDirectLevels;
42const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
43const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
44
45const UInt32 kLevelMask = 0xF;
46
47
48const UInt32 kRepBothNumber = 256;
49const UInt32 kRepNumber = kRepBothNumber + 1;
50const UInt32 kLen2Number = kRepNumber + 4;
51
52const UInt32 kLen2NumNumbers = 8;
53const UInt32 kReadTableNumber = kLen2Number + kLen2NumNumbers;
54const UInt32 kMatchNumber = kReadTableNumber + 1;
55
56const Byte kLenStart [kLenTableSize] = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224};
57const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5};
58
59const UInt32 kDistStart [kDistTableSize] = {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768U,49152U,65536,98304,131072,196608,262144,327680,393216,458752,524288,589824,655360,720896,786432,851968,917504,983040};
60const Byte kDistDirectBits[kDistTableSize] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
61
62const Byte kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
63
64const Byte kLen2DistStarts[kLen2NumNumbers]={0,4,8,16,32,64,128,192};
65const Byte kLen2DistDirectBits[kLen2NumNumbers]={2,2,3, 4, 5, 6, 6, 6};
66
67const UInt32 kDistLimit2 = 0x101 - 1;
68const UInt32 kDistLimit3 = 0x2000 - 1;
69const UInt32 kDistLimit4 = 0x40000 - 1;
70
71const UInt32 kMatchMaxLen = 255 + 2;
72const UInt32 kMatchMaxLenMax = 255 + 5;
73const UInt32 kNormalMatchMinLen = 3;
74 31
75namespace NMultimedia { 32namespace NMultimedia {
76 33
@@ -83,18 +40,13 @@ struct CFilter
83 UInt32 ByteCount; 40 UInt32 ByteCount;
84 int LastChar; 41 int LastChar;
85 42
86 Byte Decode(int &channelDelta, Byte delta);
87
88 void Init() { memset(this, 0, sizeof(*this)); } 43 void Init() { memset(this, 0, sizeof(*this)); }
89 44 Byte Decode(int &channelDelta, Byte delta);
90}; 45};
91 46
92const unsigned kNumChanelsMax = 4; 47struct CFilter2
93
94class CFilter2
95{ 48{
96public: 49 CFilter m_Filters[k_MM_NumChanelsMax];
97 CFilter m_Filters[kNumChanelsMax];
98 int m_ChannelDelta; 50 int m_ChannelDelta;
99 unsigned CurrentChannel; 51 unsigned CurrentChannel;
100 52
@@ -103,47 +55,42 @@ public:
103 { 55 {
104 return m_Filters[CurrentChannel].Decode(m_ChannelDelta, delta); 56 return m_Filters[CurrentChannel].Decode(m_ChannelDelta, delta);
105 } 57 }
106
107}; 58};
108 59
109} 60}
110 61
111typedef NBitm::CDecoder<CInBuffer> CBitDecoder; 62typedef NBitm::CDecoder<CInBuffer> CBitDecoder;
112 63
113const unsigned kNumHuffmanBits = 15; 64const unsigned kNumHufBits = 15;
114 65
115Z7_CLASS_IMP_NOQIB_2( 66Z7_CLASS_IMP_NOQIB_2(
116 CDecoder 67 CDecoder
117 , ICompressCoder 68 , ICompressCoder
118 , ICompressSetDecoderProperties2 69 , ICompressSetDecoderProperties2
119) 70)
71 bool _isSolid;
72 bool _solidAllowed;
73 bool m_TablesOK;
74 bool m_AudioMode;
75
120 CLzOutWindow m_OutWindowStream; 76 CLzOutWindow m_OutWindowStream;
121 CBitDecoder m_InBitStream; 77 CBitDecoder m_InBitStream;
122 78
123 UInt32 m_RepDistPtr; 79 UInt32 m_RepDistPtr;
124 UInt32 m_RepDists[kNumRepDists]; 80 UInt32 m_RepDists[kNumReps];
125
126 UInt32 m_LastLength; 81 UInt32 m_LastLength;
82 unsigned m_NumChannels;
127 83
128 bool _isSolid; 84 NHuffman::CDecoder<kNumHufBits, kMainTableSize, 9> m_MainDecoder;
129 bool _solidAllowed; 85 NHuffman::CDecoder256<kNumHufBits, kDistTableSize, 7> m_DistDecoder;
130 bool m_TablesOK; 86 NHuffman::CDecoder256<kNumHufBits, kLenTableSize, 7> m_LenDecoder;
131 bool m_AudioMode; 87 NHuffman::CDecoder<kNumHufBits, k_MM_TableSize, 9> m_MMDecoders[k_MM_NumChanelsMax];
132
133 NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
134 NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder;
135 NHuffman::CDecoder<kNumHuffmanBits, kLenTableSize> m_LenDecoder;
136 NHuffman::CDecoder<kNumHuffmanBits, kMMTableSize> m_MMDecoders[NMultimedia::kNumChanelsMax];
137 NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
138 88
139 UInt64 m_PackSize; 89 UInt64 m_PackSize;
140 90
141 unsigned m_NumChannels;
142 NMultimedia::CFilter2 m_MmFilter; 91 NMultimedia::CFilter2 m_MmFilter;
143
144 Byte m_LastLevels[kMaxTableSize]; 92 Byte m_LastLevels[kMaxTableSize];
145 93
146
147 void InitStructures(); 94 void InitStructures();
148 UInt32 ReadBits(unsigned numBits); 95 UInt32 ReadBits(unsigned numBits);
149 bool ReadTables(); 96 bool ReadTables();