Imported Upstream version 9.20
[platform/upstream/7zip.git] / CPP / 7zip / Compress / ArjDecoder1.h
1 // ArjDecoder1.h\r
2 \r
3 #ifndef __COMPRESS_ARJ_DECODER1_H\r
4 #define __COMPRESS_ARJ_DECODER1_H\r
5 \r
6 #include "../../Common/MyCom.h"\r
7 \r
8 #include "../ICoder.h"\r
9 \r
10 #include "../Common/InBuffer.h"\r
11 \r
12 #include "BitmDecoder.h"\r
13 #include "LzOutWindow.h"\r
14 \r
15 namespace NCompress {\r
16 namespace NArj {\r
17 namespace NDecoder1 {\r
18 \r
19 #define CODE_BIT          16\r
20 \r
21 #define THRESHOLD    3\r
22 #define DDICSIZ      26624\r
23 #define MAXDICBIT   16\r
24 #define MATCHBIT     8\r
25 #define MAXMATCH   256\r
26 #define NC          (0xFF + MAXMATCH + 2 - THRESHOLD)\r
27 #define NP          (MAXDICBIT + 1)\r
28 #define CBIT         9\r
29 #define NT          (CODE_BIT + 3)\r
30 #define PBIT         5\r
31 #define TBIT         5\r
32 \r
33 #if NT > NP\r
34 #define NPT NT\r
35 #else\r
36 #define NPT NP\r
37 #endif\r
38 \r
39 #define CTABLESIZE  4096\r
40 #define PTABLESIZE   256\r
41 \r
42 \r
43 class CCoder :\r
44   public ICompressCoder,\r
45   public CMyUnknownImp\r
46 {\r
47   CLzOutWindow m_OutWindowStream;\r
48   NBitm::CDecoder<CInBuffer> m_InBitStream;\r
49 \r
50   UInt32 left[2 * NC - 1];\r
51   UInt32 right[2 * NC - 1];\r
52   Byte c_len[NC];\r
53   Byte pt_len[NPT];\r
54 \r
55   UInt32 c_table[CTABLESIZE];\r
56   UInt32 pt_table[PTABLESIZE];\r
57   \r
58   void ReleaseStreams()\r
59   {\r
60     m_OutWindowStream.ReleaseStream();\r
61     m_InBitStream.ReleaseStream();\r
62   }\r
63 \r
64   class CCoderReleaser\r
65   {\r
66     CCoder *m_Coder;\r
67   public:\r
68     bool NeedFlush;\r
69     CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {}\r
70     ~CCoderReleaser()\r
71     {\r
72       if (NeedFlush)\r
73         m_Coder->m_OutWindowStream.Flush();\r
74       m_Coder->ReleaseStreams();\r
75     }\r
76   };\r
77   friend class CCoderReleaser;\r
78 \r
79   void MakeTable(int nchar, Byte *bitlen, int tablebits, UInt32 *table, int tablesize);\r
80   \r
81   void read_c_len();\r
82   void read_pt_len(int nn, int nbit, int i_special);\r
83   UInt32 decode_c();\r
84   UInt32 decode_p();\r
85 \r
86   HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r
87       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r
88 public:\r
89   MY_UNKNOWN_IMP\r
90 \r
91   STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r
92       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r
93 \r
94 };\r
95 \r
96 }}}\r
97 \r
98 #endif\r