diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/LzhDecoder.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,106 @@
     1.4 +// LzhDecoder.h
     1.5 +
     1.6 +#ifndef __COMPRESS_LZH_DECODER_H
     1.7 +#define __COMPRESS_LZH_DECODER_H
     1.8 +
     1.9 +#include "../../Common/MyCom.h"
    1.10 +
    1.11 +#include "../ICoder.h"
    1.12 +
    1.13 +#include "../Common/InBuffer.h"
    1.14 +
    1.15 +#include "BitmDecoder.h"
    1.16 +#include "HuffmanDecoder.h"
    1.17 +#include "LzOutWindow.h"
    1.18 +
    1.19 +namespace NCompress {
    1.20 +namespace NLzh {
    1.21 +namespace NDecoder {
    1.22 +
    1.23 +const int kMaxHuffmanLen = 16; // Check it
    1.24 +
    1.25 +const int kNumSpecLevelSymbols = 3;
    1.26 +const int kNumLevelSymbols = kNumSpecLevelSymbols + kMaxHuffmanLen;
    1.27 +
    1.28 +const int kDictBitsMax = 16;
    1.29 +const int kNumDistanceSymbols = kDictBitsMax + 1;
    1.30 +
    1.31 +const int kMaxMatch = 256;
    1.32 +const int kMinMatch = 3;
    1.33 +const int kNumCSymbols = 256 + kMaxMatch + 2 - kMinMatch;
    1.34 +
    1.35 +template <UInt32 m_NumSymbols>
    1.36 +class CHuffmanDecoder:public NCompress::NHuffman::CDecoder<kMaxHuffmanLen, m_NumSymbols>
    1.37 +{
    1.38 +public:
    1.39 +  int Symbol;
    1.40 +  template <class TBitDecoder>
    1.41 +  UInt32 Decode(TBitDecoder *bitStream)
    1.42 +  {
    1.43 +    if (Symbol >= 0)
    1.44 +      return (UInt32)Symbol;
    1.45 +    return DecodeSymbol(bitStream);
    1.46 +  }
    1.47 +};
    1.48 +
    1.49 +class CCoder :
    1.50 +  public ICompressCoder,
    1.51 +  public CMyUnknownImp
    1.52 +{
    1.53 +  CLzOutWindow m_OutWindowStream;
    1.54 +  NBitm::CDecoder<CInBuffer> m_InBitStream;
    1.55 +
    1.56 +  int m_NumDictBits;
    1.57 +
    1.58 +  CHuffmanDecoder<kNumLevelSymbols> m_LevelHuffman;
    1.59 +  CHuffmanDecoder<kNumDistanceSymbols> m_PHuffmanDecoder;
    1.60 +  CHuffmanDecoder<kNumCSymbols> m_CHuffmanDecoder;
    1.61 +
    1.62 +  void ReleaseStreams()
    1.63 +  {
    1.64 +    m_OutWindowStream.ReleaseStream();
    1.65 +    m_InBitStream.ReleaseStream();
    1.66 +  }
    1.67 +
    1.68 +  class CCoderReleaser
    1.69 +  {
    1.70 +    CCoder *m_Coder;
    1.71 +  public:
    1.72 +    bool NeedFlush;
    1.73 +    CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {}
    1.74 +    ~CCoderReleaser()
    1.75 +    {
    1.76 +      if (NeedFlush)
    1.77 +        m_Coder->m_OutWindowStream.Flush();
    1.78 +      m_Coder->ReleaseStreams();
    1.79 +    }
    1.80 +  };
    1.81 +  friend class CCoderReleaser;
    1.82 +
    1.83 +  void MakeTable(int nchar, Byte *bitlen, int tablebits,
    1.84 +      UInt32 *table, int tablesize);
    1.85 +  
    1.86 +  UInt32 ReadBits(int numBits);
    1.87 +  HRESULT ReadLevelTable();
    1.88 +  HRESULT ReadPTable(int numBits);
    1.89 +  HRESULT ReadCTable();
    1.90 +
    1.91 +public:
    1.92 +  
    1.93 +  MY_UNKNOWN_IMP
    1.94 +
    1.95 +  STDMETHOD(CodeReal)(ISequentialInStream *inStream,
    1.96 +      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
    1.97 +      ICompressProgressInfo *progress);
    1.98 +
    1.99 +  STDMETHOD(Code)(ISequentialInStream *inStream,
   1.100 +      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
   1.101 +      ICompressProgressInfo *progress);
   1.102 +
   1.103 +  void SetDictionary(int numDictBits) { m_NumDictBits = numDictBits; }
   1.104 +  CCoder(): m_NumDictBits(0) {}
   1.105 +};
   1.106 +
   1.107 +}}}
   1.108 +
   1.109 +#endif