Mercurial > vba-linux
comparison src/win32/7zip/7z/CPP/7zip/Compress/LzhDecoder.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // LzhDecoder.h | |
2 | |
3 #ifndef __COMPRESS_LZH_DECODER_H | |
4 #define __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 int kMaxHuffmanLen = 16; // Check it | |
21 | |
22 const int kNumSpecLevelSymbols = 3; | |
23 const int kNumLevelSymbols = kNumSpecLevelSymbols + kMaxHuffmanLen; | |
24 | |
25 const int kDictBitsMax = 16; | |
26 const int kNumDistanceSymbols = kDictBitsMax + 1; | |
27 | |
28 const int kMaxMatch = 256; | |
29 const int kMinMatch = 3; | |
30 const int kNumCSymbols = 256 + kMaxMatch + 2 - kMinMatch; | |
31 | |
32 template <UInt32 m_NumSymbols> | |
33 class CHuffmanDecoder:public NCompress::NHuffman::CDecoder<kMaxHuffmanLen, m_NumSymbols> | |
34 { | |
35 public: | |
36 int Symbol; | |
37 template <class TBitDecoder> | |
38 UInt32 Decode(TBitDecoder *bitStream) | |
39 { | |
40 if (Symbol >= 0) | |
41 return (UInt32)Symbol; | |
42 return DecodeSymbol(bitStream); | |
43 } | |
44 }; | |
45 | |
46 class CCoder : | |
47 public ICompressCoder, | |
48 public CMyUnknownImp | |
49 { | |
50 CLzOutWindow m_OutWindowStream; | |
51 NBitm::CDecoder<CInBuffer> m_InBitStream; | |
52 | |
53 int m_NumDictBits; | |
54 | |
55 CHuffmanDecoder<kNumLevelSymbols> m_LevelHuffman; | |
56 CHuffmanDecoder<kNumDistanceSymbols> m_PHuffmanDecoder; | |
57 CHuffmanDecoder<kNumCSymbols> m_CHuffmanDecoder; | |
58 | |
59 void ReleaseStreams() | |
60 { | |
61 m_OutWindowStream.ReleaseStream(); | |
62 m_InBitStream.ReleaseStream(); | |
63 } | |
64 | |
65 class CCoderReleaser | |
66 { | |
67 CCoder *m_Coder; | |
68 public: | |
69 bool NeedFlush; | |
70 CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {} | |
71 ~CCoderReleaser() | |
72 { | |
73 if (NeedFlush) | |
74 m_Coder->m_OutWindowStream.Flush(); | |
75 m_Coder->ReleaseStreams(); | |
76 } | |
77 }; | |
78 friend class CCoderReleaser; | |
79 | |
80 void MakeTable(int nchar, Byte *bitlen, int tablebits, | |
81 UInt32 *table, int tablesize); | |
82 | |
83 UInt32 ReadBits(int numBits); | |
84 HRESULT ReadLevelTable(); | |
85 HRESULT ReadPTable(int numBits); | |
86 HRESULT ReadCTable(); | |
87 | |
88 public: | |
89 | |
90 MY_UNKNOWN_IMP | |
91 | |
92 STDMETHOD(CodeReal)(ISequentialInStream *inStream, | |
93 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, | |
94 ICompressProgressInfo *progress); | |
95 | |
96 STDMETHOD(Code)(ISequentialInStream *inStream, | |
97 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, | |
98 ICompressProgressInfo *progress); | |
99 | |
100 void SetDictionary(int numDictBits) { m_NumDictBits = numDictBits; } | |
101 CCoder(): m_NumDictBits(0) {} | |
102 }; | |
103 | |
104 }}} | |
105 | |
106 #endif |