Imported Upstream version 9.20
[platform/upstream/7zip.git] / CPP / 7zip / Compress / Rar1Decoder.h
1 // Rar1Decoder.h\r
2 // According to unRAR license, this code may not be used to develop\r
3 // a program that creates RAR archives\r
4 \r
5 #ifndef __COMPRESS_RAR1_DECODER_H\r
6 #define __COMPRESS_RAR1_DECODER_H\r
7 \r
8 #include "../../Common/MyCom.h"\r
9 \r
10 #include "../ICoder.h"\r
11 \r
12 #include "../Common/InBuffer.h"\r
13 \r
14 #include "BitmDecoder.h"\r
15 #include "HuffmanDecoder.h"\r
16 #include "LzOutWindow.h"\r
17 \r
18 namespace NCompress {\r
19 namespace NRar1 {\r
20 \r
21 const UInt32 kNumRepDists = 4;\r
22 \r
23 typedef NBitm::CDecoder<CInBuffer> CBitDecoder;\r
24 \r
25 class CDecoder :\r
26   public ICompressCoder,\r
27   public ICompressSetDecoderProperties2,\r
28   public CMyUnknownImp\r
29 {\r
30 public:\r
31   CLzOutWindow m_OutWindowStream;\r
32   CBitDecoder m_InBitStream;\r
33 \r
34   UInt32 m_RepDists[kNumRepDists];\r
35   UInt32 m_RepDistPtr;\r
36 \r
37   UInt32 LastDist;\r
38   UInt32 LastLength;\r
39 \r
40   Int64 m_UnpackSize;\r
41   bool m_IsSolid;\r
42 \r
43   UInt32 ReadBits(int numBits);\r
44   HRESULT CopyBlock(UInt32 distance, UInt32 len);\r
45 \r
46   UInt32 DecodeNum(const UInt32 *posTab);\r
47   HRESULT ShortLZ();\r
48   HRESULT LongLZ();\r
49   HRESULT HuffDecode();\r
50   void GetFlagsBuf();\r
51   void InitData();\r
52   void InitHuff();\r
53   void CorrHuff(UInt32 *CharSet, UInt32 *NumToPlace);\r
54   void OldUnpWriteBuf();\r
55   \r
56   UInt32 ChSet[256],ChSetA[256],ChSetB[256],ChSetC[256];\r
57   UInt32 Place[256],PlaceA[256],PlaceB[256],PlaceC[256];\r
58   UInt32 NToPl[256],NToPlB[256],NToPlC[256];\r
59   UInt32 FlagBuf,AvrPlc,AvrPlcB,AvrLn1,AvrLn2,AvrLn3;\r
60   int Buf60,NumHuf,StMode,LCount,FlagsCnt;\r
61   UInt32 Nhfb,Nlzb,MaxDist3;\r
62 \r
63   void InitStructures();\r
64 \r
65   HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r
66       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r
67 \r
68 public:\r
69   CDecoder();\r
70 \r
71   MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)\r
72 \r
73   void ReleaseStreams()\r
74   {\r
75     m_OutWindowStream.ReleaseStream();\r
76     m_InBitStream.ReleaseStream();\r
77   }\r
78 \r
79   STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r
80       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r
81 \r
82   STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r
83 \r
84 };\r
85 \r
86 }}\r
87 \r
88 #endif\r