xref: /aosp_15_r20/external/lzma/CPP/7zip/Compress/Rar5Decoder.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // Rar5Decoder.h
2 // According to unRAR license, this code may not be used to develop
3 // a program that creates RAR archives
4 
5 #ifndef ZIP7_INC_COMPRESS_RAR5_DECODER_H
6 #define ZIP7_INC_COMPRESS_RAR5_DECODER_H
7 
8 #include "../../Common/MyBuffer2.h"
9 #include "../../Common/MyCom.h"
10 
11 #include "../ICoder.h"
12 
13 #include "HuffmanDecoder.h"
14 
15 namespace NCompress {
16 namespace NRar5 {
17 
18 class CBitDecoder;
19 
20 struct CFilter
21 {
22   Byte Type;
23   Byte Channels;
24   UInt32 Size;
25   UInt64 Start;
26 };
27 
28 
29 const unsigned kNumReps = 4;
30 const unsigned kLenTableSize = 11 * 4;
31 const unsigned kMainTableSize = 256 + 1 + 1 + kNumReps + kLenTableSize;
32 const unsigned kExtraDistSymbols_v7 = 16;
33 const unsigned kDistTableSize_v6 = 64;
34 const unsigned kDistTableSize_MAX = 64 + kExtraDistSymbols_v7;
35 const unsigned kNumAlignBits = 4;
36 const unsigned kAlignTableSize = 1 << kNumAlignBits;
37 
38 const unsigned kNumHufBits = 15;
39 
40 const unsigned k_NumHufTableBits_Main = 10;
41 const unsigned k_NumHufTableBits_Dist = 7;
42 const unsigned k_NumHufTableBits_Len = 7;
43 const unsigned k_NumHufTableBits_Align = 6;
44 
45 const unsigned DICT_SIZE_BITS_MAX = 40;
46 
47 Z7_CLASS_IMP_NOQIB_2(
48   CDecoder
49   , ICompressCoder
50   , ICompressSetDecoderProperties2
51 )
52   bool _useAlignBits;
53   bool _isLastBlock;
54   bool _unpackSize_Defined;
55   // bool _packSize_Defined;
56 
57   bool _unsupportedFilter;
58   Byte _lzError;
59   bool _writeError;
60 
61   bool _isSolid;
62   // bool _solidAllowed;
63   bool _is_v7;
64   bool _tableWasFilled;
65   bool _wasInit;
66 
67   Byte _exitType;
68 
69   // Byte _dictSizeLog;
70   size_t _dictSize;
71   Byte *_window;
72   size_t _winPos;
73   size_t _winSize;
74   size_t _dictSize_forCheck;
75   size_t _limit;
76   const Byte *_buf_Res;
77   UInt64 _lzSize;
78   size_t _reps[kNumReps];
79   unsigned _bitPos_Res;
80   UInt32 _lastLen;
81 
82   // unsigned _numCorrectDistSymbols;
83   unsigned _numUnusedFilters;
84   unsigned _numFilters;
85 
86   UInt64 _lzWritten;
87   UInt64 _lzFileStart;
88   UInt64 _unpackSize;
89   // UInt64 _packSize;
90   UInt64 _lzEnd;
91   UInt64 _writtenFileSize;
92   UInt64 _filterEnd;
93   UInt64 _progress_Pack;
94   UInt64 _progress_Unpack;
95   CAlignedBuffer _filterSrc;
96   CAlignedBuffer _filterDst;
97 
98   CFilter *_filters;
99   size_t _winSize_Allocated;
100   ISequentialInStream *_inStream;
101   ISequentialOutStream *_outStream;
102   ICompressProgressInfo *_progress;
103   Byte *_inputBuf;
104 
105   NHuffman::CDecoder<kNumHufBits, kMainTableSize,  k_NumHufTableBits_Main>  m_MainDecoder;
106   NHuffman::CDecoder256<kNumHufBits, kDistTableSize_MAX,  k_NumHufTableBits_Dist>  m_DistDecoder;
107   NHuffman::CDecoder256<kNumHufBits, kAlignTableSize,     k_NumHufTableBits_Align> m_AlignDecoder;
108   NHuffman::CDecoder256<kNumHufBits, kLenTableSize,       k_NumHufTableBits_Len>   m_LenDecoder;
109   Byte m_LenPlusTable[DICT_SIZE_BITS_MAX];
110 
InitFilters()111   void InitFilters()
112   {
113     _numUnusedFilters = 0;
114     _numFilters = 0;
115   }
116   void DeleteUnusedFilters();
117   HRESULT WriteData(const Byte *data, size_t size);
118   HRESULT ExecuteFilter(const CFilter &f);
119   HRESULT WriteBuf();
120   HRESULT AddFilter(CBitDecoder &_bitStream);
121   HRESULT ReadTables(CBitDecoder &_bitStream);
122   HRESULT DecodeLZ2(const CBitDecoder &_bitStream) throw();
123   HRESULT DecodeLZ();
124   HRESULT CodeReal();
125 public:
126   CDecoder();
127   ~CDecoder();
128 };
129 
130 }}
131 
132 #endif
133