xref: /aosp_15_r20/external/lzma/CPP/7zip/Compress/QuantumDecoder.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // QuantumDecoder.h
2 
3 #ifndef ZIP7_INC_COMPRESS_QUANTUM_DECODER_H
4 #define ZIP7_INC_COMPRESS_QUANTUM_DECODER_H
5 
6 #include "../../Common/MyTypes.h"
7 
8 namespace NCompress {
9 namespace NQuantum {
10 
11 const unsigned kNumLitSelectorBits = 2;
12 const unsigned kNumLitSelectors = 1 << kNumLitSelectorBits;
13 const unsigned kNumLitSymbols = 1 << (8 - kNumLitSelectorBits);
14 const unsigned kNumMatchSelectors = 3;
15 const unsigned kNumSelectors = kNumLitSelectors + kNumMatchSelectors;
16 const unsigned kNumSymbolsMax = kNumLitSymbols; // 64
17 
18 class CRangeDecoder;
19 
20 class CModelDecoder
21 {
22   unsigned NumItems;
23   unsigned ReorderCount;
24   Byte Vals[kNumSymbolsMax];
25   UInt16 Freqs[kNumSymbolsMax + 1];
26 public:
27   Byte _pad[64 - 10]; // for structure size alignment
28 
29   void Init(unsigned numItems, unsigned startVal);
30   unsigned Decode(CRangeDecoder *rc);
31 };
32 
33 
34 class CDecoder
35 {
36   UInt32 _winSize;
37   UInt32 _winPos;
38   UInt32 _winSize_allocated;
39   bool _overWin;
40   Byte *_win;
41   unsigned _numDictBits;
42 
43   CModelDecoder m_Selector;
44   CModelDecoder m_Literals[kNumLitSelectors];
45   CModelDecoder m_PosSlot[kNumMatchSelectors];
46   CModelDecoder m_LenSlot;
47 
48   void Init();
49   HRESULT CodeSpec(const Byte *inData, size_t inSize, UInt32 outSize);
50 public:
51   HRESULT Code(const Byte *inData, size_t inSize, UInt32 outSize, bool keepHistory);
52   HRESULT SetParams(unsigned numDictBits);
53 
CDecoder()54   CDecoder(): _win(NULL), _numDictBits(0) {}
GetDataPtr()55   const Byte * GetDataPtr() const { return _win + _winPos; }
56 };
57 
58 }}
59 
60 #endif
61