summaryrefslogtreecommitdiff
path: root/core/src/fxcodec/jbig2/JBig2_GeneralDecoder.h
blob: 2bd2ceac95e63896a273c4ee5bf81a40c0b037d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef _JBIG2_GENERAL_DECODER_H_
#define _JBIG2_GENERAL_DECODER_H_

#include "../../../include/fxcodec/fx_codec_def.h"
#include "../../../include/fxcrt/fx_coordinates.h"
#include "JBig2_ArithDecoder.h"
#include "JBig2_ArithIntDecoder.h"
#include "JBig2_Define.h"
#include "JBig2_SymbolDict.h"

class CJBig2_HuffmanTable;
class CJBig2_Image;
class CJBig2_PatternDict;
typedef enum {
    JBIG2_CORNER_BOTTOMLEFT = 0,
    JBIG2_CORNER_TOPLEFT	= 1,
    JBIG2_CORNER_BOTTOMRIGHT = 2,
    JBIG2_CORNER_TOPRIGHT	= 3
} JBig2Corner;
class CJBig2_GRDProc : public CJBig2_Object
{
public:
    CJBig2_GRDProc()
    {
        m_loopIndex = 0;
        m_pLine = NULL;
        m_pPause = NULL;
        m_DecodeType = 0;
        LTP = 0;
        m_ReplaceRect.left = 0;
        m_ReplaceRect.bottom = 0;
        m_ReplaceRect.top = 0;
        m_ReplaceRect.right = 0;
    }

    CJBig2_Image *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_V2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_V1(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_MMR(CJBig2_BitStream *pStream);
    FXCODEC_STATUS Start_decode_Arith(CJBig2_Image** pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause = NULL);
    FXCODEC_STATUS Start_decode_Arith_V2(CJBig2_Image** pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause = NULL);
    FXCODEC_STATUS Start_decode_Arith_V1(CJBig2_Image** pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause = NULL);
    FXCODEC_STATUS Start_decode_MMR(CJBig2_Image** pImage, CJBig2_BitStream *pStream, IFX_Pause* pPause = NULL);
    FXCODEC_STATUS Continue_decode(IFX_Pause* pPause);
    FX_RECT		   GetReplaceRect()
    {
        return m_ReplaceRect;
    };
private:
    FXCODEC_STATUS decode_Arith(IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_V2(IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_V1(IFX_Pause* pPause);
    FXCODEC_STATUS decode_MMR();
    FXCODEC_STATUS decode_Arith_Template0_opt3(CJBig2_Image*pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_Template0_unopt(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_Template1_opt3(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_Template1_unopt(CJBig2_Image * pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_Template2_opt3(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_Template2_unopt(CJBig2_Image * pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_Template3_opt3(CJBig2_Image *pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FXCODEC_STATUS decode_Arith_Template3_unopt(CJBig2_Image * pImage, CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);
    FX_DWORD	m_loopIndex;
    uint8_t *	m_pLine;
    IFX_Pause*	m_pPause;
    FXCODEC_STATUS	m_ProssiveStatus;
    CJBig2_Image** m_pImage;
    CJBig2_ArithDecoder *m_pArithDecoder;
    JBig2ArithCtx *m_gbContext;
    FX_WORD		m_DecodeType;
    FX_BOOL LTP;
    FX_RECT m_ReplaceRect;
private:

    CJBig2_Image *decode_Arith_Template0_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template0_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template0_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template0_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template1_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template1_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template1_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template1_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template2_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template2_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template2_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template2_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template3_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template3_opt2(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template3_opt3(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);

    CJBig2_Image *decode_Arith_Template3_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext);
public:
    FX_BOOL MMR;
    FX_DWORD GBW;
    FX_DWORD GBH;
    uint8_t GBTEMPLATE;
    FX_BOOL TPGDON;
    FX_BOOL USESKIP;
    CJBig2_Image * SKIP;
    signed char GBAT[8];
};
class CJBig2_GRRDProc : public CJBig2_Object
{
public:

    CJBig2_Image *decode(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);

    CJBig2_Image *decode_Template0_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);

    CJBig2_Image *decode_Template0_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);

    CJBig2_Image *decode_Template1_unopt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);

    CJBig2_Image *decode_Template1_opt(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);

    CJBig2_Image *decode_V1(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext);
public:
    FX_DWORD GRW;
    FX_DWORD GRH;
    FX_BOOL GRTEMPLATE;
    CJBig2_Image *GRREFERENCE;
    int32_t GRREFERENCEDX;
    int32_t GRREFERENCEDY;
    FX_BOOL TPGRON;
    signed char	GRAT[4];
};
typedef struct {
    CJBig2_ArithIntDecoder *IADT,
                           *IAFS,
                           *IADS,
                           *IAIT,
                           *IARI,
                           *IARDW,
                           *IARDH,
                           *IARDX,
                           *IARDY;
    CJBig2_ArithIaidDecoder *IAID;
} JBig2IntDecoderState;
class CJBig2_TRDProc : public CJBig2_Object
{
public:

    CJBig2_Image *decode_Huffman(CJBig2_BitStream *pStream, JBig2ArithCtx *grContext);

    CJBig2_Image *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *grContext,
                               JBig2IntDecoderState *pIDS = NULL);
public:
    FX_BOOL SBHUFF;
    FX_BOOL SBREFINE;
    FX_DWORD SBW;
    FX_DWORD SBH;
    FX_DWORD SBNUMINSTANCES;
    FX_DWORD SBSTRIPS;
    FX_DWORD SBNUMSYMS;

    JBig2HuffmanCode *SBSYMCODES;
    uint8_t SBSYMCODELEN;

    CJBig2_Image **SBSYMS;
    FX_BOOL SBDEFPIXEL;

    JBig2ComposeOp SBCOMBOP;
    FX_BOOL TRANSPOSED;

    JBig2Corner REFCORNER;
    signed char SBDSOFFSET;
    CJBig2_HuffmanTable *SBHUFFFS,
                        *SBHUFFDS,
                        *SBHUFFDT,
                        *SBHUFFRDW,
                        *SBHUFFRDH,
                        *SBHUFFRDX,
                        *SBHUFFRDY,
                        *SBHUFFRSIZE;
    FX_BOOL SBRTEMPLATE;
    signed char SBRAT[4];
};
class CJBig2_SDDProc : public CJBig2_Object
{
public:

    CJBig2_SymbolDict *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, JBig2ArithCtx *grContext);

    CJBig2_SymbolDict *decode_Huffman(CJBig2_BitStream *pStream, JBig2ArithCtx *gbContext, JBig2ArithCtx *grContext, IFX_Pause* pPause);
public:
    FX_BOOL SDHUFF;
    FX_BOOL SDREFAGG;
    FX_DWORD SDNUMINSYMS;
    CJBig2_Image ** SDINSYMS;
    FX_DWORD SDNUMNEWSYMS;
    FX_DWORD SDNUMEXSYMS;
    CJBig2_HuffmanTable *SDHUFFDH,
                        *SDHUFFDW,
                        *SDHUFFBMSIZE,
                        *SDHUFFAGGINST;
    uint8_t SDTEMPLATE;
    signed char SDAT[8];
    FX_BOOL SDRTEMPLATE;
    signed char SDRAT[4];
};
class CJBig2_HTRDProc : public CJBig2_Object
{
public:

    CJBig2_Image *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);

    CJBig2_Image *decode_MMR(CJBig2_BitStream *pStream, IFX_Pause* pPause);
public:
    FX_DWORD HBW,
             HBH;
    FX_BOOL HMMR;
    uint8_t HTEMPLATE;
    FX_DWORD HNUMPATS;
    CJBig2_Image **HPATS;
    FX_BOOL HDEFPIXEL;
    JBig2ComposeOp HCOMBOP;
    FX_BOOL HENABLESKIP;
    FX_DWORD HGW,
             HGH;
    int32_t HGX,
             HGY;
    FX_WORD HRX,
            HRY;
    uint8_t HPW,
            HPH;
};
class CJBig2_PDDProc : public CJBig2_Object
{
public:

    CJBig2_PatternDict *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);

    CJBig2_PatternDict *decode_MMR(CJBig2_BitStream *pStream, IFX_Pause* pPause);
public:
    FX_BOOL HDMMR;
    uint8_t HDPW,
            HDPH;
    FX_DWORD GRAYMAX;
    uint8_t HDTEMPLATE;
};
class CJBig2_GSIDProc : public CJBig2_Object
{
public:

    FX_DWORD *decode_Arith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext, IFX_Pause* pPause);

    FX_DWORD *decode_MMR(CJBig2_BitStream *pStream, IFX_Pause* pPause);
public:
    FX_BOOL GSMMR;
    FX_BOOL GSUSESKIP;
    uint8_t GSBPP;
    FX_DWORD GSW,
             GSH;
    uint8_t GSTEMPLATE;
    CJBig2_Image *GSKIP;
};
#endif