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