view 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
line wrap: on
line source
1 // LzhDecoder.h
3 #ifndef __COMPRESS_LZH_DECODER_H
4 #define __COMPRESS_LZH_DECODER_H
6 #include "../../Common/MyCom.h"
8 #include "../ICoder.h"
10 #include "../Common/InBuffer.h"
12 #include "BitmDecoder.h"
13 #include "HuffmanDecoder.h"
14 #include "LzOutWindow.h"
16 namespace NCompress {
17 namespace NLzh {
18 namespace NDecoder {
20 const int kMaxHuffmanLen = 16; // Check it
22 const int kNumSpecLevelSymbols = 3;
23 const int kNumLevelSymbols = kNumSpecLevelSymbols + kMaxHuffmanLen;
25 const int kDictBitsMax = 16;
26 const int kNumDistanceSymbols = kDictBitsMax + 1;
28 const int kMaxMatch = 256;
29 const int kMinMatch = 3;
30 const int kNumCSymbols = 256 + kMaxMatch + 2 - kMinMatch;
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 };
46 class CCoder :
47 public ICompressCoder,
48 public CMyUnknownImp
49 {
50 CLzOutWindow m_OutWindowStream;
51 NBitm::CDecoder<CInBuffer> m_InBitStream;
53 int m_NumDictBits;
55 CHuffmanDecoder<kNumLevelSymbols> m_LevelHuffman;
56 CHuffmanDecoder<kNumDistanceSymbols> m_PHuffmanDecoder;
57 CHuffmanDecoder<kNumCSymbols> m_CHuffmanDecoder;
59 void ReleaseStreams()
60 {
61 m_OutWindowStream.ReleaseStream();
62 m_InBitStream.ReleaseStream();
63 }
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;
80 void MakeTable(int nchar, Byte *bitlen, int tablebits,
81 UInt32 *table, int tablesize);
83 UInt32 ReadBits(int numBits);
84 HRESULT ReadLevelTable();
85 HRESULT ReadPTable(int numBits);
86 HRESULT ReadCTable();
88 public:
90 MY_UNKNOWN_IMP
92 STDMETHOD(CodeReal)(ISequentialInStream *inStream,
93 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
94 ICompressProgressInfo *progress);
96 STDMETHOD(Code)(ISequentialInStream *inStream,
97 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
98 ICompressProgressInfo *progress);
100 void SetDictionary(int numDictBits) { m_NumDictBits = numDictBits; }
101 CCoder(): m_NumDictBits(0) {}
102 };
104 }}}
106 #endif