OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef _JBIG2_CONTEXT_H_ | 7 #ifndef _JBIG2_CONTEXT_H_ |
8 #define _JBIG2_CONTEXT_H_ | 8 #define _JBIG2_CONTEXT_H_ |
9 #include "JBig2_Module.h" | 9 #include "JBig2_Module.h" |
10 #include "JBig2_List.h" | 10 #include "JBig2_List.h" |
11 #include "JBig2_Segment.h" | 11 #include "JBig2_Segment.h" |
12 #include "JBig2_Page.h" | 12 #include "JBig2_Page.h" |
13 #include "JBig2_GeneralDecoder.h" | 13 #include "JBig2_GeneralDecoder.h" |
14 #include "../../../include/fxcodec/fx_codec_def.h" | 14 #include "../../../include/fxcodec/fx_codec_def.h" |
15 #include "../../../include/fxcrt/fx_basic.h" | 15 #include "../../../include/fxcrt/fx_basic.h" |
16 typedef enum { | 16 typedef enum { |
17 JBIG2_OUT_OF_PAGE = 0, | 17 JBIG2_OUT_OF_PAGE = 0, |
18 JBIG2_IN_PAGE, | 18 JBIG2_IN_PAGE, |
19 } JBig2State; | 19 } JBig2State; |
20 #define JBIG2_SUCCESS» » » 0 | 20 #define JBIG2_SUCCESS 0 |
21 #define JBIG2_FAILED» » » -1 | 21 #define JBIG2_FAILED -1 |
22 #define JBIG2_ERROR_TOO_SHORT» -2 | 22 #define JBIG2_ERROR_TOO_SHORT -2 |
23 #define JBIG2_ERROR_FETAL» » -3 | 23 #define JBIG2_ERROR_FETAL -3 |
24 #define JBIG2_END_OF_PAGE» » 2 | 24 #define JBIG2_END_OF_PAGE 2 |
25 #define JBIG2_END_OF_FILE» » 3 | 25 #define JBIG2_END_OF_FILE 3 |
26 #define JBIG2_ERROR_FILE_FORMAT -4 | 26 #define JBIG2_ERROR_FILE_FORMAT -4 |
27 #define JBIG2_ERROR_STREAM_TYPE -5 | 27 #define JBIG2_ERROR_STREAM_TYPE -5 |
28 #define JBIG2_ERROR_LIMIT» » -6 | 28 #define JBIG2_ERROR_LIMIT -6 |
29 #define JBIG2_FILE_STREAM» » » 0 | 29 #define JBIG2_FILE_STREAM 0 |
30 #define JBIG2_SQUENTIAL_STREAM» » 1 | 30 #define JBIG2_SQUENTIAL_STREAM 1 |
31 #define JBIG2_RANDOM_STREAM» » » 2 | 31 #define JBIG2_RANDOM_STREAM 2 |
32 #define JBIG2_EMBED_STREAM» » » 3 | 32 #define JBIG2_EMBED_STREAM 3 |
33 #define JBIG2_MIN_SEGMENT_SIZE» » » » » 11 | 33 #define JBIG2_MIN_SEGMENT_SIZE 11 |
34 class CJBig2_Context : public CJBig2_Object | 34 class CJBig2_Context : public CJBig2_Object { |
35 { | 35 public: |
36 public: | 36 static CJBig2_Context* CreateContext(CJBig2_Module* pModule, |
| 37 FX_BYTE* pGlobalData, |
| 38 FX_DWORD dwGlobalLength, |
| 39 FX_BYTE* pData, |
| 40 FX_DWORD dwLength, |
| 41 FX_INT32 nStreamType, |
| 42 IFX_Pause* pPause = NULL); |
37 | 43 |
38 static CJBig2_Context *CreateContext(CJBig2_Module *pModule, FX_BYTE *pGloba
lData, FX_DWORD dwGlobalLength, | 44 static void DestroyContext(CJBig2_Context* pContext); |
39 FX_BYTE *pData, FX_DWORD dwLength, FX_I
NT32 nStreamType, IFX_Pause* pPause = NULL); | |
40 | 45 |
41 static void DestroyContext(CJBig2_Context *pContext); | 46 FX_INT32 getFirstPage(FX_BYTE* pBuf, |
| 47 FX_INT32 width, |
| 48 FX_INT32 height, |
| 49 FX_INT32 stride, |
| 50 IFX_Pause* pPause); |
42 | 51 |
43 FX_INT32 getFirstPage(FX_BYTE *pBuf, FX_INT32 width, FX_INT32 height, FX_INT
32 stride, IFX_Pause* pPause); | 52 FX_INT32 getNextPage(FX_BYTE* pBuf, |
| 53 FX_INT32 width, |
| 54 FX_INT32 height, |
| 55 FX_INT32 stride, |
| 56 IFX_Pause* pPause); |
44 | 57 |
45 FX_INT32 getNextPage(FX_BYTE *pBuf, FX_INT32 width, FX_INT32 height, FX_INT3
2 stride, IFX_Pause* pPause); | 58 FX_INT32 getFirstPage(CJBig2_Image** image, IFX_Pause* pPause); |
46 | 59 |
47 FX_INT32 getFirstPage(CJBig2_Image **image, IFX_Pause* pPause); | 60 FX_INT32 getNextPage(CJBig2_Image** image, IFX_Pause* pPause); |
| 61 FX_INT32 Continue(IFX_Pause* pPause); |
| 62 FXCODEC_STATUS GetProcessiveStatus() { return m_ProcessiveStatus; }; |
48 | 63 |
49 FX_INT32 getNextPage(CJBig2_Image **image, IFX_Pause* pPause); | 64 private: |
50 FX_INT32 Continue(IFX_Pause* pPause); | 65 CJBig2_Context(FX_BYTE* pGlobalData, |
51 FXCODEC_STATUS GetProcessiveStatus() | 66 FX_DWORD dwGlobalLength, |
52 { | 67 FX_BYTE* pData, |
53 return m_ProcessiveStatus; | 68 FX_DWORD dwLength, |
54 }; | 69 FX_INT32 nStreamType, |
55 private: | 70 IFX_Pause* pPause); |
56 | 71 |
57 CJBig2_Context(FX_BYTE *pGlobalData, FX_DWORD dwGlobalLength, | 72 ~CJBig2_Context(); |
58 FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, IFX_
Pause* pPause); | |
59 | 73 |
60 ~CJBig2_Context(); | 74 FX_INT32 decodeFile(IFX_Pause* pPause); |
61 | 75 |
62 FX_INT32 decodeFile(IFX_Pause* pPause); | 76 FX_INT32 decode_SquentialOrgnazation(IFX_Pause* pPause); |
63 | 77 |
64 FX_INT32 decode_SquentialOrgnazation(IFX_Pause* pPause); | 78 FX_INT32 decode_EmbedOrgnazation(IFX_Pause* pPause); |
65 | 79 |
66 FX_INT32 decode_EmbedOrgnazation(IFX_Pause* pPause); | 80 FX_INT32 decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause); |
67 | 81 |
68 FX_INT32 decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause); | 82 FX_INT32 decode_RandomOrgnazation(IFX_Pause* pPause); |
69 | 83 |
70 FX_INT32 decode_RandomOrgnazation(IFX_Pause* pPause); | 84 CJBig2_Segment* findSegmentByNumber(FX_DWORD dwNumber); |
71 | 85 |
72 CJBig2_Segment *findSegmentByNumber(FX_DWORD dwNumber); | 86 CJBig2_Segment* findReferredSegmentByTypeAndIndex(CJBig2_Segment* pSegment, |
| 87 FX_BYTE cType, |
| 88 FX_INT32 nIndex); |
73 | 89 |
74 CJBig2_Segment *findReferredSegmentByTypeAndIndex(CJBig2_Segment *pSegment,
FX_BYTE cType, FX_INT32 nIndex); | 90 FX_INT32 parseSegmentHeader(CJBig2_Segment* pSegment); |
75 | 91 |
76 FX_INT32 parseSegmentHeader(CJBig2_Segment *pSegment); | 92 FX_INT32 parseSegmentData(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
| 93 FX_INT32 ProcessiveParseSegmentData(CJBig2_Segment* pSegment, |
| 94 IFX_Pause* pPause); |
77 | 95 |
78 FX_INT32 parseSegmentData(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 96 FX_INT32 parseSymbolDict(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
79 FX_INT32 ProcessiveParseSegmentData(CJBig2_Segment *pSegment, IFX_Pause* pPa
use); | |
80 | 97 |
81 FX_INT32 parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 98 FX_INT32 parseTextRegion(CJBig2_Segment* pSegment); |
82 | 99 |
83 FX_INT32 parseTextRegion(CJBig2_Segment *pSegment); | 100 FX_INT32 parsePatternDict(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
84 | 101 |
85 FX_INT32 parsePatternDict(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 102 FX_INT32 parseHalftoneRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
86 | 103 |
87 FX_INT32 parseHalftoneRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 104 FX_INT32 parseGenericRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
88 | 105 |
89 FX_INT32 parseGenericRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 106 FX_INT32 parseGenericRefinementRegion(CJBig2_Segment* pSegment); |
90 | 107 |
91 FX_INT32 parseGenericRefinementRegion(CJBig2_Segment *pSegment); | 108 FX_INT32 parseTable(CJBig2_Segment* pSegment); |
92 | 109 |
93 FX_INT32 parseTable(CJBig2_Segment *pSegment); | 110 FX_INT32 parseRegionInfo(JBig2RegionInfo* pRI); |
94 | 111 |
95 FX_INT32 parseRegionInfo(JBig2RegionInfo *pRI); | 112 JBig2HuffmanCode* decodeSymbolIDHuffmanTable(CJBig2_BitStream* pStream, |
| 113 FX_DWORD SBNUMSYMS); |
96 | 114 |
| 115 void huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP); |
97 | 116 |
| 117 void huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, int NTEMP); |
98 | 118 |
99 JBig2HuffmanCode *decodeSymbolIDHuffmanTable(CJBig2_BitStream *pStream, FX_D
WORD SBNUMSYMS); | 119 private: |
| 120 CJBig2_Context* m_pGlobalContext; |
100 | 121 |
101 void huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP); | 122 FX_INT32 m_nStreamType; |
102 | 123 |
103 void huffman_assign_code(JBig2HuffmanCode *SBSYMCODES, int NTEMP); | 124 CJBig2_BitStream* m_pStream; |
104 | 125 |
105 private: | 126 FX_INT32 m_nState; |
106 | 127 |
107 CJBig2_Context *m_pGlobalContext; | 128 CJBig2_List<CJBig2_Segment>* m_pSegmentList; |
108 | 129 |
109 FX_INT32 m_nStreamType; | 130 CJBig2_List<JBig2PageInfo>* m_pPageInfoList; |
110 | 131 |
111 CJBig2_BitStream *m_pStream; | 132 CJBig2_Image* m_pPage; |
112 | 133 |
113 FX_INT32 m_nState; | 134 FX_BOOL m_bBufSpecified; |
114 | 135 |
115 CJBig2_List<CJBig2_Segment> *m_pSegmentList; | 136 FX_INT32 m_nSegmentDecoded; |
116 | 137 IFX_Pause* m_pPause; |
117 CJBig2_List<JBig2PageInfo> *m_pPageInfoList; | 138 FX_INT32 m_PauseStep; |
118 | 139 FXCODEC_STATUS m_ProcessiveStatus; |
119 CJBig2_Image *m_pPage; | 140 FX_BOOL m_bFirstPage; |
120 | 141 CJBig2_ArithDecoder* m_pArithDecoder; |
121 FX_BOOL m_bBufSpecified; | 142 CJBig2_GRDProc* m_pGRD; |
122 | 143 JBig2ArithCtx* m_gbContext; |
123 FX_INT32 m_nSegmentDecoded; | 144 CJBig2_Segment* m_pSegment; |
124 IFX_Pause*» m_pPause; | 145 FX_DWORD m_dwOffset; |
125 FX_INT32» m_PauseStep; | 146 JBig2RegionInfo m_ri; |
126 FXCODEC_STATUS m_ProcessiveStatus; | |
127 FX_BOOL» m_bFirstPage; | |
128 CJBig2_ArithDecoder *m_pArithDecoder; | |
129 CJBig2_GRDProc *m_pGRD; | |
130 JBig2ArithCtx *m_gbContext; | |
131 CJBig2_Segment *m_pSegment; | |
132 FX_DWORD m_dwOffset; | |
133 JBig2RegionInfo m_ri; | |
134 }; | 147 }; |
135 #endif | 148 #endif |
OLD | NEW |