Make a bunch of JBig2 classes independent of CJBig2_Object.
[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
21 enum JBig2Corner {
22   JBIG2_CORNER_BOTTOMLEFT = 0,
23   JBIG2_CORNER_TOPLEFT = 1,
24   JBIG2_CORNER_BOTTOMRIGHT = 2,
25   JBIG2_CORNER_TOPRIGHT = 3
26 };
27
28 class CJBig2_GRDProc : public CJBig2_Object {
29  public:
30   CJBig2_GRDProc() {
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,
43                              JBig2ArithCtx* gbContext);
44
45   FXCODEC_STATUS Start_decode_Arith(CJBig2_Image** pImage,
46                                     CJBig2_ArithDecoder* pArithDecoder,
47                                     JBig2ArithCtx* gbContext,
48                                     IFX_Pause* pPause = NULL);
49   FXCODEC_STATUS Start_decode_MMR(CJBig2_Image** pImage,
50                                   CJBig2_BitStream* pStream,
51                                   IFX_Pause* pPause = NULL);
52   FXCODEC_STATUS Continue_decode(IFX_Pause* pPause);
53   FX_RECT GetReplaceRect() { return m_ReplaceRect; }
54
55   FX_BOOL MMR;
56   FX_DWORD GBW;
57   FX_DWORD GBH;
58   uint8_t GBTEMPLATE;
59   FX_BOOL TPGDON;
60   FX_BOOL USESKIP;
61   CJBig2_Image* SKIP;
62   int8_t GBAT[8];
63
64  private:
65   FXCODEC_STATUS decode_Arith(IFX_Pause* pPause);
66   FXCODEC_STATUS decode_Arith_Template0_opt3(CJBig2_Image* pImage,
67                                              CJBig2_ArithDecoder* pArithDecoder,
68                                              JBig2ArithCtx* gbContext,
69                                              IFX_Pause* pPause);
70   FXCODEC_STATUS decode_Arith_Template0_unopt(
71       CJBig2_Image* pImage,
72       CJBig2_ArithDecoder* pArithDecoder,
73       JBig2ArithCtx* gbContext,
74       IFX_Pause* pPause);
75   FXCODEC_STATUS decode_Arith_Template1_opt3(CJBig2_Image* pImage,
76                                              CJBig2_ArithDecoder* pArithDecoder,
77                                              JBig2ArithCtx* gbContext,
78                                              IFX_Pause* pPause);
79   FXCODEC_STATUS decode_Arith_Template1_unopt(
80       CJBig2_Image* pImage,
81       CJBig2_ArithDecoder* pArithDecoder,
82       JBig2ArithCtx* gbContext,
83       IFX_Pause* pPause);
84   FXCODEC_STATUS decode_Arith_Template2_opt3(CJBig2_Image* pImage,
85                                              CJBig2_ArithDecoder* pArithDecoder,
86                                              JBig2ArithCtx* gbContext,
87                                              IFX_Pause* pPause);
88   FXCODEC_STATUS decode_Arith_Template2_unopt(
89       CJBig2_Image* pImage,
90       CJBig2_ArithDecoder* pArithDecoder,
91       JBig2ArithCtx* gbContext,
92       IFX_Pause* pPause);
93   FXCODEC_STATUS decode_Arith_Template3_opt3(CJBig2_Image* pImage,
94                                              CJBig2_ArithDecoder* pArithDecoder,
95                                              JBig2ArithCtx* gbContext,
96                                              IFX_Pause* pPause);
97   FXCODEC_STATUS decode_Arith_Template3_unopt(
98       CJBig2_Image* pImage,
99       CJBig2_ArithDecoder* pArithDecoder,
100       JBig2ArithCtx* gbContext,
101       IFX_Pause* pPause);
102   CJBig2_Image* decode_Arith_Template0_opt3(CJBig2_ArithDecoder* pArithDecoder,
103                                             JBig2ArithCtx* gbContext);
104
105   CJBig2_Image* decode_Arith_Template0_unopt(CJBig2_ArithDecoder* pArithDecoder,
106                                              JBig2ArithCtx* gbContext);
107
108   CJBig2_Image* decode_Arith_Template1_opt3(CJBig2_ArithDecoder* pArithDecoder,
109                                             JBig2ArithCtx* gbContext);
110
111   CJBig2_Image* decode_Arith_Template1_unopt(CJBig2_ArithDecoder* pArithDecoder,
112                                              JBig2ArithCtx* gbContext);
113
114   CJBig2_Image* decode_Arith_Template2_opt3(CJBig2_ArithDecoder* pArithDecoder,
115                                             JBig2ArithCtx* gbContext);
116
117   CJBig2_Image* decode_Arith_Template2_unopt(CJBig2_ArithDecoder* pArithDecoder,
118                                              JBig2ArithCtx* gbContext);
119
120   CJBig2_Image* decode_Arith_Template3_opt3(CJBig2_ArithDecoder* pArithDecoder,
121                                             JBig2ArithCtx* gbContext);
122
123   CJBig2_Image* decode_Arith_Template3_unopt(CJBig2_ArithDecoder* pArithDecoder,
124                                              JBig2ArithCtx* gbContext);
125
126   FX_DWORD m_loopIndex;
127   uint8_t* m_pLine;
128   IFX_Pause* m_pPause;
129   FXCODEC_STATUS m_ProssiveStatus;
130   CJBig2_Image** m_pImage;
131   CJBig2_ArithDecoder* m_pArithDecoder;
132   JBig2ArithCtx* m_gbContext;
133   FX_WORD m_DecodeType;
134   FX_BOOL LTP;
135   FX_RECT m_ReplaceRect;
136 };
137
138 class CJBig2_GRRDProc : public CJBig2_Object {
139  public:
140   CJBig2_Image* decode(CJBig2_ArithDecoder* pArithDecoder,
141                        JBig2ArithCtx* grContext);
142
143   CJBig2_Image* decode_Template0_unopt(CJBig2_ArithDecoder* pArithDecoder,
144                                        JBig2ArithCtx* grContext);
145
146   CJBig2_Image* decode_Template0_opt(CJBig2_ArithDecoder* pArithDecoder,
147                                      JBig2ArithCtx* grContext);
148
149   CJBig2_Image* decode_Template1_unopt(CJBig2_ArithDecoder* pArithDecoder,
150                                        JBig2ArithCtx* grContext);
151
152   CJBig2_Image* decode_Template1_opt(CJBig2_ArithDecoder* pArithDecoder,
153                                      JBig2ArithCtx* grContext);
154
155   FX_DWORD GRW;
156   FX_DWORD GRH;
157   FX_BOOL GRTEMPLATE;
158   CJBig2_Image* GRREFERENCE;
159   int32_t GRREFERENCEDX;
160   int32_t GRREFERENCEDY;
161   FX_BOOL TPGRON;
162   int8_t GRAT[4];
163 };
164
165 typedef struct {
166   CJBig2_ArithIntDecoder *IADT, *IAFS, *IADS, *IAIT, *IARI, *IARDW, *IARDH,
167       *IARDX, *IARDY;
168   CJBig2_ArithIaidDecoder* IAID;
169 } JBig2IntDecoderState;
170
171 class CJBig2_TRDProc : public CJBig2_Object {
172  public:
173   CJBig2_Image* decode_Huffman(CJBig2_BitStream* pStream,
174                                JBig2ArithCtx* grContext);
175
176   CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
177                              JBig2ArithCtx* grContext,
178                              JBig2IntDecoderState* pIDS = NULL);
179
180  public:
181   FX_BOOL SBHUFF;
182   FX_BOOL SBREFINE;
183   FX_DWORD SBW;
184   FX_DWORD SBH;
185   FX_DWORD SBNUMINSTANCES;
186   FX_DWORD SBSTRIPS;
187   FX_DWORD SBNUMSYMS;
188
189   JBig2HuffmanCode* SBSYMCODES;
190   uint8_t SBSYMCODELEN;
191
192   CJBig2_Image** SBSYMS;
193   FX_BOOL SBDEFPIXEL;
194
195   JBig2ComposeOp SBCOMBOP;
196   FX_BOOL TRANSPOSED;
197
198   JBig2Corner REFCORNER;
199   int8_t SBDSOFFSET;
200   CJBig2_HuffmanTable *SBHUFFFS, *SBHUFFDS, *SBHUFFDT, *SBHUFFRDW, *SBHUFFRDH,
201       *SBHUFFRDX, *SBHUFFRDY, *SBHUFFRSIZE;
202   FX_BOOL SBRTEMPLATE;
203   int8_t SBRAT[4];
204 };
205 class CJBig2_SDDProc : public CJBig2_Object {
206  public:
207   CJBig2_SymbolDict* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
208                                   JBig2ArithCtx* gbContext,
209                                   JBig2ArithCtx* grContext);
210
211   CJBig2_SymbolDict* decode_Huffman(CJBig2_BitStream* pStream,
212                                     JBig2ArithCtx* gbContext,
213                                     JBig2ArithCtx* grContext,
214                                     IFX_Pause* pPause);
215
216  public:
217   FX_BOOL SDHUFF;
218   FX_BOOL SDREFAGG;
219   FX_DWORD SDNUMINSYMS;
220   CJBig2_Image** SDINSYMS;
221   FX_DWORD SDNUMNEWSYMS;
222   FX_DWORD SDNUMEXSYMS;
223   CJBig2_HuffmanTable *SDHUFFDH, *SDHUFFDW, *SDHUFFBMSIZE, *SDHUFFAGGINST;
224   uint8_t SDTEMPLATE;
225   int8_t SDAT[8];
226   FX_BOOL SDRTEMPLATE;
227   int8_t SDRAT[4];
228 };
229 class CJBig2_HTRDProc : public CJBig2_Object {
230  public:
231   CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
232                              JBig2ArithCtx* gbContext,
233                              IFX_Pause* pPause);
234
235   CJBig2_Image* decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause);
236
237  public:
238   FX_DWORD HBW, HBH;
239   FX_BOOL HMMR;
240   uint8_t HTEMPLATE;
241   FX_DWORD HNUMPATS;
242   CJBig2_Image** HPATS;
243   FX_BOOL HDEFPIXEL;
244   JBig2ComposeOp HCOMBOP;
245   FX_BOOL HENABLESKIP;
246   FX_DWORD HGW, HGH;
247   int32_t HGX, HGY;
248   FX_WORD HRX, HRY;
249   uint8_t HPW, HPH;
250 };
251 class CJBig2_PDDProc : public CJBig2_Object {
252  public:
253   CJBig2_PatternDict* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
254                                    JBig2ArithCtx* gbContext,
255                                    IFX_Pause* pPause);
256
257   CJBig2_PatternDict* decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause);
258
259  public:
260   FX_BOOL HDMMR;
261   uint8_t HDPW, HDPH;
262   FX_DWORD GRAYMAX;
263   uint8_t HDTEMPLATE;
264 };
265 class CJBig2_GSIDProc : public CJBig2_Object {
266  public:
267   FX_DWORD* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
268                          JBig2ArithCtx* gbContext,
269                          IFX_Pause* pPause);
270
271   FX_DWORD* decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause);
272
273  public:
274   FX_BOOL GSMMR;
275   FX_BOOL GSUSESKIP;
276   uint8_t GSBPP;
277   FX_DWORD GSW, GSH;
278   uint8_t GSTEMPLATE;
279   CJBig2_Image* GSKIP;
280 };
281 #endif