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 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "JBig2_Module.h" | 13 #include "JBig2_Module.h" |
14 #include "JBig2_List.h" | 14 #include "JBig2_List.h" |
15 #include "JBig2_Segment.h" | 15 #include "JBig2_Segment.h" |
16 #include "JBig2_Page.h" | 16 #include "JBig2_Page.h" |
17 #include "JBig2_GeneralDecoder.h" | 17 #include "JBig2_GeneralDecoder.h" |
18 #include "../../../include/fxcodec/fx_codec_def.h" | 18 #include "../../../include/fxcodec/fx_codec_def.h" |
19 | 19 |
20 typedef std::pair<uint8_t*, CJBig2_SymbolDict*> CJBig2_CachePair; | 20 typedef std::pair<uint8_t*, CJBig2_SymbolDict*> CJBig2_CachePair; |
21 typedef enum { | 21 typedef enum { |
22 JBIG2_OUT_OF_PAGE = 0, | 22 JBIG2_OUT_OF_PAGE = 0, |
23 JBIG2_IN_PAGE, | 23 JBIG2_IN_PAGE, |
24 } JBig2State; | 24 } JBig2State; |
25 #define JBIG2_SUCCESS» » » 0 | 25 #define JBIG2_SUCCESS 0 |
26 #define JBIG2_FAILED» » » -1 | 26 #define JBIG2_FAILED -1 |
27 #define JBIG2_ERROR_TOO_SHORT» -2 | 27 #define JBIG2_ERROR_TOO_SHORT -2 |
28 #define JBIG2_ERROR_FATAL» » -3 | 28 #define JBIG2_ERROR_FATAL -3 |
29 #define JBIG2_END_OF_PAGE» » 2 | 29 #define JBIG2_END_OF_PAGE 2 |
30 #define JBIG2_END_OF_FILE» » 3 | 30 #define JBIG2_END_OF_FILE 3 |
31 #define JBIG2_ERROR_FILE_FORMAT -4 | 31 #define JBIG2_ERROR_FILE_FORMAT -4 |
32 #define JBIG2_ERROR_STREAM_TYPE -5 | 32 #define JBIG2_ERROR_STREAM_TYPE -5 |
33 #define JBIG2_ERROR_LIMIT» » -6 | 33 #define JBIG2_ERROR_LIMIT -6 |
34 #define JBIG2_FILE_STREAM» » » 0 | 34 #define JBIG2_FILE_STREAM 0 |
35 #define JBIG2_SQUENTIAL_STREAM» » 1 | 35 #define JBIG2_SQUENTIAL_STREAM 1 |
36 #define JBIG2_RANDOM_STREAM» » » 2 | 36 #define JBIG2_RANDOM_STREAM 2 |
37 #define JBIG2_EMBED_STREAM» » » 3 | 37 #define JBIG2_EMBED_STREAM 3 |
38 #define JBIG2_MIN_SEGMENT_SIZE» » » » » 11 | 38 #define JBIG2_MIN_SEGMENT_SIZE 11 |
39 class CJBig2_Context : public CJBig2_Object | 39 class CJBig2_Context : public CJBig2_Object { |
40 { | 40 public: |
41 public: | 41 static CJBig2_Context* CreateContext( |
| 42 CJBig2_Module* pModule, |
| 43 uint8_t* pGlobalData, |
| 44 FX_DWORD dwGlobalLength, |
| 45 uint8_t* pData, |
| 46 FX_DWORD dwLength, |
| 47 int32_t nStreamType, |
| 48 std::list<CJBig2_CachePair>* pSymbolDictCache, |
| 49 IFX_Pause* pPause = NULL); |
42 | 50 |
43 static CJBig2_Context *CreateContext(CJBig2_Module *pModule, uint8_t *pGloba
lData, FX_DWORD dwGlobalLength, | 51 static void DestroyContext(CJBig2_Context* pContext); |
44 uint8_t *pData, FX_DWORD dwLength, int3
2_t nStreamType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPaus
e = NULL); | |
45 | 52 |
46 static void DestroyContext(CJBig2_Context *pContext); | 53 int32_t getFirstPage(uint8_t* pBuf, |
| 54 int32_t width, |
| 55 int32_t height, |
| 56 int32_t stride, |
| 57 IFX_Pause* pPause); |
47 | 58 |
48 int32_t getFirstPage(uint8_t *pBuf, int32_t width, int32_t height, int32_t s
tride, IFX_Pause* pPause); | 59 int32_t getNextPage(uint8_t* pBuf, |
| 60 int32_t width, |
| 61 int32_t height, |
| 62 int32_t stride, |
| 63 IFX_Pause* pPause); |
49 | 64 |
50 int32_t getNextPage(uint8_t *pBuf, int32_t width, int32_t height, int32_t st
ride, IFX_Pause* pPause); | 65 int32_t getFirstPage(CJBig2_Image** image, IFX_Pause* pPause); |
51 | 66 |
52 int32_t getFirstPage(CJBig2_Image **image, IFX_Pause* pPause); | 67 int32_t getNextPage(CJBig2_Image** image, IFX_Pause* pPause); |
| 68 int32_t Continue(IFX_Pause* pPause); |
| 69 FXCODEC_STATUS GetProcessiveStatus() { return m_ProcessiveStatus; }; |
53 | 70 |
54 int32_t getNextPage(CJBig2_Image **image, IFX_Pause* pPause); | 71 private: |
55 int32_t Continue(IFX_Pause* pPause); | 72 CJBig2_Context(uint8_t* pGlobalData, |
56 FXCODEC_STATUS GetProcessiveStatus() | 73 FX_DWORD dwGlobalLength, |
57 { | 74 uint8_t* pData, |
58 return m_ProcessiveStatus; | 75 FX_DWORD dwLength, |
59 }; | 76 int32_t nStreamType, |
60 private: | 77 std::list<CJBig2_CachePair>* pSymbolDictCache, |
| 78 IFX_Pause* pPause); |
61 | 79 |
62 CJBig2_Context(uint8_t *pGlobalData, FX_DWORD dwGlobalLength, | 80 ~CJBig2_Context(); |
63 uint8_t *pData, FX_DWORD dwLength, int32_t nStreamType, std::
list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause); | |
64 | 81 |
65 ~CJBig2_Context(); | 82 int32_t decodeFile(IFX_Pause* pPause); |
66 | 83 |
67 int32_t decodeFile(IFX_Pause* pPause); | 84 int32_t decode_SquentialOrgnazation(IFX_Pause* pPause); |
68 | 85 |
69 int32_t decode_SquentialOrgnazation(IFX_Pause* pPause); | 86 int32_t decode_EmbedOrgnazation(IFX_Pause* pPause); |
70 | 87 |
71 int32_t decode_EmbedOrgnazation(IFX_Pause* pPause); | 88 int32_t decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause); |
72 | 89 |
73 int32_t decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause); | 90 int32_t decode_RandomOrgnazation(IFX_Pause* pPause); |
74 | 91 |
75 int32_t decode_RandomOrgnazation(IFX_Pause* pPause); | 92 CJBig2_Segment* findSegmentByNumber(FX_DWORD dwNumber); |
76 | 93 |
77 CJBig2_Segment *findSegmentByNumber(FX_DWORD dwNumber); | 94 CJBig2_Segment* findReferredSegmentByTypeAndIndex(CJBig2_Segment* pSegment, |
| 95 uint8_t cType, |
| 96 int32_t nIndex); |
78 | 97 |
79 CJBig2_Segment *findReferredSegmentByTypeAndIndex(CJBig2_Segment *pSegment,
uint8_t cType, int32_t nIndex); | 98 int32_t parseSegmentHeader(CJBig2_Segment* pSegment); |
80 | 99 |
81 int32_t parseSegmentHeader(CJBig2_Segment *pSegment); | 100 int32_t parseSegmentData(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
| 101 int32_t ProcessiveParseSegmentData(CJBig2_Segment* pSegment, |
| 102 IFX_Pause* pPause); |
82 | 103 |
83 int32_t parseSegmentData(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 104 int32_t parseSymbolDict(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
84 int32_t ProcessiveParseSegmentData(CJBig2_Segment *pSegment, IFX_Pause* pPau
se); | |
85 | 105 |
86 int32_t parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 106 int32_t parseTextRegion(CJBig2_Segment* pSegment); |
87 | 107 |
88 int32_t parseTextRegion(CJBig2_Segment *pSegment); | 108 int32_t parsePatternDict(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
89 | 109 |
90 int32_t parsePatternDict(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 110 int32_t parseHalftoneRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
91 | 111 |
92 int32_t parseHalftoneRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 112 int32_t parseGenericRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause); |
93 | 113 |
94 int32_t parseGenericRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause); | 114 int32_t parseGenericRefinementRegion(CJBig2_Segment* pSegment); |
95 | 115 |
96 int32_t parseGenericRefinementRegion(CJBig2_Segment *pSegment); | 116 int32_t parseTable(CJBig2_Segment* pSegment); |
97 | 117 |
98 int32_t parseTable(CJBig2_Segment *pSegment); | 118 int32_t parseRegionInfo(JBig2RegionInfo* pRI); |
99 | 119 |
100 int32_t parseRegionInfo(JBig2RegionInfo *pRI); | 120 JBig2HuffmanCode* decodeSymbolIDHuffmanTable(CJBig2_BitStream* pStream, |
| 121 FX_DWORD SBNUMSYMS); |
101 | 122 |
| 123 void huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP); |
102 | 124 |
| 125 void huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, int NTEMP); |
103 | 126 |
104 JBig2HuffmanCode *decodeSymbolIDHuffmanTable(CJBig2_BitStream *pStream, FX_D
WORD SBNUMSYMS); | 127 private: |
| 128 CJBig2_Context* m_pGlobalContext; |
105 | 129 |
106 void huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP); | 130 int32_t m_nStreamType; |
107 | 131 |
108 void huffman_assign_code(JBig2HuffmanCode *SBSYMCODES, int NTEMP); | 132 CJBig2_BitStream* m_pStream; |
109 | 133 |
110 private: | 134 int32_t m_nState; |
111 | 135 |
112 CJBig2_Context *m_pGlobalContext; | 136 CJBig2_List<CJBig2_Segment>* m_pSegmentList; |
113 | 137 |
114 int32_t m_nStreamType; | 138 CJBig2_List<JBig2PageInfo>* m_pPageInfoList; |
115 | 139 |
116 CJBig2_BitStream *m_pStream; | 140 CJBig2_Image* m_pPage; |
117 | 141 |
118 int32_t m_nState; | 142 FX_BOOL m_bBufSpecified; |
119 | 143 |
120 CJBig2_List<CJBig2_Segment> *m_pSegmentList; | 144 int32_t m_nSegmentDecoded; |
121 | 145 IFX_Pause* m_pPause; |
122 CJBig2_List<JBig2PageInfo> *m_pPageInfoList; | 146 int32_t m_PauseStep; |
123 | 147 FXCODEC_STATUS m_ProcessiveStatus; |
124 CJBig2_Image *m_pPage; | 148 FX_BOOL m_bFirstPage; |
125 | 149 CJBig2_ArithDecoder* m_pArithDecoder; |
126 FX_BOOL m_bBufSpecified; | 150 CJBig2_GRDProc* m_pGRD; |
127 | 151 JBig2ArithCtx* m_gbContext; |
128 int32_t m_nSegmentDecoded; | 152 CJBig2_Segment* m_pSegment; |
129 IFX_Pause*» m_pPause; | 153 FX_DWORD m_dwOffset; |
130 int32_t» m_PauseStep; | 154 JBig2RegionInfo m_ri; |
131 FXCODEC_STATUS m_ProcessiveStatus; | 155 std::list<CJBig2_CachePair>* m_pSymbolDictCache; |
132 FX_BOOL» m_bFirstPage; | |
133 CJBig2_ArithDecoder *m_pArithDecoder; | |
134 CJBig2_GRDProc *m_pGRD; | |
135 JBig2ArithCtx *m_gbContext; | |
136 CJBig2_Segment *m_pSegment; | |
137 FX_DWORD m_dwOffset; | |
138 JBig2RegionInfo m_ri; | |
139 std::list<CJBig2_CachePair>* m_pSymbolDictCache; | |
140 }; | 156 }; |
141 #endif | 157 #endif |
OLD | NEW |