diff src/win32/7zip/7z/CPP/7zip/Compress/Rar2Decoder.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/Rar2Decoder.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,174 @@
     1.4 +// Rar2Decoder.h
     1.5 +// According to unRAR license, this code may not be used to develop
     1.6 +// a program that creates RAR archives
     1.7 +
     1.8 +#ifndef __COMPRESS_RAR2_DECODER_H
     1.9 +#define __COMPRESS_RAR2_DECODER_H
    1.10 +
    1.11 +#include "../../Common/MyCom.h"
    1.12 +
    1.13 +#include "../ICoder.h"
    1.14 +
    1.15 +#include "../Common/InBuffer.h"
    1.16 +
    1.17 +#include "BitmDecoder.h"
    1.18 +#include "HuffmanDecoder.h"
    1.19 +#include "LzOutWindow.h"
    1.20 +
    1.21 +namespace NCompress {
    1.22 +namespace NRar2 {
    1.23 +
    1.24 +const UInt32 kNumRepDists = 4;
    1.25 +const UInt32 kDistTableSize = 48;
    1.26 +
    1.27 +const int kMMTableSize = 256 + 1;
    1.28 +
    1.29 +const UInt32 kMainTableSize = 298;
    1.30 +const UInt32 kLenTableSize = 28;
    1.31 +
    1.32 +const UInt32 kDistTableStart = kMainTableSize;
    1.33 +const UInt32 kLenTableStart = kDistTableStart + kDistTableSize;
    1.34 +
    1.35 +const UInt32 kHeapTablesSizesSum = kMainTableSize + kDistTableSize + kLenTableSize;
    1.36 +
    1.37 +const UInt32 kLevelTableSize = 19;
    1.38 +
    1.39 +const UInt32 kMMTablesSizesSum = kMMTableSize * 4;
    1.40 +
    1.41 +const UInt32 kMaxTableSize = kMMTablesSizesSum;
    1.42 +
    1.43 +const UInt32 kTableDirectLevels = 16;
    1.44 +const UInt32 kTableLevelRepNumber = kTableDirectLevels;
    1.45 +const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
    1.46 +const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
    1.47 +
    1.48 +const UInt32 kLevelMask = 0xF;
    1.49 +
    1.50 +
    1.51 +const UInt32 kRepBothNumber = 256;
    1.52 +const UInt32 kRepNumber = kRepBothNumber + 1;
    1.53 +const UInt32 kLen2Number = kRepNumber + 4;
    1.54 +
    1.55 +const UInt32 kLen2NumNumbers = 8;
    1.56 +const UInt32 kReadTableNumber = kLen2Number + kLen2NumNumbers;
    1.57 +const UInt32 kMatchNumber = kReadTableNumber + 1;
    1.58 +
    1.59 +const Byte kLenStart[kLenTableSize]      = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224};
    1.60 +const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5};
    1.61 +
    1.62 +const UInt32 kDistStart[kDistTableSize]     = {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768U,49152U,65536,98304,131072,196608,262144,327680,393216,458752,524288,589824,655360,720896,786432,851968,917504,983040};
    1.63 +const Byte kDistDirectBits[kDistTableSize] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5,  6,  6,  7,  7,  8,  8,   9,   9,  10,  10,  11,  11,  12,   12,   13,   13,    14,    14,   15,   15,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16};
    1.64 +
    1.65 +const Byte kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
    1.66 +
    1.67 +const Byte kLen2DistStarts[kLen2NumNumbers]={0,4,8,16,32,64,128,192};
    1.68 +const Byte kLen2DistDirectBits[kLen2NumNumbers]={2,2,3, 4, 5, 6,  6,  6};
    1.69 +
    1.70 +const UInt32 kDistLimit2 = 0x101 - 1;
    1.71 +const UInt32 kDistLimit3 = 0x2000 - 1;
    1.72 +const UInt32 kDistLimit4 = 0x40000 - 1;
    1.73 +
    1.74 +const UInt32 kMatchMaxLen = 255 + 2;
    1.75 +const UInt32 kMatchMaxLenMax = 255 + 5;
    1.76 +const UInt32 kNormalMatchMinLen = 3;
    1.77 +
    1.78 +namespace NMultimedia {
    1.79 +
    1.80 +struct CFilter
    1.81 +{
    1.82 +  int K1,K2,K3,K4,K5;
    1.83 +  int D1,D2,D3,D4;
    1.84 +  int LastDelta;
    1.85 +  UInt32 Dif[11];
    1.86 +  UInt32 ByteCount;
    1.87 +  int LastChar;
    1.88 +
    1.89 +  Byte Decode(int &channelDelta, Byte delta);
    1.90 +
    1.91 +  void Init() { memset(this, 0, sizeof(*this)); }
    1.92 +
    1.93 +};
    1.94 +
    1.95 +const int kNumChanelsMax = 4;
    1.96 +
    1.97 +class CFilter2
    1.98 +{
    1.99 +public:
   1.100 +  CFilter  m_Filters[kNumChanelsMax];
   1.101 +  int m_ChannelDelta;
   1.102 +  int CurrentChannel;
   1.103 +
   1.104 +  void Init() { memset(this, 0, sizeof(*this)); }
   1.105 +  Byte Decode(Byte delta)
   1.106 +  {
   1.107 +    return m_Filters[CurrentChannel].Decode(m_ChannelDelta, delta);
   1.108 +  }
   1.109 +
   1.110 +};
   1.111 +
   1.112 +}
   1.113 +
   1.114 +typedef NBitm::CDecoder<CInBuffer> CBitDecoder;
   1.115 +
   1.116 +const int kNumHuffmanBits = 15;
   1.117 +
   1.118 +class CDecoder :
   1.119 +  public ICompressCoder,
   1.120 +  public ICompressSetDecoderProperties2,
   1.121 +  public CMyUnknownImp
   1.122 +{
   1.123 +  CLzOutWindow m_OutWindowStream;
   1.124 +  CBitDecoder m_InBitStream;
   1.125 +  NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
   1.126 +  NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder;
   1.127 +  NHuffman::CDecoder<kNumHuffmanBits, kLenTableSize> m_LenDecoder;
   1.128 +  NHuffman::CDecoder<kNumHuffmanBits, kMMTableSize> m_MMDecoders[NMultimedia::kNumChanelsMax];
   1.129 +  NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
   1.130 +
   1.131 +  bool m_AudioMode;
   1.132 +
   1.133 +  NMultimedia::CFilter2 m_MmFilter;
   1.134 +  int m_NumChannels;
   1.135 +
   1.136 +  UInt32 m_RepDists[kNumRepDists];
   1.137 +  UInt32 m_RepDistPtr;
   1.138 +
   1.139 +  UInt32 m_LastLength;
   1.140 +  
   1.141 +  Byte m_LastLevels[kMaxTableSize];
   1.142 +
   1.143 +  UInt64 m_PackSize;
   1.144 +  bool m_IsSolid;
   1.145 +
   1.146 +  void InitStructures();
   1.147 +  UInt32 ReadBits(int numBits);
   1.148 +  bool ReadTables();
   1.149 +  bool ReadLastTables();
   1.150 +
   1.151 +  bool DecodeMm(UInt32 pos);
   1.152 +  bool DecodeLz(Int32 pos);
   1.153 +
   1.154 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
   1.155 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
   1.156 +
   1.157 +public:
   1.158 +  CDecoder();
   1.159 +
   1.160 +  MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
   1.161 +
   1.162 +  void ReleaseStreams()
   1.163 +  {
   1.164 +    m_OutWindowStream.ReleaseStream();
   1.165 +    m_InBitStream.ReleaseStream();
   1.166 +  }
   1.167 +
   1.168 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
   1.169 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
   1.170 +
   1.171 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
   1.172 +
   1.173 +};
   1.174 +
   1.175 +}}
   1.176 +
   1.177 +#endif