xref: /aosp_15_r20/external/lzma/CPP/7zip/Compress/LzhDecoder.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // LzhDecoder.h
2 
3 #ifndef ZIP7_INC_COMPRESS_LZH_DECODER_H
4 #define ZIP7_INC_COMPRESS_LZH_DECODER_H
5 
6 #include "../../Common/MyCom.h"
7 
8 #include "../ICoder.h"
9 
10 #include "../Common/InBuffer.h"
11 
12 #include "BitmDecoder.h"
13 #include "HuffmanDecoder.h"
14 #include "LzOutWindow.h"
15 
16 namespace NCompress {
17 namespace NLzh {
18 namespace NDecoder {
19 
20 const unsigned kMatchMinLen = 3;
21 const unsigned kMatchMaxLen = 256;
22 const unsigned NC = 256 + kMatchMaxLen - kMatchMinLen + 1;
23 const unsigned NUM_CODE_BITS = 16;
24 const unsigned NUM_DIC_BITS_MAX = 25;
25 const unsigned NT = NUM_CODE_BITS + 3;
26 const unsigned NP = NUM_DIC_BITS_MAX + 1;
27 const unsigned NPT = NP; // Max(NT, NP)
28 
29 class CCoder
30 {
31   CLzOutWindow _outWindow;
32   NBitm::CDecoder<CInBuffer> _inBitStream;
33 
34   int _symbolT;
35   int _symbolC;
36   UInt32 DictSize;
37   // bool FinishMode;
38 
39   NHuffman::CDecoder256<NUM_CODE_BITS, NPT, 7> _decoderT;
40   NHuffman::CDecoder<NUM_CODE_BITS, NC, 10> _decoderC;
41 
42   class CCoderReleaser
43   {
44     CCoder *_coder;
45   public:
CCoderReleaser(CCoder * coder)46     CCoderReleaser(CCoder *coder): _coder(coder) {}
Disable()47     void Disable() { _coder = NULL; }
~CCoderReleaser()48     ~CCoderReleaser() { if (_coder) _coder->_outWindow.Flush(); }
49   };
50   friend class CCoderReleaser;
51 
52   bool ReadTP(unsigned num, unsigned numBits, int spec);
53   bool ReadC();
54 
55   HRESULT CodeReal(UInt32 outSize, ICompressProgressInfo *progress);
56 public:
CCoder()57   CCoder(): DictSize(1 << 16)
58       // , FinishMode(true)
59       {}
SetDictSize(UInt32 dictSize)60   void SetDictSize(UInt32 dictSize) { DictSize = dictSize; }
GetInputProcessedSize()61   UInt64 GetInputProcessedSize() const { return _inBitStream.GetProcessedSize(); }
62   HRESULT Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
63       UInt32 outSize, ICompressProgressInfo *progress);
64 };
65 
66 }}}
67 
68 #endif
69