1 // ImplodeDecoder.h
2 
3 #ifndef __COMPRESS_IMPLODE_DECODER_H
4 #define __COMPRESS_IMPLODE_DECODER_H
5 
6 #include "../../Common/MyCom.h"
7 
8 #include "../ICoder.h"
9 
10 #include "../Common/InBuffer.h"
11 
12 #include "BitlDecoder.h"
13 #include "LzOutWindow.h"
14 
15 namespace NCompress {
16 namespace NImplode {
17 namespace NDecoder {
18 
19 typedef NBitl::CDecoder<CInBuffer> CInBit;
20 
21 const unsigned kNumHuffmanBits = 16;
22 const unsigned kMaxHuffTableSize = 1 << 8;
23 
24 class CHuffmanDecoder
25 {
26   UInt32 _limits[kNumHuffmanBits + 1];
27   UInt32 _poses[kNumHuffmanBits + 1];
28   Byte _symbols[kMaxHuffTableSize];
29 public:
30   bool Build(const Byte *lens, unsigned numSymbols) throw();
31   UInt32 Decode(CInBit *inStream) const throw();
32 };
33 
34 
35 class CCoder:
36   public ICompressCoder,
37   public ICompressSetDecoderProperties2,
38   public ICompressSetFinishMode,
39   public ICompressGetInStreamProcessedSize,
40   public CMyUnknownImp
41 {
42   CLzOutWindow _outWindowStream;
43   CInBit _inBitStream;
44 
45   CHuffmanDecoder _litDecoder;
46   CHuffmanDecoder _lenDecoder;
47   CHuffmanDecoder _distDecoder;
48 
49   Byte _flags;
50   bool _fullStreamMode;
51 
52   bool BuildHuff(CHuffmanDecoder &table, unsigned numSymbols);
53   HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
54       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
55 
56 public:
57   MY_UNKNOWN_IMP3(
58       ICompressSetDecoderProperties2,
59       ICompressSetFinishMode,
60       ICompressGetInStreamProcessedSize)
61 
62   STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
63       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
64   STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
65   STDMETHOD(SetFinishMode)(UInt32 finishMode);
66   STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
67 
68   CCoder();
69 };
70 
71 }}}
72 
73 #endif
74