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 #include <map> | |
8 #include <list> | 7 #include <list> |
9 #include "JBig2_Context.h" | 8 #include "JBig2_Context.h" |
10 | 9 |
11 // Implement a very small least recently used (LRU) cache. It is very | 10 // Implement a very small least recently used (LRU) cache. It is very |
12 // common for a JBIG2 dictionary to span multiple pages in a PDF file, | 11 // common for a JBIG2 dictionary to span multiple pages in a PDF file, |
13 // and we do not want to decode the same dictionary over and over | 12 // and we do not want to decode the same dictionary over and over |
14 // again. We key off of the memory location of the dictionary. The | 13 // again. We key off of the memory location of the dictionary. The |
15 // list keeps track of the freshness of entries, with freshest ones | 14 // list keeps track of the freshness of entries, with freshest ones |
16 // at the front. Even a tiny cache size like 2 makes a dramatic | 15 // at the front. Even a tiny cache size like 2 makes a dramatic |
17 // difference for typical JBIG2 documents. | 16 // difference for typical JBIG2 documents. |
(...skipping 22 matching lines...) Expand all Loading... |
40 int32_t nStreamType, | 39 int32_t nStreamType, |
41 std::list<CJBig2_CachePair>* pSymbolDictCache, | 40 std::list<CJBig2_CachePair>* pSymbolDictCache, |
42 IFX_Pause* pPause) { | 41 IFX_Pause* pPause) { |
43 if (pGlobalData && (dwGlobalLength > 0)) { | 42 if (pGlobalData && (dwGlobalLength > 0)) { |
44 JBIG2_ALLOC(m_pGlobalContext, | 43 JBIG2_ALLOC(m_pGlobalContext, |
45 CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength, | 44 CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength, |
46 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); | 45 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); |
47 } else { | 46 } else { |
48 m_pGlobalContext = NULL; | 47 m_pGlobalContext = NULL; |
49 } | 48 } |
50 JBIG2_ALLOC(m_pStream, CJBig2_BitStream(pData, dwLength)); | 49 m_pStream = new CJBig2_BitStream(pData, dwLength); |
51 m_nStreamType = nStreamType; | 50 m_nStreamType = nStreamType; |
52 m_nState = JBIG2_OUT_OF_PAGE; | 51 m_nState = JBIG2_OUT_OF_PAGE; |
53 JBIG2_ALLOC(m_pSegmentList, CJBig2_List<CJBig2_Segment>); | |
54 JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(1)); | |
55 m_pPage = NULL; | 52 m_pPage = NULL; |
56 m_bBufSpecified = FALSE; | 53 m_bBufSpecified = FALSE; |
57 m_pPause = pPause; | 54 m_pPause = pPause; |
58 m_nSegmentDecoded = 0; | 55 m_nSegmentDecoded = 0; |
59 m_PauseStep = 10; | 56 m_PauseStep = 10; |
60 m_pArithDecoder = NULL; | 57 m_pArithDecoder = NULL; |
61 m_pGRD = NULL; | 58 m_pGRD = NULL; |
62 m_gbContext = NULL; | 59 m_gbContext = NULL; |
63 m_pSegment = NULL; | |
64 m_dwOffset = 0; | 60 m_dwOffset = 0; |
65 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; | 61 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; |
66 m_pSymbolDictCache = pSymbolDictCache; | 62 m_pSymbolDictCache = pSymbolDictCache; |
67 } | 63 } |
68 CJBig2_Context::~CJBig2_Context() { | 64 CJBig2_Context::~CJBig2_Context() { |
69 delete m_pArithDecoder; | 65 delete m_pArithDecoder; |
70 m_pArithDecoder = NULL; | 66 m_pArithDecoder = NULL; |
71 delete m_pGRD; | 67 delete m_pGRD; |
72 m_pGRD = NULL; | 68 m_pGRD = NULL; |
73 if (m_gbContext) { | 69 if (m_gbContext) { |
74 m_pModule->JBig2_Free(m_gbContext); | 70 m_pModule->JBig2_Free(m_gbContext); |
75 } | 71 } |
76 m_gbContext = NULL; | 72 m_gbContext = NULL; |
77 delete m_pGlobalContext; | 73 delete m_pGlobalContext; |
78 m_pGlobalContext = NULL; | 74 m_pGlobalContext = NULL; |
79 delete m_pPageInfoList; | |
80 m_pPageInfoList = NULL; | |
81 if (m_bBufSpecified) { | 75 if (m_bBufSpecified) { |
82 delete m_pPage; | 76 delete m_pPage; |
83 } | 77 } |
84 m_pPage = NULL; | 78 m_pPage = NULL; |
85 delete m_pStream; | 79 delete m_pStream; |
86 m_pStream = NULL; | 80 m_pStream = NULL; |
87 delete m_pSegmentList; | |
88 m_pSegmentList = NULL; | |
89 } | 81 } |
90 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) { | 82 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) { |
91 uint8_t cFlags; | 83 uint8_t cFlags; |
92 FX_DWORD dwTemp; | 84 FX_DWORD dwTemp; |
93 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; | 85 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; |
94 int32_t nRet; | 86 int32_t nRet; |
95 if (m_pStream->getByteLeft() < 8) { | 87 if (m_pStream->getByteLeft() < 8) { |
96 m_pModule->JBig2_Error("file header too short."); | 88 m_pModule->JBig2_Error("file header too short."); |
97 nRet = JBIG2_ERROR_TOO_SHORT; | 89 nRet = JBIG2_ERROR_TOO_SHORT; |
98 goto failed; | 90 goto failed; |
99 } | 91 } |
100 if (JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) { | 92 if (JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) { |
101 m_pModule->JBig2_Error("not jbig2 file"); | 93 m_pModule->JBig2_Error("not jbig2 file"); |
102 nRet = JBIG2_ERROR_FILE_FORMAT; | 94 nRet = JBIG2_ERROR_FILE_FORMAT; |
103 goto failed; | 95 goto failed; |
104 } | 96 } |
105 m_pStream->offset(8); | 97 m_pStream->offset(8); |
106 if (m_pStream->read1Byte(&cFlags) != 0) { | 98 if (m_pStream->read1Byte(&cFlags) != 0) { |
107 m_pModule->JBig2_Error("file header too short."); | 99 m_pModule->JBig2_Error("file header too short."); |
108 nRet = JBIG2_ERROR_TOO_SHORT; | 100 nRet = JBIG2_ERROR_TOO_SHORT; |
109 goto failed; | 101 goto failed; |
110 } | 102 } |
111 if (!(cFlags & 0x02)) { | 103 if (!(cFlags & 0x02)) { |
112 if (m_pStream->readInteger(&dwTemp) != 0) { | 104 if (m_pStream->readInteger(&dwTemp) != 0) { |
113 m_pModule->JBig2_Error("file header too short."); | 105 m_pModule->JBig2_Error("file header too short."); |
114 nRet = JBIG2_ERROR_TOO_SHORT; | 106 nRet = JBIG2_ERROR_TOO_SHORT; |
115 goto failed; | 107 goto failed; |
116 } | 108 } |
117 if (dwTemp > 0) { | 109 if (dwTemp > 0) { |
118 delete m_pPageInfoList; | 110 m_PageInfoList.clear(); |
119 JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(dwTemp)); | 111 m_PageInfoList.resize(dwTemp); |
120 } | 112 } |
121 } | 113 } |
122 if (cFlags & 0x01) { | 114 if (cFlags & 0x01) { |
123 m_nStreamType = JBIG2_SQUENTIAL_STREAM; | 115 m_nStreamType = JBIG2_SQUENTIAL_STREAM; |
124 return decode_SquentialOrgnazation(pPause); | 116 return decode_SquentialOrgnazation(pPause); |
125 } else { | 117 } else { |
126 m_nStreamType = JBIG2_RANDOM_STREAM; | 118 m_nStreamType = JBIG2_RANDOM_STREAM; |
127 return decode_RandomOrgnazation_FirstPage(pPause); | 119 return decode_RandomOrgnazation_FirstPage(pPause); |
128 } | 120 } |
129 failed: | 121 failed: |
130 return nRet; | 122 return nRet; |
131 } | 123 } |
132 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { | 124 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { |
133 int32_t nRet; | 125 int32_t nRet; |
134 if (m_pStream->getByteLeft() > 0) { | 126 if (m_pStream->getByteLeft() <= 0) |
135 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { | 127 return JBIG2_END_OF_FILE; |
136 if (m_pSegment == NULL) { | 128 |
137 JBIG2_ALLOC(m_pSegment, CJBig2_Segment()); | 129 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { |
138 nRet = parseSegmentHeader(m_pSegment); | 130 if (!m_pSegment) { |
139 if (nRet != JBIG2_SUCCESS) { | 131 m_pSegment.reset(new CJBig2_Segment); |
140 delete m_pSegment; | 132 nRet = parseSegmentHeader(m_pSegment.get()); |
141 m_pSegment = NULL; | 133 if (nRet != JBIG2_SUCCESS) { |
142 return nRet; | 134 m_pSegment.reset(); |
143 } | |
144 m_dwOffset = m_pStream->getOffset(); | |
145 } | |
146 nRet = parseSegmentData(m_pSegment, pPause); | |
147 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | |
148 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | |
149 m_PauseStep = 2; | |
150 return JBIG2_SUCCESS; | |
151 } | |
152 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | |
153 delete m_pSegment; | |
154 m_pSegment = NULL; | |
155 break; | |
156 } else if (nRet != JBIG2_SUCCESS) { | |
157 delete m_pSegment; | |
158 m_pSegment = NULL; | |
159 return nRet; | 135 return nRet; |
160 } | 136 } |
161 m_pSegmentList->addItem(m_pSegment); | 137 m_dwOffset = m_pStream->getOffset(); |
162 if (m_pSegment->m_dwData_length != 0xffffffff) { | |
163 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; | |
164 m_pStream->setOffset(m_dwOffset); | |
165 } else { | |
166 m_pStream->offset(4); | |
167 } | |
168 m_pSegment = NULL; | |
169 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && | |
170 pPause->NeedToPauseNow()) { | |
171 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | |
172 m_PauseStep = 2; | |
173 return JBIG2_SUCCESS; | |
174 } | |
175 } | 138 } |
176 } else { | 139 nRet = parseSegmentData(m_pSegment.get(), pPause); |
177 return JBIG2_END_OF_FILE; | 140 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 141 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 142 m_PauseStep = 2; |
| 143 return JBIG2_SUCCESS; |
| 144 } |
| 145 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { |
| 146 m_pSegment.reset(); |
| 147 return JBIG2_SUCCESS; |
| 148 } |
| 149 if (nRet != JBIG2_SUCCESS) { |
| 150 m_pSegment.reset(); |
| 151 return nRet; |
| 152 } |
| 153 if (m_pSegment->m_dwData_length != 0xffffffff) { |
| 154 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; |
| 155 m_pStream->setOffset(m_dwOffset); |
| 156 } else { |
| 157 m_pStream->offset(4); |
| 158 } |
| 159 m_SegmentList.push_back(m_pSegment.release()); |
| 160 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && |
| 161 pPause->NeedToPauseNow()) { |
| 162 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 163 m_PauseStep = 2; |
| 164 return JBIG2_SUCCESS; |
| 165 } |
178 } | 166 } |
179 return JBIG2_SUCCESS; | 167 return JBIG2_SUCCESS; |
180 } | 168 } |
181 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { | 169 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { |
182 return decode_SquentialOrgnazation(pPause); | 170 return decode_SquentialOrgnazation(pPause); |
183 } | 171 } |
184 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { | 172 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { |
185 CJBig2_Segment* pSegment; | |
186 int32_t nRet; | 173 int32_t nRet; |
187 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { | 174 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { |
188 JBIG2_ALLOC(pSegment, CJBig2_Segment()); | 175 nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); |
189 nRet = parseSegmentHeader(pSegment); | 176 nRet = parseSegmentHeader(pSegment.get()); |
190 if (nRet != JBIG2_SUCCESS) { | 177 if (nRet != JBIG2_SUCCESS) { |
191 delete pSegment; | |
192 return nRet; | 178 return nRet; |
193 } else if (pSegment->m_cFlags.s.type == 51) { | 179 } else if (pSegment->m_cFlags.s.type == 51) { |
194 delete pSegment; | |
195 break; | 180 break; |
196 } | 181 } |
197 m_pSegmentList->addItem(pSegment); | 182 m_SegmentList.push_back(pSegment.release()); |
198 if (pPause && m_pPause && pPause->NeedToPauseNow()) { | 183 if (pPause && m_pPause && pPause->NeedToPauseNow()) { |
199 m_PauseStep = 3; | 184 m_PauseStep = 3; |
200 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 185 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
201 return JBIG2_SUCCESS; | 186 return JBIG2_SUCCESS; |
202 } | 187 } |
203 } | 188 } |
204 m_nSegmentDecoded = 0; | 189 m_nSegmentDecoded = 0; |
205 return decode_RandomOrgnazation(pPause); | 190 return decode_RandomOrgnazation(pPause); |
206 } | 191 } |
207 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { | 192 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { |
208 int32_t nRet; | 193 for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) { |
209 for (; m_nSegmentDecoded < m_pSegmentList->getLength(); m_nSegmentDecoded++) { | 194 int32_t nRet = |
210 nRet = parseSegmentData(m_pSegmentList->getAt(m_nSegmentDecoded), pPause); | 195 parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause); |
211 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | 196 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) |
212 break; | 197 return JBIG2_SUCCESS; |
213 } else if (nRet != JBIG2_SUCCESS) { | 198 |
| 199 if (nRet != JBIG2_SUCCESS) |
214 return nRet; | 200 return nRet; |
215 } | 201 |
216 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | 202 if (m_pPage && pPause && pPause->NeedToPauseNow()) { |
217 m_PauseStep = 4; | 203 m_PauseStep = 4; |
218 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 204 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
219 return JBIG2_SUCCESS; | 205 return JBIG2_SUCCESS; |
220 } | 206 } |
221 } | 207 } |
222 return JBIG2_SUCCESS; | 208 return JBIG2_SUCCESS; |
223 } | 209 } |
224 int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, | 210 int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, |
225 int32_t width, | 211 int32_t width, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 291 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
306 if (nRet != JBIG2_SUCCESS) { | 292 if (nRet != JBIG2_SUCCESS) { |
307 return nRet; | 293 return nRet; |
308 } | 294 } |
309 } | 295 } |
310 m_bBufSpecified = FALSE; | 296 m_bBufSpecified = FALSE; |
311 return Continue(pPause); | 297 return Continue(pPause); |
312 } | 298 } |
313 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { | 299 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { |
314 CJBig2_Segment* pSeg; | 300 CJBig2_Segment* pSeg; |
315 int32_t i; | |
316 if (m_pGlobalContext) { | 301 if (m_pGlobalContext) { |
317 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); | 302 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); |
318 if (pSeg) { | 303 if (pSeg) { |
319 return pSeg; | 304 return pSeg; |
320 } | 305 } |
321 } | 306 } |
322 for (i = 0; i < m_pSegmentList->getLength(); i++) { | 307 for (size_t i = 0; i < m_SegmentList.size(); ++i) { |
323 pSeg = m_pSegmentList->getAt(i); | 308 pSeg = m_SegmentList.get(i); |
324 if (pSeg->m_dwNumber == dwNumber) { | 309 if (pSeg->m_dwNumber == dwNumber) { |
325 return pSeg; | 310 return pSeg; |
326 } | 311 } |
327 } | 312 } |
328 return NULL; | 313 return nullptr; |
329 } | 314 } |
330 CJBig2_Segment* CJBig2_Context::findReferredSegmentByTypeAndIndex( | 315 CJBig2_Segment* CJBig2_Context::findReferredSegmentByTypeAndIndex( |
331 CJBig2_Segment* pSegment, | 316 CJBig2_Segment* pSegment, |
332 uint8_t cType, | 317 uint8_t cType, |
333 int32_t nIndex) { | 318 int32_t nIndex) { |
334 CJBig2_Segment* pSeg; | 319 CJBig2_Segment* pSeg; |
335 int32_t i, count; | 320 int32_t i, count; |
336 count = 0; | 321 count = 0; |
337 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { | 322 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { |
338 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 323 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 case 40: | 458 case 40: |
474 case 42: | 459 case 42: |
475 case 43: | 460 case 43: |
476 if (m_nState == JBIG2_OUT_OF_PAGE) { | 461 if (m_nState == JBIG2_OUT_OF_PAGE) { |
477 goto failed2; | 462 goto failed2; |
478 } else { | 463 } else { |
479 return parseGenericRefinementRegion(pSegment); | 464 return parseGenericRefinementRegion(pSegment); |
480 } | 465 } |
481 case 48: { | 466 case 48: { |
482 FX_WORD wTemp; | 467 FX_WORD wTemp; |
483 JBig2PageInfo* pPageInfo; | 468 nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); |
484 JBIG2_ALLOC(pPageInfo, JBig2PageInfo); | |
485 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || | 469 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || |
486 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || | 470 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || |
487 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || | 471 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || |
488 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || | 472 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || |
489 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || | 473 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || |
490 (m_pStream->readShortInteger(&wTemp) != 0)) { | 474 (m_pStream->readShortInteger(&wTemp) != 0)) { |
491 delete pPageInfo; | |
492 goto failed1; | 475 goto failed1; |
493 } | 476 } |
494 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0; | 477 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0; |
495 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; | 478 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; |
496 if ((pPageInfo->m_dwHeight == 0xffffffff) && | 479 if ((pPageInfo->m_dwHeight == 0xffffffff) && |
497 (pPageInfo->m_bIsStriped != 1)) { | 480 (pPageInfo->m_bIsStriped != TRUE)) { |
498 m_pModule->JBig2_Warn("page height = 0xffffffff buf stripe field is 0"); | 481 m_pModule->JBig2_Warn("page height = 0xffffffff buf stripe field is 0"); |
499 pPageInfo->m_bIsStriped = 1; | 482 pPageInfo->m_bIsStriped = TRUE; |
500 } | 483 } |
501 if (!m_bBufSpecified) { | 484 if (!m_bBufSpecified) { |
502 delete m_pPage; | 485 delete m_pPage; |
503 if (pPageInfo->m_dwHeight == 0xffffffff) { | 486 if (pPageInfo->m_dwHeight == 0xffffffff) { |
504 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, | 487 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, |
505 pPageInfo->m_wMaxStripeSize)); | 488 pPageInfo->m_wMaxStripeSize)); |
506 } else { | 489 } else { |
507 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, | 490 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, |
508 pPageInfo->m_dwHeight)); | 491 pPageInfo->m_dwHeight)); |
509 } | 492 } |
510 } | 493 } |
511 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); | 494 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); |
512 m_pPageInfoList->addItem(pPageInfo); | 495 m_PageInfoList.push_back(pPageInfo.release()); |
513 m_nState = JBIG2_IN_PAGE; | 496 m_nState = JBIG2_IN_PAGE; |
514 } break; | 497 } break; |
515 case 49: | 498 case 49: |
516 m_nState = JBIG2_OUT_OF_PAGE; | 499 m_nState = JBIG2_OUT_OF_PAGE; |
517 return JBIG2_END_OF_PAGE; | 500 return JBIG2_END_OF_PAGE; |
518 break; | 501 break; |
519 case 50: | 502 case 50: |
520 m_pStream->offset(pSegment->m_dwData_length); | 503 m_pStream->offset(pSegment->m_dwData_length); |
521 break; | 504 break; |
522 case 51: | 505 case 51: |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 if (pSymbolDictDecoder->SDHUFF == 1) { | 629 if (pSymbolDictDecoder->SDHUFF == 1) { |
647 if ((cSDHUFFDH == 2) || (cSDHUFFDW == 2)) { | 630 if ((cSDHUFFDH == 2) || (cSDHUFFDW == 2)) { |
648 m_pModule->JBig2_Error( | 631 m_pModule->JBig2_Error( |
649 "symbol dictionary segment : SDHUFFDH=2 or SDHUFFDW=2 is not " | 632 "symbol dictionary segment : SDHUFFDH=2 or SDHUFFDW=2 is not " |
650 "permitted."); | 633 "permitted."); |
651 nRet = JBIG2_ERROR_FATAL; | 634 nRet = JBIG2_ERROR_FATAL; |
652 goto failed; | 635 goto failed; |
653 } | 636 } |
654 nIndex = 0; | 637 nIndex = 0; |
655 if (cSDHUFFDH == 0) { | 638 if (cSDHUFFDH == 0) { |
656 JBIG2_ALLOC(Table_B4, CJBig2_HuffmanTable(HuffmanTable_B4, | 639 Table_B4 = new CJBig2_HuffmanTable(HuffmanTable_B4, |
657 sizeof(HuffmanTable_B4) / | 640 FX_ArraySize(HuffmanTable_B4), |
658 sizeof(JBig2TableLine), | 641 HuffmanTable_HTOOB_B4); |
659 HuffmanTable_HTOOB_B4)); | |
660 pSymbolDictDecoder->SDHUFFDH = Table_B4; | 642 pSymbolDictDecoder->SDHUFFDH = Table_B4; |
661 } else if (cSDHUFFDH == 1) { | 643 } else if (cSDHUFFDH == 1) { |
662 JBIG2_ALLOC(Table_B5, CJBig2_HuffmanTable(HuffmanTable_B5, | 644 Table_B5 = new CJBig2_HuffmanTable(HuffmanTable_B5, |
663 sizeof(HuffmanTable_B5) / | 645 FX_ArraySize(HuffmanTable_B5), |
664 sizeof(JBig2TableLine), | 646 HuffmanTable_HTOOB_B5); |
665 HuffmanTable_HTOOB_B5)); | |
666 pSymbolDictDecoder->SDHUFFDH = Table_B5; | 647 pSymbolDictDecoder->SDHUFFDH = Table_B5; |
667 } else { | 648 } else { |
668 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 649 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
669 if (!pSeg) { | 650 if (!pSeg) { |
670 m_pModule->JBig2_Error( | 651 m_pModule->JBig2_Error( |
671 "symbol dictionary segment : SDHUFFDH can't find user supplied " | 652 "symbol dictionary segment : SDHUFFDH can't find user supplied " |
672 "table."); | 653 "table."); |
673 nRet = JBIG2_ERROR_FATAL; | 654 nRet = JBIG2_ERROR_FATAL; |
674 goto failed; | 655 goto failed; |
675 } | 656 } |
676 pSymbolDictDecoder->SDHUFFDH = pSeg->m_Result.ht; | 657 pSymbolDictDecoder->SDHUFFDH = pSeg->m_Result.ht; |
677 } | 658 } |
678 if (cSDHUFFDW == 0) { | 659 if (cSDHUFFDW == 0) { |
679 JBIG2_ALLOC(Table_B2, CJBig2_HuffmanTable(HuffmanTable_B2, | 660 Table_B2 = new CJBig2_HuffmanTable(HuffmanTable_B2, |
680 sizeof(HuffmanTable_B2) / | 661 FX_ArraySize(HuffmanTable_B2), |
681 sizeof(JBig2TableLine), | 662 HuffmanTable_HTOOB_B2); |
682 HuffmanTable_HTOOB_B2)); | |
683 pSymbolDictDecoder->SDHUFFDW = Table_B2; | 663 pSymbolDictDecoder->SDHUFFDW = Table_B2; |
684 } else if (cSDHUFFDW == 1) { | 664 } else if (cSDHUFFDW == 1) { |
685 JBIG2_ALLOC(Table_B3, CJBig2_HuffmanTable(HuffmanTable_B3, | 665 Table_B3 = new CJBig2_HuffmanTable(HuffmanTable_B3, |
686 sizeof(HuffmanTable_B3) / | 666 FX_ArraySize(HuffmanTable_B3), |
687 sizeof(JBig2TableLine), | 667 HuffmanTable_HTOOB_B3); |
688 HuffmanTable_HTOOB_B3)); | |
689 pSymbolDictDecoder->SDHUFFDW = Table_B3; | 668 pSymbolDictDecoder->SDHUFFDW = Table_B3; |
690 } else { | 669 } else { |
691 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 670 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
692 if (!pSeg) { | 671 if (!pSeg) { |
693 m_pModule->JBig2_Error( | 672 m_pModule->JBig2_Error( |
694 "symbol dictionary segment : SDHUFFDW can't find user supplied " | 673 "symbol dictionary segment : SDHUFFDW can't find user supplied " |
695 "table."); | 674 "table."); |
696 nRet = JBIG2_ERROR_FATAL; | 675 nRet = JBIG2_ERROR_FATAL; |
697 goto failed; | 676 goto failed; |
698 } | 677 } |
699 pSymbolDictDecoder->SDHUFFDW = pSeg->m_Result.ht; | 678 pSymbolDictDecoder->SDHUFFDW = pSeg->m_Result.ht; |
700 } | 679 } |
701 if (cSDHUFFBMSIZE == 0) { | 680 if (cSDHUFFBMSIZE == 0) { |
702 JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1, | 681 Table_B1 = new CJBig2_HuffmanTable(HuffmanTable_B1, |
703 sizeof(HuffmanTable_B1) / | 682 FX_ArraySize(HuffmanTable_B1), |
704 sizeof(JBig2TableLine), | 683 HuffmanTable_HTOOB_B1); |
705 HuffmanTable_HTOOB_B1)); | |
706 pSymbolDictDecoder->SDHUFFBMSIZE = Table_B1; | 684 pSymbolDictDecoder->SDHUFFBMSIZE = Table_B1; |
707 } else { | 685 } else { |
708 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 686 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
709 if (!pSeg) { | 687 if (!pSeg) { |
710 m_pModule->JBig2_Error( | 688 m_pModule->JBig2_Error( |
711 "symbol dictionary segment : SDHUFFBMSIZE can't find user supplied " | 689 "symbol dictionary segment : SDHUFFBMSIZE can't find user supplied " |
712 "table."); | 690 "table."); |
713 nRet = JBIG2_ERROR_FATAL; | 691 nRet = JBIG2_ERROR_FATAL; |
714 goto failed; | 692 goto failed; |
715 } | 693 } |
716 pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_Result.ht; | 694 pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_Result.ht; |
717 } | 695 } |
718 if (pSymbolDictDecoder->SDREFAGG == 1) { | 696 if (pSymbolDictDecoder->SDREFAGG == 1) { |
719 if (cSDHUFFAGGINST == 0) { | 697 if (cSDHUFFAGGINST == 0) { |
720 if (!Table_B1) { | 698 if (!Table_B1) { |
721 JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1, | 699 Table_B1 = new CJBig2_HuffmanTable(HuffmanTable_B1, |
722 sizeof(HuffmanTable_B1) / | 700 FX_ArraySize(HuffmanTable_B1), |
723 sizeof(JBig2TableLine), | 701 HuffmanTable_HTOOB_B1); |
724 HuffmanTable_HTOOB_B1)); | |
725 } | 702 } |
726 pSymbolDictDecoder->SDHUFFAGGINST = Table_B1; | 703 pSymbolDictDecoder->SDHUFFAGGINST = Table_B1; |
727 } else { | 704 } else { |
728 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 705 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
729 if (!pSeg) { | 706 if (!pSeg) { |
730 m_pModule->JBig2_Error( | 707 m_pModule->JBig2_Error( |
731 "symbol dictionary segment : SDHUFFAGGINST can't find user " | 708 "symbol dictionary segment : SDHUFFAGGINST can't find user " |
732 "supplied table."); | 709 "supplied table."); |
733 nRet = JBIG2_ERROR_FATAL; | 710 nRet = JBIG2_ERROR_FATAL; |
734 goto failed; | 711 goto failed; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 if (it->first == key) { | 753 if (it->first == key) { |
777 pSegment->m_Result.sd = it->second->DeepCopy(); | 754 pSegment->m_Result.sd = it->second->DeepCopy(); |
778 m_pSymbolDictCache->push_front(*it); | 755 m_pSymbolDictCache->push_front(*it); |
779 m_pSymbolDictCache->erase(it); | 756 m_pSymbolDictCache->erase(it); |
780 cache_hit = true; | 757 cache_hit = true; |
781 break; | 758 break; |
782 } | 759 } |
783 } | 760 } |
784 if (!cache_hit) { | 761 if (!cache_hit) { |
785 if (pSymbolDictDecoder->SDHUFF == 0) { | 762 if (pSymbolDictDecoder->SDHUFF == 0) { |
786 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 763 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
787 pSegment->m_Result.sd = | 764 pSegment->m_Result.sd = |
788 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); | 765 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); |
789 delete pArithDecoder; | 766 delete pArithDecoder; |
790 if (pSegment->m_Result.sd == NULL) { | 767 if (pSegment->m_Result.sd == NULL) { |
791 nRet = JBIG2_ERROR_FATAL; | 768 nRet = JBIG2_ERROR_FATAL; |
792 goto failed; | 769 goto failed; |
793 } | 770 } |
794 m_pStream->alignByte(); | 771 m_pStream->alignByte(); |
795 m_pStream->offset(2); | 772 m_pStream->offset(2); |
796 } else { | 773 } else { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 if ((cSBHUFFFS == 2) || (cSBHUFFRDW == 2) || (cSBHUFFRDH == 2) || | 957 if ((cSBHUFFFS == 2) || (cSBHUFFRDW == 2) || (cSBHUFFRDH == 2) || |
981 (cSBHUFFRDX == 2) || (cSBHUFFRDY == 2)) { | 958 (cSBHUFFRDX == 2) || (cSBHUFFRDY == 2)) { |
982 m_pModule->JBig2_Error( | 959 m_pModule->JBig2_Error( |
983 "text region segment : SBHUFFFS=2 or SBHUFFRDW=2 or " | 960 "text region segment : SBHUFFFS=2 or SBHUFFRDW=2 or " |
984 "SBHUFFRDH=2 or SBHUFFRDX=2 or SBHUFFRDY=2 is not permitted"); | 961 "SBHUFFRDH=2 or SBHUFFRDX=2 or SBHUFFRDY=2 is not permitted"); |
985 nRet = JBIG2_ERROR_FATAL; | 962 nRet = JBIG2_ERROR_FATAL; |
986 goto failed; | 963 goto failed; |
987 } | 964 } |
988 nIndex = 0; | 965 nIndex = 0; |
989 if (cSBHUFFFS == 0) { | 966 if (cSBHUFFFS == 0) { |
990 JBIG2_ALLOC(Table_B6, CJBig2_HuffmanTable(HuffmanTable_B6, | 967 Table_B6 = new CJBig2_HuffmanTable(HuffmanTable_B6, |
991 sizeof(HuffmanTable_B6) / | 968 FX_ArraySize(HuffmanTable_B6), |
992 sizeof(JBig2TableLine), | 969 HuffmanTable_HTOOB_B6); |
993 HuffmanTable_HTOOB_B6)); | |
994 pTRD->SBHUFFFS = Table_B6; | 970 pTRD->SBHUFFFS = Table_B6; |
995 } else if (cSBHUFFFS == 1) { | 971 } else if (cSBHUFFFS == 1) { |
996 JBIG2_ALLOC(Table_B7, CJBig2_HuffmanTable(HuffmanTable_B7, | 972 Table_B7 = new CJBig2_HuffmanTable(HuffmanTable_B7, |
997 sizeof(HuffmanTable_B7) / | 973 FX_ArraySize(HuffmanTable_B7), |
998 sizeof(JBig2TableLine), | 974 HuffmanTable_HTOOB_B7); |
999 HuffmanTable_HTOOB_B7)); | |
1000 pTRD->SBHUFFFS = Table_B7; | 975 pTRD->SBHUFFFS = Table_B7; |
1001 } else { | 976 } else { |
1002 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 977 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1003 if (!pSeg) { | 978 if (!pSeg) { |
1004 m_pModule->JBig2_Error( | 979 m_pModule->JBig2_Error( |
1005 "text region segment : SBHUFFFS can't find user supplied table"); | 980 "text region segment : SBHUFFFS can't find user supplied table"); |
1006 nRet = JBIG2_ERROR_FATAL; | 981 nRet = JBIG2_ERROR_FATAL; |
1007 goto failed; | 982 goto failed; |
1008 } | 983 } |
1009 pTRD->SBHUFFFS = pSeg->m_Result.ht; | 984 pTRD->SBHUFFFS = pSeg->m_Result.ht; |
1010 } | 985 } |
1011 if (cSBHUFFDS == 0) { | 986 if (cSBHUFFDS == 0) { |
1012 JBIG2_ALLOC(Table_B8, CJBig2_HuffmanTable(HuffmanTable_B8, | 987 Table_B8 = new CJBig2_HuffmanTable(HuffmanTable_B8, |
1013 sizeof(HuffmanTable_B8) / | 988 FX_ArraySize(HuffmanTable_B8), |
1014 sizeof(JBig2TableLine), | 989 HuffmanTable_HTOOB_B8); |
1015 HuffmanTable_HTOOB_B8)); | |
1016 pTRD->SBHUFFDS = Table_B8; | 990 pTRD->SBHUFFDS = Table_B8; |
1017 } else if (cSBHUFFDS == 1) { | 991 } else if (cSBHUFFDS == 1) { |
1018 JBIG2_ALLOC(Table_B9, CJBig2_HuffmanTable(HuffmanTable_B9, | 992 Table_B9 = new CJBig2_HuffmanTable(HuffmanTable_B9, |
1019 sizeof(HuffmanTable_B9) / | 993 FX_ArraySize(HuffmanTable_B9), |
1020 sizeof(JBig2TableLine), | 994 HuffmanTable_HTOOB_B9); |
1021 HuffmanTable_HTOOB_B9)); | |
1022 pTRD->SBHUFFDS = Table_B9; | 995 pTRD->SBHUFFDS = Table_B9; |
1023 } else if (cSBHUFFDS == 2) { | 996 } else if (cSBHUFFDS == 2) { |
1024 JBIG2_ALLOC(Table_B10, CJBig2_HuffmanTable(HuffmanTable_B10, | 997 Table_B10 = new CJBig2_HuffmanTable(HuffmanTable_B10, |
1025 sizeof(HuffmanTable_B10) / | 998 FX_ArraySize(HuffmanTable_B10), |
1026 sizeof(JBig2TableLine), | 999 HuffmanTable_HTOOB_B10); |
1027 HuffmanTable_HTOOB_B10)); | |
1028 pTRD->SBHUFFDS = Table_B10; | 1000 pTRD->SBHUFFDS = Table_B10; |
1029 } else { | 1001 } else { |
1030 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1002 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1031 if (!pSeg) { | 1003 if (!pSeg) { |
1032 m_pModule->JBig2_Error( | 1004 m_pModule->JBig2_Error( |
1033 "text region segment : SBHUFFDS can't find user supplied table"); | 1005 "text region segment : SBHUFFDS can't find user supplied table"); |
1034 nRet = JBIG2_ERROR_FATAL; | 1006 nRet = JBIG2_ERROR_FATAL; |
1035 goto failed; | 1007 goto failed; |
1036 } | 1008 } |
1037 pTRD->SBHUFFDS = pSeg->m_Result.ht; | 1009 pTRD->SBHUFFDS = pSeg->m_Result.ht; |
1038 } | 1010 } |
1039 if (cSBHUFFDT == 0) { | 1011 if (cSBHUFFDT == 0) { |
1040 JBIG2_ALLOC(Table_B11, CJBig2_HuffmanTable(HuffmanTable_B11, | 1012 Table_B11 = new CJBig2_HuffmanTable(HuffmanTable_B11, |
1041 sizeof(HuffmanTable_B11) / | 1013 FX_ArraySize(HuffmanTable_B11), |
1042 sizeof(JBig2TableLine), | 1014 HuffmanTable_HTOOB_B11); |
1043 HuffmanTable_HTOOB_B11)); | |
1044 pTRD->SBHUFFDT = Table_B11; | 1015 pTRD->SBHUFFDT = Table_B11; |
1045 } else if (cSBHUFFDT == 1) { | 1016 } else if (cSBHUFFDT == 1) { |
1046 JBIG2_ALLOC(Table_B12, CJBig2_HuffmanTable(HuffmanTable_B12, | 1017 Table_B12 = new CJBig2_HuffmanTable(HuffmanTable_B12, |
1047 sizeof(HuffmanTable_B12) / | 1018 FX_ArraySize(HuffmanTable_B12), |
1048 sizeof(JBig2TableLine), | 1019 HuffmanTable_HTOOB_B12); |
1049 HuffmanTable_HTOOB_B12)); | |
1050 pTRD->SBHUFFDT = Table_B12; | 1020 pTRD->SBHUFFDT = Table_B12; |
1051 } else if (cSBHUFFDT == 2) { | 1021 } else if (cSBHUFFDT == 2) { |
1052 JBIG2_ALLOC(Table_B13, CJBig2_HuffmanTable(HuffmanTable_B13, | 1022 Table_B13 = new CJBig2_HuffmanTable(HuffmanTable_B13, |
1053 sizeof(HuffmanTable_B13) / | 1023 FX_ArraySize(HuffmanTable_B13), |
1054 sizeof(JBig2TableLine), | 1024 HuffmanTable_HTOOB_B13); |
1055 HuffmanTable_HTOOB_B13)); | |
1056 pTRD->SBHUFFDT = Table_B13; | 1025 pTRD->SBHUFFDT = Table_B13; |
1057 } else { | 1026 } else { |
1058 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1027 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1059 if (!pSeg) { | 1028 if (!pSeg) { |
1060 m_pModule->JBig2_Error( | 1029 m_pModule->JBig2_Error( |
1061 "text region segment : SBHUFFDT can't find user supplied table"); | 1030 "text region segment : SBHUFFDT can't find user supplied table"); |
1062 nRet = JBIG2_ERROR_FATAL; | 1031 nRet = JBIG2_ERROR_FATAL; |
1063 goto failed; | 1032 goto failed; |
1064 } | 1033 } |
1065 pTRD->SBHUFFDT = pSeg->m_Result.ht; | 1034 pTRD->SBHUFFDT = pSeg->m_Result.ht; |
1066 } | 1035 } |
1067 if (cSBHUFFRDW == 0) { | 1036 if (cSBHUFFRDW == 0) { |
1068 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1037 Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14, |
1069 sizeof(HuffmanTable_B14) / | 1038 FX_ArraySize(HuffmanTable_B14), |
1070 sizeof(JBig2TableLine), | 1039 HuffmanTable_HTOOB_B14); |
1071 HuffmanTable_HTOOB_B14)); | |
1072 pTRD->SBHUFFRDW = Table_B14; | 1040 pTRD->SBHUFFRDW = Table_B14; |
1073 } else if (cSBHUFFRDW == 1) { | 1041 } else if (cSBHUFFRDW == 1) { |
1074 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1042 Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15, |
1075 sizeof(HuffmanTable_B15) / | 1043 FX_ArraySize(HuffmanTable_B15), |
1076 sizeof(JBig2TableLine), | 1044 HuffmanTable_HTOOB_B15); |
1077 HuffmanTable_HTOOB_B15)); | |
1078 pTRD->SBHUFFRDW = Table_B15; | 1045 pTRD->SBHUFFRDW = Table_B15; |
1079 } else { | 1046 } else { |
1080 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1047 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1081 if (!pSeg) { | 1048 if (!pSeg) { |
1082 m_pModule->JBig2_Error( | 1049 m_pModule->JBig2_Error( |
1083 "text region segment : SBHUFFRDW can't find user supplied table"); | 1050 "text region segment : SBHUFFRDW can't find user supplied table"); |
1084 nRet = JBIG2_ERROR_FATAL; | 1051 nRet = JBIG2_ERROR_FATAL; |
1085 goto failed; | 1052 goto failed; |
1086 } | 1053 } |
1087 pTRD->SBHUFFRDW = pSeg->m_Result.ht; | 1054 pTRD->SBHUFFRDW = pSeg->m_Result.ht; |
1088 } | 1055 } |
1089 if (cSBHUFFRDH == 0) { | 1056 if (cSBHUFFRDH == 0) { |
1090 if (!Table_B14) { | 1057 if (!Table_B14) { |
1091 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1058 Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14, |
1092 sizeof(HuffmanTable_B14) / | 1059 FX_ArraySize(HuffmanTable_B14), |
1093 sizeof(JBig2TableLine), | 1060 HuffmanTable_HTOOB_B14); |
1094 HuffmanTable_HTOOB_B14)); | |
1095 } | 1061 } |
1096 pTRD->SBHUFFRDH = Table_B14; | 1062 pTRD->SBHUFFRDH = Table_B14; |
1097 } else if (cSBHUFFRDH == 1) { | 1063 } else if (cSBHUFFRDH == 1) { |
1098 if (!Table_B15) { | 1064 if (!Table_B15) { |
1099 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1065 Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15, |
1100 sizeof(HuffmanTable_B15) / | 1066 FX_ArraySize(HuffmanTable_B15), |
1101 sizeof(JBig2TableLine), | 1067 HuffmanTable_HTOOB_B15); |
1102 HuffmanTable_HTOOB_B15)); | |
1103 } | 1068 } |
1104 pTRD->SBHUFFRDH = Table_B15; | 1069 pTRD->SBHUFFRDH = Table_B15; |
1105 } else { | 1070 } else { |
1106 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1071 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1107 if (!pSeg) { | 1072 if (!pSeg) { |
1108 m_pModule->JBig2_Error( | 1073 m_pModule->JBig2_Error( |
1109 "text region segment : SBHUFFRDH can't find user supplied table"); | 1074 "text region segment : SBHUFFRDH can't find user supplied table"); |
1110 nRet = JBIG2_ERROR_FATAL; | 1075 nRet = JBIG2_ERROR_FATAL; |
1111 goto failed; | 1076 goto failed; |
1112 } | 1077 } |
1113 pTRD->SBHUFFRDH = pSeg->m_Result.ht; | 1078 pTRD->SBHUFFRDH = pSeg->m_Result.ht; |
1114 } | 1079 } |
1115 if (cSBHUFFRDX == 0) { | 1080 if (cSBHUFFRDX == 0) { |
1116 if (!Table_B14) { | 1081 if (!Table_B14) { |
1117 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1082 Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14, |
1118 sizeof(HuffmanTable_B14) / | 1083 FX_ArraySize(HuffmanTable_B14), |
1119 sizeof(JBig2TableLine), | 1084 HuffmanTable_HTOOB_B14); |
1120 HuffmanTable_HTOOB_B14)); | |
1121 } | 1085 } |
1122 pTRD->SBHUFFRDX = Table_B14; | 1086 pTRD->SBHUFFRDX = Table_B14; |
1123 } else if (cSBHUFFRDX == 1) { | 1087 } else if (cSBHUFFRDX == 1) { |
1124 if (!Table_B15) { | 1088 if (!Table_B15) { |
1125 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1089 Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15, |
1126 sizeof(HuffmanTable_B15) / | 1090 FX_ArraySize(HuffmanTable_B15), |
1127 sizeof(JBig2TableLine), | 1091 HuffmanTable_HTOOB_B15); |
1128 HuffmanTable_HTOOB_B15)); | |
1129 } | 1092 } |
1130 pTRD->SBHUFFRDX = Table_B15; | 1093 pTRD->SBHUFFRDX = Table_B15; |
1131 } else { | 1094 } else { |
1132 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1095 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1133 if (!pSeg) { | 1096 if (!pSeg) { |
1134 m_pModule->JBig2_Error( | 1097 m_pModule->JBig2_Error( |
1135 "text region segment : SBHUFFRDX can't find user supplied table"); | 1098 "text region segment : SBHUFFRDX can't find user supplied table"); |
1136 nRet = JBIG2_ERROR_FATAL; | 1099 nRet = JBIG2_ERROR_FATAL; |
1137 goto failed; | 1100 goto failed; |
1138 } | 1101 } |
1139 pTRD->SBHUFFRDX = pSeg->m_Result.ht; | 1102 pTRD->SBHUFFRDX = pSeg->m_Result.ht; |
1140 } | 1103 } |
1141 if (cSBHUFFRDY == 0) { | 1104 if (cSBHUFFRDY == 0) { |
1142 if (!Table_B14) { | 1105 if (!Table_B14) { |
1143 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1106 Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14, |
1144 sizeof(HuffmanTable_B14) / | 1107 FX_ArraySize(HuffmanTable_B14), |
1145 sizeof(JBig2TableLine), | 1108 HuffmanTable_HTOOB_B14); |
1146 HuffmanTable_HTOOB_B14)); | |
1147 } | 1109 } |
1148 pTRD->SBHUFFRDY = Table_B14; | 1110 pTRD->SBHUFFRDY = Table_B14; |
1149 } else if (cSBHUFFRDY == 1) { | 1111 } else if (cSBHUFFRDY == 1) { |
1150 if (!Table_B15) { | 1112 if (!Table_B15) { |
1151 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1113 Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15, |
1152 sizeof(HuffmanTable_B15) / | 1114 FX_ArraySize(HuffmanTable_B15), |
1153 sizeof(JBig2TableLine), | 1115 HuffmanTable_HTOOB_B15); |
1154 HuffmanTable_HTOOB_B15)); | |
1155 } | 1116 } |
1156 pTRD->SBHUFFRDY = Table_B15; | 1117 pTRD->SBHUFFRDY = Table_B15; |
1157 } else { | 1118 } else { |
1158 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1119 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1159 if (!pSeg) { | 1120 if (!pSeg) { |
1160 m_pModule->JBig2_Error( | 1121 m_pModule->JBig2_Error( |
1161 "text region segment : SBHUFFRDY can't find user supplied table"); | 1122 "text region segment : SBHUFFRDY can't find user supplied table"); |
1162 nRet = JBIG2_ERROR_FATAL; | 1123 nRet = JBIG2_ERROR_FATAL; |
1163 goto failed; | 1124 goto failed; |
1164 } | 1125 } |
1165 pTRD->SBHUFFRDY = pSeg->m_Result.ht; | 1126 pTRD->SBHUFFRDY = pSeg->m_Result.ht; |
1166 } | 1127 } |
1167 if (cSBHUFFRSIZE == 0) { | 1128 if (cSBHUFFRSIZE == 0) { |
1168 JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1, | 1129 Table_B1 = new CJBig2_HuffmanTable(HuffmanTable_B1, |
1169 sizeof(HuffmanTable_B1) / | 1130 FX_ArraySize(HuffmanTable_B1), |
1170 sizeof(JBig2TableLine), | 1131 HuffmanTable_HTOOB_B1); |
1171 HuffmanTable_HTOOB_B1)); | |
1172 pTRD->SBHUFFRSIZE = Table_B1; | 1132 pTRD->SBHUFFRSIZE = Table_B1; |
1173 } else { | 1133 } else { |
1174 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1134 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1175 if (!pSeg) { | 1135 if (!pSeg) { |
1176 m_pModule->JBig2_Error( | 1136 m_pModule->JBig2_Error( |
1177 "text region segment : SBHUFFRSIZE can't find user supplied table"); | 1137 "text region segment : SBHUFFRSIZE can't find user supplied table"); |
1178 nRet = JBIG2_ERROR_FATAL; | 1138 nRet = JBIG2_ERROR_FATAL; |
1179 goto failed; | 1139 goto failed; |
1180 } | 1140 } |
1181 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; | 1141 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; |
1182 } | 1142 } |
1183 } | 1143 } |
1184 if (pTRD->SBREFINE == 1) { | 1144 if (pTRD->SBREFINE == 1) { |
1185 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; | 1145 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; |
1186 grContext = | 1146 grContext = |
1187 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1147 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1188 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1148 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1189 } | 1149 } |
1190 if (pTRD->SBHUFF == 0) { | 1150 if (pTRD->SBHUFF == 0) { |
1191 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1151 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1192 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1152 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1193 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); | 1153 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); |
1194 delete pArithDecoder; | 1154 delete pArithDecoder; |
1195 if (pSegment->m_Result.im == NULL) { | 1155 if (pSegment->m_Result.im == NULL) { |
1196 nRet = JBIG2_ERROR_FATAL; | 1156 nRet = JBIG2_ERROR_FATAL; |
1197 goto failed; | 1157 goto failed; |
1198 } | 1158 } |
1199 m_pStream->alignByte(); | 1159 m_pStream->alignByte(); |
1200 m_pStream->offset(2); | 1160 m_pStream->offset(2); |
1201 } else { | 1161 } else { |
1202 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1162 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1203 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream, grContext); | 1163 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream, grContext); |
1204 if (pSegment->m_Result.im == NULL) { | 1164 if (pSegment->m_Result.im == NULL) { |
1205 nRet = JBIG2_ERROR_FATAL; | 1165 nRet = JBIG2_ERROR_FATAL; |
1206 goto failed; | 1166 goto failed; |
1207 } | 1167 } |
1208 m_pStream->alignByte(); | 1168 m_pStream->alignByte(); |
1209 } | 1169 } |
1210 if (pSegment->m_cFlags.s.type != 4) { | 1170 if (pSegment->m_cFlags.s.type != 4) { |
1211 if (!m_bBufSpecified) { | 1171 if (!m_bBufSpecified) { |
1212 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1172 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1213 if ((pPageInfo->m_bIsStriped == 1) && | 1173 if ((pPageInfo->m_bIsStriped == 1) && |
1214 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1174 (ri.y + ri.height > m_pPage->m_nHeight)) { |
1215 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1175 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1216 } | 1176 } |
1217 } | 1177 } |
1218 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1178 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
1219 (JBig2ComposeOp)(ri.flags & 0x03)); | 1179 (JBig2ComposeOp)(ri.flags & 0x03)); |
1220 delete pSegment->m_Result.im; | 1180 delete pSegment->m_Result.im; |
1221 pSegment->m_Result.im = NULL; | 1181 pSegment->m_Result.im = NULL; |
1222 } | 1182 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 } | 1252 } |
1293 pPDD->HDMMR = cFlags & 0x01; | 1253 pPDD->HDMMR = cFlags & 0x01; |
1294 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; | 1254 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; |
1295 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; | 1255 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; |
1296 if (pPDD->HDMMR == 0) { | 1256 if (pPDD->HDMMR == 0) { |
1297 dwTemp = | 1257 dwTemp = |
1298 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; | 1258 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; |
1299 gbContext = | 1259 gbContext = |
1300 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1260 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1301 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1261 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1302 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1262 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1303 pSegment->m_Result.pd = | 1263 pSegment->m_Result.pd = |
1304 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); | 1264 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); |
1305 delete pArithDecoder; | 1265 delete pArithDecoder; |
1306 if (pSegment->m_Result.pd == NULL) { | 1266 if (pSegment->m_Result.pd == NULL) { |
1307 m_pModule->JBig2_Free(gbContext); | 1267 m_pModule->JBig2_Free(gbContext); |
1308 nRet = JBIG2_ERROR_FATAL; | 1268 nRet = JBIG2_ERROR_FATAL; |
1309 goto failed; | 1269 goto failed; |
1310 } | 1270 } |
1311 m_pModule->JBig2_Free(gbContext); | 1271 m_pModule->JBig2_Free(gbContext); |
1312 m_pStream->alignByte(); | 1272 m_pStream->alignByte(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 pHRD->HNUMPATS = pPatternDict->NUMPATS; | 1338 pHRD->HNUMPATS = pPatternDict->NUMPATS; |
1379 pHRD->HPATS = pPatternDict->HDPATS; | 1339 pHRD->HPATS = pPatternDict->HDPATS; |
1380 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; | 1340 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; |
1381 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; | 1341 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; |
1382 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1342 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1383 if (pHRD->HMMR == 0) { | 1343 if (pHRD->HMMR == 0) { |
1384 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; | 1344 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; |
1385 gbContext = | 1345 gbContext = |
1386 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1346 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1387 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1347 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1388 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1348 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1389 pSegment->m_Result.im = | 1349 pSegment->m_Result.im = |
1390 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); | 1350 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); |
1391 delete pArithDecoder; | 1351 delete pArithDecoder; |
1392 if (pSegment->m_Result.im == NULL) { | 1352 if (pSegment->m_Result.im == NULL) { |
1393 m_pModule->JBig2_Free(gbContext); | 1353 m_pModule->JBig2_Free(gbContext); |
1394 nRet = JBIG2_ERROR_FATAL; | 1354 nRet = JBIG2_ERROR_FATAL; |
1395 goto failed; | 1355 goto failed; |
1396 } | 1356 } |
1397 m_pModule->JBig2_Free(gbContext); | 1357 m_pModule->JBig2_Free(gbContext); |
1398 m_pStream->alignByte(); | 1358 m_pStream->alignByte(); |
1399 m_pStream->offset(2); | 1359 m_pStream->offset(2); |
1400 } else { | 1360 } else { |
1401 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); | 1361 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); |
1402 if (pSegment->m_Result.im == NULL) { | 1362 if (pSegment->m_Result.im == NULL) { |
1403 nRet = JBIG2_ERROR_FATAL; | 1363 nRet = JBIG2_ERROR_FATAL; |
1404 goto failed; | 1364 goto failed; |
1405 } | 1365 } |
1406 m_pStream->alignByte(); | 1366 m_pStream->alignByte(); |
1407 } | 1367 } |
1408 if (pSegment->m_cFlags.s.type != 20) { | 1368 if (pSegment->m_cFlags.s.type != 20) { |
1409 if (!m_bBufSpecified) { | 1369 if (!m_bBufSpecified) { |
1410 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1370 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1411 if ((pPageInfo->m_bIsStriped == 1) && | 1371 if ((pPageInfo->m_bIsStriped == 1) && |
1412 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1372 (ri.y + ri.height > m_pPage->m_nHeight)) { |
1413 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1373 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1414 } | 1374 } |
1415 } | 1375 } |
1416 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1376 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
1417 (JBig2ComposeOp)(ri.flags & 0x03)); | 1377 (JBig2ComposeOp)(ri.flags & 0x03)); |
1418 delete pSegment->m_Result.im; | 1378 delete pSegment->m_Result.im; |
1419 pSegment->m_Result.im = NULL; | 1379 pSegment->m_Result.im = NULL; |
1420 } | 1380 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1434 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1475 if (m_pGRD->MMR == 0) { | 1435 if (m_pGRD->MMR == 0) { |
1476 dwTemp = | 1436 dwTemp = |
1477 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; | 1437 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; |
1478 if (m_gbContext == NULL) { | 1438 if (m_gbContext == NULL) { |
1479 m_gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc( | 1439 m_gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc( |
1480 sizeof(JBig2ArithCtx) * dwTemp); | 1440 sizeof(JBig2ArithCtx) * dwTemp); |
1481 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1441 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1482 } | 1442 } |
1483 if (m_pArithDecoder == NULL) { | 1443 if (m_pArithDecoder == NULL) { |
1484 JBIG2_ALLOC(m_pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1444 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1485 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( | 1445 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( |
1486 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); | 1446 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); |
1487 } else { | 1447 } else { |
1488 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); | 1448 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); |
1489 } | 1449 } |
1490 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1450 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
1491 if (pSegment->m_cFlags.s.type != 36) { | 1451 if (pSegment->m_cFlags.s.type != 36) { |
1492 if (!m_bBufSpecified) { | 1452 if (!m_bBufSpecified) { |
1493 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1453 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1494 if ((pPageInfo->m_bIsStriped == 1) && | 1454 if ((pPageInfo->m_bIsStriped == 1) && |
1495 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1455 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
1496 m_pPage->expand(m_ri.y + m_ri.height, | 1456 m_pPage->expand(m_ri.y + m_ri.height, |
1497 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1457 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1498 } | 1458 } |
1499 } | 1459 } |
1500 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1460 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
1501 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1461 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
1502 pSegment->m_Result.im, | 1462 pSegment->m_Result.im, |
1503 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1463 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
(...skipping 21 matching lines...) Expand all Loading... |
1525 m_pGRD->Continue_decode(pPause); | 1485 m_pGRD->Continue_decode(pPause); |
1526 } | 1486 } |
1527 if (pSegment->m_Result.im == NULL) { | 1487 if (pSegment->m_Result.im == NULL) { |
1528 nRet = JBIG2_ERROR_FATAL; | 1488 nRet = JBIG2_ERROR_FATAL; |
1529 goto failed; | 1489 goto failed; |
1530 } | 1490 } |
1531 m_pStream->alignByte(); | 1491 m_pStream->alignByte(); |
1532 } | 1492 } |
1533 if (pSegment->m_cFlags.s.type != 36) { | 1493 if (pSegment->m_cFlags.s.type != 36) { |
1534 if (!m_bBufSpecified) { | 1494 if (!m_bBufSpecified) { |
1535 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1495 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1536 if ((pPageInfo->m_bIsStriped == 1) && | 1496 if ((pPageInfo->m_bIsStriped == 1) && |
1537 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1497 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
1538 m_pPage->expand(m_ri.y + m_ri.height, | 1498 m_pPage->expand(m_ri.y + m_ri.height, |
1539 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1499 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1540 } | 1500 } |
1541 } | 1501 } |
1542 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1502 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
1543 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1503 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
1544 pSegment->m_Result.im, | 1504 pSegment->m_Result.im, |
1545 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1505 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 pGRRD->GRREFERENCE = pSeg->m_Result.im; | 1572 pGRRD->GRREFERENCE = pSeg->m_Result.im; |
1613 } else { | 1573 } else { |
1614 pGRRD->GRREFERENCE = m_pPage; | 1574 pGRRD->GRREFERENCE = m_pPage; |
1615 } | 1575 } |
1616 pGRRD->GRREFERENCEDX = 0; | 1576 pGRRD->GRREFERENCEDX = 0; |
1617 pGRRD->GRREFERENCEDY = 0; | 1577 pGRRD->GRREFERENCEDY = 0; |
1618 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; | 1578 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; |
1619 grContext = | 1579 grContext = |
1620 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1580 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1621 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1581 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1622 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1582 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1623 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1583 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1624 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); | 1584 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); |
1625 delete pArithDecoder; | 1585 delete pArithDecoder; |
1626 if (pSegment->m_Result.im == NULL) { | 1586 if (pSegment->m_Result.im == NULL) { |
1627 m_pModule->JBig2_Free(grContext); | 1587 m_pModule->JBig2_Free(grContext); |
1628 nRet = JBIG2_ERROR_FATAL; | 1588 nRet = JBIG2_ERROR_FATAL; |
1629 goto failed; | 1589 goto failed; |
1630 } | 1590 } |
1631 m_pModule->JBig2_Free(grContext); | 1591 m_pModule->JBig2_Free(grContext); |
1632 m_pStream->alignByte(); | 1592 m_pStream->alignByte(); |
1633 m_pStream->offset(2); | 1593 m_pStream->offset(2); |
1634 if (pSegment->m_cFlags.s.type != 40) { | 1594 if (pSegment->m_cFlags.s.type != 40) { |
1635 if (!m_bBufSpecified) { | 1595 if (!m_bBufSpecified) { |
1636 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1596 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1637 if ((pPageInfo->m_bIsStriped == 1) && | 1597 if ((pPageInfo->m_bIsStriped == 1) && |
1638 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1598 (ri.y + ri.height > m_pPage->m_nHeight)) { |
1639 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1599 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1640 } | 1600 } |
1641 } | 1601 } |
1642 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1602 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
1643 (JBig2ComposeOp)(ri.flags & 0x03)); | 1603 (JBig2ComposeOp)(ri.flags & 0x03)); |
1644 delete pSegment->m_Result.im; | 1604 delete pSegment->m_Result.im; |
1645 pSegment->m_Result.im = NULL; | 1605 pSegment->m_Result.im = NULL; |
1646 } | 1606 } |
1647 delete pGRRD; | 1607 delete pGRRD; |
1648 return JBIG2_SUCCESS; | 1608 return JBIG2_SUCCESS; |
1649 failed: | 1609 failed: |
1650 delete pGRRD; | 1610 delete pGRRD; |
1651 return nRet; | 1611 return nRet; |
1652 } | 1612 } |
1653 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { | 1613 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { |
1654 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; | 1614 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; |
1655 JBIG2_ALLOC(pSegment->m_Result.ht, CJBig2_HuffmanTable(m_pStream)); | 1615 pSegment->m_Result.ht = new CJBig2_HuffmanTable(m_pStream); |
1656 if (!pSegment->m_Result.ht->isOK()) { | 1616 if (!pSegment->m_Result.ht->isOK()) { |
1657 delete pSegment->m_Result.ht; | 1617 delete pSegment->m_Result.ht; |
1658 pSegment->m_Result.ht = NULL; | 1618 pSegment->m_Result.ht = NULL; |
1659 return JBIG2_ERROR_FATAL; | 1619 return JBIG2_ERROR_FATAL; |
1660 } | 1620 } |
1661 m_pStream->alignByte(); | 1621 m_pStream->alignByte(); |
1662 return JBIG2_SUCCESS; | 1622 return JBIG2_SUCCESS; |
1663 } | 1623 } |
1664 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { | 1624 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { |
1665 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || | 1625 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 SBSYMCODES[CURTEMP].code = CURCODE; | 1777 SBSYMCODES[CURTEMP].code = CURCODE; |
1818 CURCODE = CURCODE + 1; | 1778 CURCODE = CURCODE + 1; |
1819 } | 1779 } |
1820 CURTEMP = CURTEMP + 1; | 1780 CURTEMP = CURTEMP + 1; |
1821 } | 1781 } |
1822 CURLEN = CURLEN + 1; | 1782 CURLEN = CURLEN + 1; |
1823 } | 1783 } |
1824 m_pModule->JBig2_Free(LENCOUNT); | 1784 m_pModule->JBig2_Free(LENCOUNT); |
1825 m_pModule->JBig2_Free(FIRSTCODE); | 1785 m_pModule->JBig2_Free(FIRSTCODE); |
1826 } | 1786 } |
OLD | NEW |