Initial commit.
[pdfium.git] / core / src / fxcodec / jbig2 / JBig2_GeneralDecoder.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _JBIG2_GENERAL_DECODER_H_\r
8 #define _JBIG2_GENERAL_DECODER_H_\r
9 #include "../../../include/fxcodec/fx_codec_def.h"\r
10 #include "../../../include/fxcrt/fx_basic.h"\r
11 #include "JBig2_Define.h"\r
12 #include "JBig2_SymbolDict.h"\r
13 #include "JBig2_ArithDecoder.h"\r
14 #include "JBig2_ArithIntDecoder.h"\r
15 #include "../../../include/fxcrt/fx_coordinates.h"\r
16 class CJBig2_HuffmanTable;\r
17 class CJBig2_Image;\r
18 class CJBig2_PatternDict;\r
19 typedef enum {\r
20     JBIG2_CORNER_BOTTOMLEFT = 0,\r
21     JBIG2_CORNER_TOPLEFT        = 1,\r
22     JBIG2_CORNER_BOTTOMRIGHT = 2,\r
23     JBIG2_CORNER_TOPRIGHT       = 3\r
24 } JBig2Corner;\r
25 class CJBig2_GRDProc : public CJBig2_Object\r
26 {\r
27 public:\r
28     CJBig2_GRDProc()\r
29     {\r
30         m_loopIndex = 0;\r
31         m_pLine = NULL;\r
32         m_pPause = NULL;\r
33         m_DecodeType = 0;\r
34         LTP = 0;\r
35         m_ReplaceRect.left = 0;\r
36         m_ReplaceRect.bottom = 0;\r
37         m_ReplaceRect.top = 0;\r
38         m_ReplaceRect.right = 0;\r
39     }\r
40 \r
41     CJBig2_Image *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
42 \r
43     CJBig2_Image *decode_Arith_V2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
44 \r
45     CJBig2_Image *decode_Arith_V1(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
46 \r
47     CJBig2_Image *decode_MMR(CJBig2_BitStream *pStream);\r
48     FXCODEC_STATUS Start_decode_Arith(CJBig2_Image** pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause = NULL);\r
49     FXCODEC_STATUS Start_decode_Arith_V2(CJBig2_Image** pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause = NULL);\r
50     FXCODEC_STATUS Start_decode_Arith_V1(CJBig2_Image** pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause = NULL);\r
51     FXCODEC_STATUS Start_decode_MMR(CJBig2_Image** pImage, CJBig2_BitStream *pStream, IFX_Pause* pPause = NULL);\r
52     FXCODEC_STATUS Continue_decode(IFX_Pause* pPause);\r
53     FX_RECT                GetReplaceRect()\r
54     {\r
55         return m_ReplaceRect;\r
56     };\r
57 private:\r
58     FXCODEC_STATUS decode_Arith(IFX_Pause* pPause);\r
59     FXCODEC_STATUS decode_Arith_V2(IFX_Pause* pPause);\r
60     FXCODEC_STATUS decode_Arith_V1(IFX_Pause* pPause);\r
61     FXCODEC_STATUS decode_MMR();\r
62     FXCODEC_STATUS decode_Arith_Template0_opt3(CJBig2_Image*pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
63     FXCODEC_STATUS decode_Arith_Template0_unopt(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
64     FXCODEC_STATUS decode_Arith_Template1_opt3(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
65     FXCODEC_STATUS decode_Arith_Template1_unopt(CJBig2_Image * pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
66     FXCODEC_STATUS decode_Arith_Template2_opt3(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
67     FXCODEC_STATUS decode_Arith_Template2_unopt(CJBig2_Image * pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
68     FXCODEC_STATUS decode_Arith_Template3_opt3(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
69     FXCODEC_STATUS decode_Arith_Template3_unopt(CJBig2_Image * pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
70     FX_DWORD    m_loopIndex;\r
71     FX_BYTE *   m_pLine;\r
72     IFX_Pause*  m_pPause;\r
73     FXCODEC_STATUS      m_ProssiveStatus;\r
74     CJBig2_Image** m_pImage;\r
75     CJBig2_ArithDecoder *m_pArithDecoder;\r
76     JBig2ArithCtx *m_gbContext;\r
77     FX_WORD             m_DecodeType;\r
78     FX_BOOL LTP;\r
79     FX_RECT m_ReplaceRect;\r
80 private:\r
81 \r
82     CJBig2_Image *decode_Arith_Template0_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
83 \r
84     CJBig2_Image *decode_Arith_Template0_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
85 \r
86     CJBig2_Image *decode_Arith_Template0_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
87 \r
88     CJBig2_Image *decode_Arith_Template0_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
89 \r
90     CJBig2_Image *decode_Arith_Template1_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
91 \r
92     CJBig2_Image *decode_Arith_Template1_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
93 \r
94     CJBig2_Image *decode_Arith_Template1_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
95 \r
96     CJBig2_Image *decode_Arith_Template1_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
97 \r
98     CJBig2_Image *decode_Arith_Template2_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
99 \r
100     CJBig2_Image *decode_Arith_Template2_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
101 \r
102     CJBig2_Image *decode_Arith_Template2_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
103 \r
104     CJBig2_Image *decode_Arith_Template2_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
105 \r
106     CJBig2_Image *decode_Arith_Template3_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
107 \r
108     CJBig2_Image *decode_Arith_Template3_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
109 \r
110     CJBig2_Image *decode_Arith_Template3_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
111 \r
112     CJBig2_Image *decode_Arith_Template3_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);\r
113 public:\r
114     FX_BOOL MMR;\r
115     FX_DWORD GBW;\r
116     FX_DWORD GBH;\r
117     FX_BYTE GBTEMPLATE;\r
118     FX_BOOL TPGDON;\r
119     FX_BOOL USESKIP;\r
120     CJBig2_Image * SKIP;\r
121     signed char GBAT[8];\r
122 };\r
123 class CJBig2_GRRDProc : public CJBig2_Object\r
124 {\r
125 public:\r
126 \r
127     CJBig2_Image *decode(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);\r
128 \r
129     CJBig2_Image *decode_Template0_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);\r
130 \r
131     CJBig2_Image *decode_Template0_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);\r
132 \r
133     CJBig2_Image *decode_Template1_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);\r
134 \r
135     CJBig2_Image *decode_Template1_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);\r
136 \r
137     CJBig2_Image *decode_V1(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);\r
138 public:\r
139     FX_DWORD GRW;\r
140     FX_DWORD GRH;\r
141     FX_BOOL GRTEMPLATE;\r
142     CJBig2_Image *GRREFERENCE;\r
143     FX_INT32 GRREFERENCEDX;\r
144     FX_INT32 GRREFERENCEDY;\r
145     FX_BOOL TPGRON;\r
146     signed char GRAT[4];\r
147 };\r
148 typedef struct {\r
149     CJBig2_ArithIntDecoder *IADT,\r
150                            *IAFS,\r
151                            *IADS,\r
152                            *IAIT,\r
153                            *IARI,\r
154                            *IARDW,\r
155                            *IARDH,\r
156                            *IARDX,\r
157                            *IARDY;\r
158     CJBig2_ArithIaidDecoder *IAID;\r
159 } JBig2IntDecoderState;\r
160 class CJBig2_TRDProc : public CJBig2_Object\r
161 {\r
162 public:\r
163 \r
164     CJBig2_Image *decode_Huffman(CJBig2_BitStream *pStream, JBig2ArithCtx *grContext);\r
165 \r
166     CJBig2_Image *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext,\r
167                                JBig2IntDecoderState *pIDS = NULL);\r
168 public:\r
169     FX_BOOL SBHUFF;\r
170     FX_BOOL SBREFINE;\r
171     FX_DWORD SBW;\r
172     FX_DWORD SBH;\r
173     FX_DWORD SBNUMINSTANCES;\r
174     FX_DWORD SBSTRIPS;\r
175     FX_DWORD SBNUMSYMS;\r
176 \r
177     JBig2HuffmanCode *SBSYMCODES;\r
178     FX_BYTE SBSYMCODELEN;\r
179 \r
180     CJBig2_Image **SBSYMS;\r
181     FX_BOOL SBDEFPIXEL;\r
182 \r
183     JBig2ComposeOp SBCOMBOP;\r
184     FX_BOOL TRANSPOSED;\r
185 \r
186     JBig2Corner REFCORNER;\r
187     signed char SBDSOFFSET;\r
188     CJBig2_HuffmanTable *SBHUFFFS,\r
189                         *SBHUFFDS,\r
190                         *SBHUFFDT,\r
191                         *SBHUFFRDW,\r
192                         *SBHUFFRDH,\r
193                         *SBHUFFRDX,\r
194                         *SBHUFFRDY,\r
195                         *SBHUFFRSIZE;\r
196     FX_BOOL SBRTEMPLATE;\r
197     signed char SBRAT[4];\r
198 };\r
199 class CJBig2_SDDProc : public CJBig2_Object\r
200 {\r
201 public:\r
202 \r
203     CJBig2_SymbolDict *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, JBig2ArithCtx *grContext);\r
204 \r
205     CJBig2_SymbolDict *decode_Huffman(CJBig2_BitStream *pStream, JBig2ArithCtx *gbContext, JBig2ArithCtx *grContext, IFX_Pause* pPause);\r
206 public:\r
207     FX_BOOL SDHUFF;\r
208     FX_BOOL SDREFAGG;\r
209     FX_DWORD SDNUMINSYMS;\r
210     CJBig2_Image ** SDINSYMS;\r
211     FX_DWORD SDNUMNEWSYMS;\r
212     FX_DWORD SDNUMEXSYMS;\r
213     CJBig2_HuffmanTable *SDHUFFDH,\r
214                         *SDHUFFDW,\r
215                         *SDHUFFBMSIZE,\r
216                         *SDHUFFAGGINST;\r
217     FX_BYTE SDTEMPLATE;\r
218     signed char SDAT[8];\r
219     FX_BOOL SDRTEMPLATE;\r
220     signed char SDRAT[4];\r
221 };\r
222 class CJBig2_HTRDProc : public CJBig2_Object\r
223 {\r
224 public:\r
225 \r
226     CJBig2_Image *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
227 \r
228     CJBig2_Image *decode_MMR(CJBig2_BitStream *pStream, IFX_Pause* pPause);\r
229 public:\r
230     FX_DWORD HBW,\r
231              HBH;\r
232     FX_BOOL HMMR;\r
233     FX_BYTE HTEMPLATE;\r
234     FX_DWORD HNUMPATS;\r
235     CJBig2_Image **HPATS;\r
236     FX_BOOL HDEFPIXEL;\r
237     JBig2ComposeOp HCOMBOP;\r
238     FX_BOOL HENABLESKIP;\r
239     FX_DWORD HGW,\r
240              HGH;\r
241     FX_INT32 HGX,\r
242              HGY;\r
243     FX_WORD HRX,\r
244             HRY;\r
245     FX_BYTE HPW,\r
246             HPH;\r
247 };\r
248 class CJBig2_PDDProc : public CJBig2_Object\r
249 {\r
250 public:\r
251 \r
252     CJBig2_PatternDict *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
253 \r
254     CJBig2_PatternDict *decode_MMR(CJBig2_BitStream *pStream, IFX_Pause* pPause);\r
255 public:\r
256     FX_BOOL HDMMR;\r
257     FX_BYTE HDPW,\r
258             HDPH;\r
259     FX_DWORD GRAYMAX;\r
260     FX_BYTE HDTEMPLATE;\r
261 };\r
262 class CJBig2_GSIDProc : public CJBig2_Object\r
263 {\r
264 public:\r
265 \r
266     FX_DWORD *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);\r
267 \r
268     FX_DWORD *decode_MMR(CJBig2_BitStream *pStream, IFX_Pause* pPause);\r
269 public:\r
270     FX_BOOL GSMMR;\r
271     FX_BOOL GSUSESKIP;\r
272     FX_BYTE GSBPP;\r
273     FX_DWORD GSW,\r
274              GSH;\r
275     FX_BYTE GSTEMPLATE;\r
276     CJBig2_Image *GSKIP;\r
277 };\r
278 #endif\r