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 "JBig2_Context.h" | 7 #include "JBig2_Context.h" |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 // list keeps track of the freshness of entries, with freshest ones | 22 // list keeps track of the freshness of entries, with freshest ones |
23 // at the front. Even a tiny cache size like 2 makes a dramatic | 23 // at the front. Even a tiny cache size like 2 makes a dramatic |
24 // difference for typical JBIG2 documents. | 24 // difference for typical JBIG2 documents. |
25 static const int kSymbolDictCacheMaxSize = 2; | 25 static const int kSymbolDictCacheMaxSize = 2; |
26 | 26 |
27 CJBig2_Context* CJBig2_Context::CreateContext( | 27 CJBig2_Context* CJBig2_Context::CreateContext( |
28 const uint8_t* pGlobalData, | 28 const uint8_t* pGlobalData, |
29 FX_DWORD dwGlobalLength, | 29 FX_DWORD dwGlobalLength, |
30 const uint8_t* pData, | 30 const uint8_t* pData, |
31 FX_DWORD dwLength, | 31 FX_DWORD dwLength, |
32 int32_t nStreamType, | |
33 std::list<CJBig2_CachePair>* pSymbolDictCache, | 32 std::list<CJBig2_CachePair>* pSymbolDictCache, |
34 IFX_Pause* pPause) { | 33 IFX_Pause* pPause) { |
35 return new CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, | 34 return new CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, |
36 nStreamType, pSymbolDictCache, pPause); | 35 pSymbolDictCache, pPause); |
37 } | 36 } |
| 37 |
38 void CJBig2_Context::DestroyContext(CJBig2_Context* pContext) { | 38 void CJBig2_Context::DestroyContext(CJBig2_Context* pContext) { |
39 delete pContext; | 39 delete pContext; |
40 } | 40 } |
| 41 |
41 CJBig2_Context::CJBig2_Context(const uint8_t* pGlobalData, | 42 CJBig2_Context::CJBig2_Context(const uint8_t* pGlobalData, |
42 FX_DWORD dwGlobalLength, | 43 FX_DWORD dwGlobalLength, |
43 const uint8_t* pData, | 44 const uint8_t* pData, |
44 FX_DWORD dwLength, | 45 FX_DWORD dwLength, |
45 int32_t nStreamType, | |
46 std::list<CJBig2_CachePair>* pSymbolDictCache, | 46 std::list<CJBig2_CachePair>* pSymbolDictCache, |
47 IFX_Pause* pPause) { | 47 IFX_Pause* pPause) |
| 48 : m_nSegmentDecoded(0), |
| 49 m_bInPage(false), |
| 50 m_bBufSpecified(false), |
| 51 m_PauseStep(10), |
| 52 m_pPause(pPause), |
| 53 m_ProcessingStatus(FXCODEC_STATUS_FRAME_READY), |
| 54 m_pArithDecoder(NULL), |
| 55 m_gbContext(NULL), |
| 56 m_dwOffset(0), |
| 57 m_pSymbolDictCache(pSymbolDictCache) { |
48 if (pGlobalData && (dwGlobalLength > 0)) { | 58 if (pGlobalData && (dwGlobalLength > 0)) { |
49 m_pGlobalContext = | 59 m_pGlobalContext = new CJBig2_Context( |
50 new CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength, | 60 nullptr, 0, pGlobalData, dwGlobalLength, pSymbolDictCache, pPause); |
51 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause); | |
52 } else { | 61 } else { |
53 m_pGlobalContext = NULL; | 62 m_pGlobalContext = nullptr; |
54 } | 63 } |
55 m_pStream = new CJBig2_BitStream(pData, dwLength); | 64 |
56 m_nStreamType = nStreamType; | 65 m_pStream.reset(new CJBig2_BitStream(pData, dwLength)); |
57 m_nState = JBIG2_OUT_OF_PAGE; | |
58 m_pPage = NULL; | |
59 m_bBufSpecified = FALSE; | |
60 m_pPause = pPause; | |
61 m_nSegmentDecoded = 0; | |
62 m_PauseStep = 10; | |
63 m_pArithDecoder = NULL; | |
64 m_pGRD = NULL; | |
65 m_gbContext = NULL; | |
66 m_dwOffset = 0; | |
67 m_ProcessingStatus = FXCODEC_STATUS_FRAME_READY; | |
68 m_pSymbolDictCache = pSymbolDictCache; | |
69 } | 66 } |
| 67 |
70 CJBig2_Context::~CJBig2_Context() { | 68 CJBig2_Context::~CJBig2_Context() { |
71 delete m_pArithDecoder; | 69 delete m_pArithDecoder; |
72 m_pArithDecoder = NULL; | 70 m_pArithDecoder = NULL; |
73 delete m_pGRD; | |
74 m_pGRD = NULL; | |
75 FX_Free(m_gbContext); | 71 FX_Free(m_gbContext); |
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 if (m_bBufSpecified) { | |
80 delete m_pPage; | |
81 } | |
82 m_pPage = NULL; | |
83 delete m_pStream; | |
84 m_pStream = NULL; | |
85 } | |
86 | |
87 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) { | |
88 if (m_pStream->getByteLeft() < 8) | |
89 return JBIG2_ERROR_TOO_SHORT; | |
90 | |
91 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; | |
92 if (JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) | |
93 return JBIG2_ERROR_FILE_FORMAT; | |
94 | |
95 m_pStream->offset(8); | |
96 | |
97 uint8_t cFlags; | |
98 if (m_pStream->read1Byte(&cFlags) != 0) | |
99 return JBIG2_ERROR_TOO_SHORT; | |
100 | |
101 if (!(cFlags & 0x02)) { | |
102 FX_DWORD dwTemp; | |
103 if (m_pStream->readInteger(&dwTemp) != 0) | |
104 return JBIG2_ERROR_TOO_SHORT; | |
105 | |
106 if (dwTemp > 0) { | |
107 m_PageInfoList.clear(); | |
108 m_PageInfoList.resize(dwTemp); | |
109 } | |
110 } | |
111 | |
112 if (cFlags & 0x01) { | |
113 m_nStreamType = JBIG2_SQUENTIAL_STREAM; | |
114 return decode_SquentialOrgnazation(pPause); | |
115 } | |
116 | |
117 m_nStreamType = JBIG2_RANDOM_STREAM; | |
118 return decode_RandomOrgnazation_FirstPage(pPause); | |
119 } | 75 } |
120 | 76 |
121 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { | 77 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { |
122 int32_t nRet; | 78 int32_t nRet; |
123 if (m_pStream->getByteLeft() <= 0) | 79 if (m_pStream->getByteLeft() <= 0) |
124 return JBIG2_END_OF_FILE; | 80 return JBIG2_END_OF_FILE; |
125 | 81 |
126 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { | 82 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { |
127 if (!m_pSegment) { | 83 if (!m_pSegment) { |
128 m_pSegment.reset(new CJBig2_Segment); | 84 m_pSegment.reset(new CJBig2_Segment); |
(...skipping 12 matching lines...) Expand all Loading... |
141 } | 97 } |
142 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | 98 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { |
143 m_pSegment.reset(); | 99 m_pSegment.reset(); |
144 return JBIG2_SUCCESS; | 100 return JBIG2_SUCCESS; |
145 } | 101 } |
146 if (nRet != JBIG2_SUCCESS) { | 102 if (nRet != JBIG2_SUCCESS) { |
147 m_pSegment.reset(); | 103 m_pSegment.reset(); |
148 return nRet; | 104 return nRet; |
149 } | 105 } |
150 if (m_pSegment->m_dwData_length != 0xffffffff) { | 106 if (m_pSegment->m_dwData_length != 0xffffffff) { |
151 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; | 107 m_dwOffset += m_pSegment->m_dwData_length; |
152 m_pStream->setOffset(m_dwOffset); | 108 m_pStream->setOffset(m_dwOffset); |
153 } else { | 109 } else { |
154 m_pStream->offset(4); | 110 m_pStream->offset(4); |
155 } | 111 } |
156 m_SegmentList.push_back(m_pSegment.release()); | 112 m_SegmentList.push_back(m_pSegment.release()); |
157 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && | 113 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && |
158 pPause->NeedToPauseNow()) { | 114 pPause->NeedToPauseNow()) { |
159 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 115 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
160 m_PauseStep = 2; | 116 m_PauseStep = 2; |
161 return JBIG2_SUCCESS; | 117 return JBIG2_SUCCESS; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 int32_t stride, | 166 int32_t stride, |
211 IFX_Pause* pPause) { | 167 IFX_Pause* pPause) { |
212 int32_t nRet = 0; | 168 int32_t nRet = 0; |
213 if (m_pGlobalContext) { | 169 if (m_pGlobalContext) { |
214 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 170 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
215 if (nRet != JBIG2_SUCCESS) { | 171 if (nRet != JBIG2_SUCCESS) { |
216 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 172 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
217 return nRet; | 173 return nRet; |
218 } | 174 } |
219 } | 175 } |
220 m_bFirstPage = TRUE; | |
221 m_PauseStep = 0; | 176 m_PauseStep = 0; |
222 delete m_pPage; | 177 m_pPage.reset(new CJBig2_Image(width, height, stride, pBuf)); |
223 m_pPage = new CJBig2_Image(width, height, stride, pBuf); | 178 m_bBufSpecified = true; |
224 m_bBufSpecified = TRUE; | 179 if (pPause && pPause->NeedToPauseNow()) { |
225 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | |
226 m_PauseStep = 1; | 180 m_PauseStep = 1; |
227 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 181 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
228 return nRet; | 182 return nRet; |
229 } | 183 } |
230 int ret = Continue(pPause); | 184 return Continue(pPause); |
231 return ret; | |
232 } | 185 } |
233 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { | 186 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { |
234 m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; | 187 m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; |
235 int32_t nRet; | 188 int32_t nRet; |
236 if (m_PauseStep <= 1) { | 189 if (m_PauseStep <= 1) { |
237 switch (m_nStreamType) { | 190 nRet = decode_EmbedOrgnazation(pPause); |
238 case JBIG2_FILE_STREAM: | |
239 nRet = decodeFile(pPause); | |
240 break; | |
241 case JBIG2_SQUENTIAL_STREAM: | |
242 nRet = decode_SquentialOrgnazation(pPause); | |
243 break; | |
244 case JBIG2_RANDOM_STREAM: | |
245 if (m_bFirstPage) { | |
246 nRet = decode_RandomOrgnazation_FirstPage(pPause); | |
247 } else { | |
248 nRet = decode_RandomOrgnazation(pPause); | |
249 } | |
250 break; | |
251 case JBIG2_EMBED_STREAM: | |
252 nRet = decode_EmbedOrgnazation(pPause); | |
253 break; | |
254 default: | |
255 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | |
256 return JBIG2_ERROR_STREAM_TYPE; | |
257 } | |
258 } else if (m_PauseStep == 2) { | 191 } else if (m_PauseStep == 2) { |
259 nRet = decode_SquentialOrgnazation(pPause); | 192 nRet = decode_SquentialOrgnazation(pPause); |
260 } else if (m_PauseStep == 3) { | 193 } else if (m_PauseStep == 3) { |
261 nRet = decode_RandomOrgnazation_FirstPage(pPause); | 194 nRet = decode_RandomOrgnazation_FirstPage(pPause); |
262 } else if (m_PauseStep == 4) { | 195 } else if (m_PauseStep == 4) { |
263 nRet = decode_RandomOrgnazation(pPause); | 196 nRet = decode_RandomOrgnazation(pPause); |
264 } else if (m_PauseStep == 5) { | 197 } else if (m_PauseStep == 5) { |
265 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; | 198 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
266 return JBIG2_SUCCESS; | 199 return JBIG2_SUCCESS; |
267 } | 200 } |
268 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 201 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
269 return nRet; | 202 return nRet; |
270 } | 203 } |
271 m_PauseStep = 5; | 204 m_PauseStep = 5; |
272 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { | 205 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { |
273 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; | 206 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
274 return JBIG2_SUCCESS; | 207 return JBIG2_SUCCESS; |
275 } | 208 } |
276 if (nRet == JBIG2_SUCCESS) { | 209 if (nRet == JBIG2_SUCCESS) { |
277 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; | 210 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
278 } else { | 211 } else { |
279 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 212 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
280 } | 213 } |
281 return nRet; | 214 return nRet; |
282 } | 215 } |
283 int32_t CJBig2_Context::getFirstPage(CJBig2_Image** image, IFX_Pause* pPause) { | 216 |
284 int32_t nRet; | |
285 m_bFirstPage = TRUE; | |
286 m_PauseStep = 0; | |
287 if (m_pGlobalContext) { | |
288 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | |
289 if (nRet != JBIG2_SUCCESS) { | |
290 return nRet; | |
291 } | |
292 } | |
293 m_bBufSpecified = FALSE; | |
294 return Continue(pPause); | |
295 } | |
296 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { | 217 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { |
297 CJBig2_Segment* pSeg; | 218 CJBig2_Segment* pSeg; |
298 if (m_pGlobalContext) { | 219 if (m_pGlobalContext) { |
299 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); | 220 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); |
300 if (pSeg) { | 221 if (pSeg) { |
301 return pSeg; | 222 return pSeg; |
302 } | 223 } |
303 } | 224 } |
304 for (size_t i = 0; i < m_SegmentList.size(); ++i) { | 225 for (size_t i = 0; i < m_SegmentList.size(); ++i) { |
305 pSeg = m_SegmentList.get(i); | 226 pSeg = m_SegmentList.get(i); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 335 } |
415 | 336 |
416 int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, | 337 int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, |
417 IFX_Pause* pPause) { | 338 IFX_Pause* pPause) { |
418 switch (pSegment->m_cFlags.s.type) { | 339 switch (pSegment->m_cFlags.s.type) { |
419 case 0: | 340 case 0: |
420 return parseSymbolDict(pSegment, pPause); | 341 return parseSymbolDict(pSegment, pPause); |
421 case 4: | 342 case 4: |
422 case 6: | 343 case 6: |
423 case 7: | 344 case 7: |
424 if (m_nState == JBIG2_OUT_OF_PAGE) | 345 if (!m_bInPage) |
425 return JBIG2_ERROR_FATAL; | 346 return JBIG2_ERROR_FATAL; |
426 return parseTextRegion(pSegment); | 347 return parseTextRegion(pSegment); |
427 case 16: | 348 case 16: |
428 return parsePatternDict(pSegment, pPause); | 349 return parsePatternDict(pSegment, pPause); |
429 case 20: | 350 case 20: |
430 case 22: | 351 case 22: |
431 case 23: | 352 case 23: |
432 if (m_nState == JBIG2_OUT_OF_PAGE) | 353 if (!m_bInPage) |
433 return JBIG2_ERROR_FATAL; | 354 return JBIG2_ERROR_FATAL; |
434 return parseHalftoneRegion(pSegment, pPause); | 355 return parseHalftoneRegion(pSegment, pPause); |
435 case 36: | 356 case 36: |
436 case 38: | 357 case 38: |
437 case 39: | 358 case 39: |
438 if (m_nState == JBIG2_OUT_OF_PAGE) | 359 if (!m_bInPage) |
439 return JBIG2_ERROR_FATAL; | 360 return JBIG2_ERROR_FATAL; |
440 return parseGenericRegion(pSegment, pPause); | 361 return parseGenericRegion(pSegment, pPause); |
441 case 40: | 362 case 40: |
442 case 42: | 363 case 42: |
443 case 43: | 364 case 43: |
444 if (m_nState == JBIG2_OUT_OF_PAGE) | 365 if (!m_bInPage) |
445 return JBIG2_ERROR_FATAL; | 366 return JBIG2_ERROR_FATAL; |
446 return parseGenericRefinementRegion(pSegment); | 367 return parseGenericRefinementRegion(pSegment); |
447 case 48: { | 368 case 48: { |
448 FX_WORD wTemp; | 369 FX_WORD wTemp; |
449 nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); | 370 nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); |
450 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || | 371 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || |
451 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || | 372 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || |
452 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || | 373 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || |
453 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || | 374 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || |
454 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || | 375 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || |
455 (m_pStream->readShortInteger(&wTemp) != 0)) { | 376 (m_pStream->readShortInteger(&wTemp) != 0)) { |
456 return JBIG2_ERROR_TOO_SHORT; | 377 return JBIG2_ERROR_TOO_SHORT; |
457 } | 378 } |
458 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? TRUE : FALSE; | 379 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? TRUE : FALSE; |
459 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; | 380 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; |
460 bool bMaxHeight = (pPageInfo->m_dwHeight == 0xffffffff); | 381 bool bMaxHeight = (pPageInfo->m_dwHeight == 0xffffffff); |
461 if (bMaxHeight && pPageInfo->m_bIsStriped != TRUE) | 382 if (bMaxHeight && pPageInfo->m_bIsStriped != TRUE) |
462 pPageInfo->m_bIsStriped = TRUE; | 383 pPageInfo->m_bIsStriped = TRUE; |
463 | 384 |
464 if (!m_bBufSpecified) { | 385 if (!m_bBufSpecified) { |
465 delete m_pPage; | |
466 FX_DWORD height = | 386 FX_DWORD height = |
467 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; | 387 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; |
468 m_pPage = new CJBig2_Image(pPageInfo->m_dwWidth, height); | 388 m_pPage.reset(new CJBig2_Image(pPageInfo->m_dwWidth, height)); |
469 } | 389 } |
470 | 390 |
471 if (!m_pPage->m_pData) { | 391 if (!m_pPage->m_pData) { |
472 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 392 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
473 return JBIG2_ERROR_TOO_SHORT; | 393 return JBIG2_ERROR_TOO_SHORT; |
474 } | 394 } |
475 | 395 |
476 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); | 396 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); |
477 m_PageInfoList.push_back(pPageInfo.release()); | 397 m_PageInfoList.push_back(pPageInfo.release()); |
478 m_nState = JBIG2_IN_PAGE; | 398 m_bInPage = true; |
479 } break; | 399 } break; |
480 case 49: | 400 case 49: |
481 m_nState = JBIG2_OUT_OF_PAGE; | 401 m_bInPage = false; |
482 return JBIG2_END_OF_PAGE; | 402 return JBIG2_END_OF_PAGE; |
483 break; | 403 break; |
484 case 50: | 404 case 50: |
485 m_pStream->offset(pSegment->m_dwData_length); | 405 m_pStream->offset(pSegment->m_dwData_length); |
486 break; | 406 break; |
487 case 51: | 407 case 51: |
488 return JBIG2_END_OF_FILE; | 408 return JBIG2_END_OF_FILE; |
489 case 52: | 409 case 52: |
490 m_pStream->offset(pSegment->m_dwData_length); | 410 m_pStream->offset(pSegment->m_dwData_length); |
491 break; | 411 break; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 if (it->first == key) { | 622 if (it->first == key) { |
703 pSegment->m_Result.sd = it->second->DeepCopy(); | 623 pSegment->m_Result.sd = it->second->DeepCopy(); |
704 m_pSymbolDictCache->push_front(*it); | 624 m_pSymbolDictCache->push_front(*it); |
705 m_pSymbolDictCache->erase(it); | 625 m_pSymbolDictCache->erase(it); |
706 cache_hit = true; | 626 cache_hit = true; |
707 break; | 627 break; |
708 } | 628 } |
709 } | 629 } |
710 if (!cache_hit) { | 630 if (!cache_hit) { |
711 if (pSymbolDictDecoder->SDHUFF == 0) { | 631 if (pSymbolDictDecoder->SDHUFF == 0) { |
712 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 632 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
713 pSegment->m_Result.sd = | 633 pSegment->m_Result.sd = |
714 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); | 634 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); |
715 delete pArithDecoder; | 635 delete pArithDecoder; |
716 if (pSegment->m_Result.sd == NULL) { | 636 if (pSegment->m_Result.sd == NULL) { |
717 nRet = JBIG2_ERROR_FATAL; | 637 nRet = JBIG2_ERROR_FATAL; |
718 goto failed; | 638 goto failed; |
719 } | 639 } |
720 m_pStream->alignByte(); | 640 m_pStream->alignByte(); |
721 m_pStream->offset(2); | 641 m_pStream->offset(2); |
722 } else { | 642 } else { |
723 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman( | 643 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman( |
724 m_pStream, gbContext, grContext, pPause); | 644 m_pStream.get(), gbContext, grContext, pPause); |
725 if (pSegment->m_Result.sd == NULL) { | 645 if (pSegment->m_Result.sd == NULL) { |
726 nRet = JBIG2_ERROR_FATAL; | 646 nRet = JBIG2_ERROR_FATAL; |
727 goto failed; | 647 goto failed; |
728 } | 648 } |
729 m_pStream->alignByte(); | 649 m_pStream->alignByte(); |
730 } | 650 } |
731 CJBig2_SymbolDict* value = pSegment->m_Result.sd->DeepCopy(); | 651 CJBig2_SymbolDict* value = pSegment->m_Result.sd->DeepCopy(); |
732 if (value && kSymbolDictCacheMaxSize > 0) { | 652 if (value && kSymbolDictCacheMaxSize > 0) { |
733 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { | 653 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { |
734 delete m_pSymbolDictCache->back().second; | 654 delete m_pSymbolDictCache->back().second; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, | 786 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, |
867 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); | 787 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); |
868 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; | 788 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; |
869 } | 789 } |
870 } | 790 } |
871 pTRD->SBSYMS = SBSYMS; | 791 pTRD->SBSYMS = SBSYMS; |
872 } else { | 792 } else { |
873 pTRD->SBSYMS = NULL; | 793 pTRD->SBSYMS = NULL; |
874 } | 794 } |
875 if (pTRD->SBHUFF == 1) { | 795 if (pTRD->SBHUFF == 1) { |
876 SBSYMCODES = decodeSymbolIDHuffmanTable(m_pStream, pTRD->SBNUMSYMS); | 796 SBSYMCODES = decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS); |
877 if (SBSYMCODES == NULL) { | 797 if (SBSYMCODES == NULL) { |
878 nRet = JBIG2_ERROR_FATAL; | 798 nRet = JBIG2_ERROR_FATAL; |
879 goto failed; | 799 goto failed; |
880 } | 800 } |
881 m_pStream->alignByte(); | 801 m_pStream->alignByte(); |
882 pTRD->SBSYMCODES = SBSYMCODES; | 802 pTRD->SBSYMCODES = SBSYMCODES; |
883 } else { | 803 } else { |
884 dwTemp = 0; | 804 dwTemp = 0; |
885 while ((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { | 805 while ((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { |
886 dwTemp++; | 806 dwTemp++; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 } | 975 } |
1056 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; | 976 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; |
1057 } | 977 } |
1058 } | 978 } |
1059 if (pTRD->SBREFINE == 1) { | 979 if (pTRD->SBREFINE == 1) { |
1060 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; | 980 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; |
1061 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 981 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1062 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 982 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1063 } | 983 } |
1064 if (pTRD->SBHUFF == 0) { | 984 if (pTRD->SBHUFF == 0) { |
1065 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 985 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1066 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 986 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1067 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); | 987 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); |
1068 delete pArithDecoder; | 988 delete pArithDecoder; |
1069 if (pSegment->m_Result.im == NULL) { | 989 if (pSegment->m_Result.im == NULL) { |
1070 nRet = JBIG2_ERROR_FATAL; | 990 nRet = JBIG2_ERROR_FATAL; |
1071 goto failed; | 991 goto failed; |
1072 } | 992 } |
1073 m_pStream->alignByte(); | 993 m_pStream->alignByte(); |
1074 m_pStream->offset(2); | 994 m_pStream->offset(2); |
1075 } else { | 995 } else { |
1076 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 996 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1077 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream, grContext); | 997 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream.get(), grContext); |
1078 if (pSegment->m_Result.im == NULL) { | 998 if (pSegment->m_Result.im == NULL) { |
1079 nRet = JBIG2_ERROR_FATAL; | 999 nRet = JBIG2_ERROR_FATAL; |
1080 goto failed; | 1000 goto failed; |
1081 } | 1001 } |
1082 m_pStream->alignByte(); | 1002 m_pStream->alignByte(); |
1083 } | 1003 } |
1084 if (pSegment->m_cFlags.s.type != 4) { | 1004 if (pSegment->m_cFlags.s.type != 4) { |
1085 if (!m_bBufSpecified) { | 1005 if (!m_bBufSpecified) { |
1086 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1006 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1087 if ((pPageInfo->m_bIsStriped == 1) && | 1007 if ((pPageInfo->m_bIsStriped == 1) && |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 goto failed; | 1069 goto failed; |
1150 } | 1070 } |
1151 pPDD->HDMMR = cFlags & 0x01; | 1071 pPDD->HDMMR = cFlags & 0x01; |
1152 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; | 1072 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; |
1153 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; | 1073 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; |
1154 if (pPDD->HDMMR == 0) { | 1074 if (pPDD->HDMMR == 0) { |
1155 dwTemp = | 1075 dwTemp = |
1156 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; | 1076 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; |
1157 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1077 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1158 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1078 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1159 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1079 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1160 pSegment->m_Result.pd = | 1080 pSegment->m_Result.pd = |
1161 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); | 1081 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); |
1162 delete pArithDecoder; | 1082 delete pArithDecoder; |
1163 if (pSegment->m_Result.pd == NULL) { | 1083 if (pSegment->m_Result.pd == NULL) { |
1164 FX_Free(gbContext); | 1084 FX_Free(gbContext); |
1165 nRet = JBIG2_ERROR_FATAL; | 1085 nRet = JBIG2_ERROR_FATAL; |
1166 goto failed; | 1086 goto failed; |
1167 } | 1087 } |
1168 FX_Free(gbContext); | 1088 FX_Free(gbContext); |
1169 m_pStream->alignByte(); | 1089 m_pStream->alignByte(); |
1170 m_pStream->offset(2); | 1090 m_pStream->offset(2); |
1171 } else { | 1091 } else { |
1172 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream, pPause); | 1092 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream.get(), pPause); |
1173 if (pSegment->m_Result.pd == NULL) { | 1093 if (pSegment->m_Result.pd == NULL) { |
1174 nRet = JBIG2_ERROR_FATAL; | 1094 nRet = JBIG2_ERROR_FATAL; |
1175 goto failed; | 1095 goto failed; |
1176 } | 1096 } |
1177 m_pStream->alignByte(); | 1097 m_pStream->alignByte(); |
1178 } | 1098 } |
1179 delete pPDD; | 1099 delete pPDD; |
1180 return JBIG2_SUCCESS; | 1100 return JBIG2_SUCCESS; |
1181 failed: | 1101 failed: |
1182 delete pPDD; | 1102 delete pPDD; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 } | 1147 } |
1228 pHRD->HNUMPATS = pPatternDict->NUMPATS; | 1148 pHRD->HNUMPATS = pPatternDict->NUMPATS; |
1229 pHRD->HPATS = pPatternDict->HDPATS; | 1149 pHRD->HPATS = pPatternDict->HDPATS; |
1230 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; | 1150 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; |
1231 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; | 1151 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; |
1232 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1152 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1233 if (pHRD->HMMR == 0) { | 1153 if (pHRD->HMMR == 0) { |
1234 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; | 1154 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; |
1235 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1155 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1236 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1156 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1237 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1157 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1238 pSegment->m_Result.im = | 1158 pSegment->m_Result.im = |
1239 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); | 1159 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); |
1240 delete pArithDecoder; | 1160 delete pArithDecoder; |
1241 if (pSegment->m_Result.im == NULL) { | 1161 if (pSegment->m_Result.im == NULL) { |
1242 FX_Free(gbContext); | 1162 FX_Free(gbContext); |
1243 nRet = JBIG2_ERROR_FATAL; | 1163 nRet = JBIG2_ERROR_FATAL; |
1244 goto failed; | 1164 goto failed; |
1245 } | 1165 } |
1246 FX_Free(gbContext); | 1166 FX_Free(gbContext); |
1247 m_pStream->alignByte(); | 1167 m_pStream->alignByte(); |
1248 m_pStream->offset(2); | 1168 m_pStream->offset(2); |
1249 } else { | 1169 } else { |
1250 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); | 1170 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get(), pPause); |
1251 if (pSegment->m_Result.im == NULL) { | 1171 if (pSegment->m_Result.im == NULL) { |
1252 nRet = JBIG2_ERROR_FATAL; | 1172 nRet = JBIG2_ERROR_FATAL; |
1253 goto failed; | 1173 goto failed; |
1254 } | 1174 } |
1255 m_pStream->alignByte(); | 1175 m_pStream->alignByte(); |
1256 } | 1176 } |
1257 if (pSegment->m_cFlags.s.type != 20) { | 1177 if (pSegment->m_cFlags.s.type != 20) { |
1258 if (!m_bBufSpecified) { | 1178 if (!m_bBufSpecified) { |
1259 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1179 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1260 if ((pPageInfo->m_bIsStriped == 1) && | 1180 if ((pPageInfo->m_bIsStriped == 1) && |
(...skipping 11 matching lines...) Expand all Loading... |
1272 failed: | 1192 failed: |
1273 delete pHRD; | 1193 delete pHRD; |
1274 return nRet; | 1194 return nRet; |
1275 } | 1195 } |
1276 | 1196 |
1277 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, | 1197 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, |
1278 IFX_Pause* pPause) { | 1198 IFX_Pause* pPause) { |
1279 FX_DWORD dwTemp; | 1199 FX_DWORD dwTemp; |
1280 uint8_t cFlags; | 1200 uint8_t cFlags; |
1281 int32_t i, nRet; | 1201 int32_t i, nRet; |
1282 if (m_pGRD == NULL) { | 1202 if (!m_pGRD) { |
1283 m_pGRD = new CJBig2_GRDProc(); | 1203 m_pGRD.reset(new CJBig2_GRDProc); |
1284 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) || | 1204 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) || |
1285 (m_pStream->read1Byte(&cFlags) != 0)) { | 1205 (m_pStream->read1Byte(&cFlags) != 0)) { |
1286 nRet = JBIG2_ERROR_TOO_SHORT; | 1206 nRet = JBIG2_ERROR_TOO_SHORT; |
1287 goto failed; | 1207 goto failed; |
1288 } | 1208 } |
1289 if (m_ri.height < 0 || m_ri.width < 0) { | 1209 if (m_ri.height < 0 || m_ri.width < 0) { |
1290 nRet = JBIG2_FAILED; | 1210 nRet = JBIG2_FAILED; |
1291 goto failed; | 1211 goto failed; |
1292 } | 1212 } |
1293 m_pGRD->GBW = m_ri.width; | 1213 m_pGRD->GBW = m_ri.width; |
(...skipping 22 matching lines...) Expand all Loading... |
1316 } | 1236 } |
1317 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1237 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1318 if (m_pGRD->MMR == 0) { | 1238 if (m_pGRD->MMR == 0) { |
1319 dwTemp = | 1239 dwTemp = |
1320 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; | 1240 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; |
1321 if (m_gbContext == NULL) { | 1241 if (m_gbContext == NULL) { |
1322 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1242 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1323 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1243 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1324 } | 1244 } |
1325 if (m_pArithDecoder == NULL) { | 1245 if (m_pArithDecoder == NULL) { |
1326 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1246 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1327 m_ProcessingStatus = m_pGRD->Start_decode_Arith( | 1247 m_ProcessingStatus = m_pGRD->Start_decode_Arith( |
1328 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); | 1248 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); |
1329 } else { | 1249 } else { |
1330 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); | 1250 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); |
1331 } | 1251 } |
1332 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1252 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
1333 if (pSegment->m_cFlags.s.type != 36) { | 1253 if (pSegment->m_cFlags.s.type != 36) { |
1334 if (!m_bBufSpecified) { | 1254 if (!m_bBufSpecified) { |
1335 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1255 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1336 if ((pPageInfo->m_bIsStriped == 1) && | 1256 if ((pPageInfo->m_bIsStriped == 1) && |
(...skipping 17 matching lines...) Expand all Loading... |
1354 m_gbContext = NULL; | 1274 m_gbContext = NULL; |
1355 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 1275 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
1356 goto failed; | 1276 goto failed; |
1357 } | 1277 } |
1358 FX_Free(m_gbContext); | 1278 FX_Free(m_gbContext); |
1359 m_gbContext = NULL; | 1279 m_gbContext = NULL; |
1360 m_pStream->alignByte(); | 1280 m_pStream->alignByte(); |
1361 m_pStream->offset(2); | 1281 m_pStream->offset(2); |
1362 } | 1282 } |
1363 } else { | 1283 } else { |
1364 FXCODEC_STATUS status = | 1284 FXCODEC_STATUS status = m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, |
1365 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); | 1285 m_pStream.get(), pPause); |
1366 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1286 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
1367 m_pGRD->Continue_decode(pPause); | 1287 m_pGRD->Continue_decode(pPause); |
1368 } | 1288 } |
1369 if (pSegment->m_Result.im == NULL) { | 1289 if (pSegment->m_Result.im == NULL) { |
1370 nRet = JBIG2_ERROR_FATAL; | 1290 nRet = JBIG2_ERROR_FATAL; |
1371 goto failed; | 1291 goto failed; |
1372 } | 1292 } |
1373 m_pStream->alignByte(); | 1293 m_pStream->alignByte(); |
1374 } | 1294 } |
1375 if (pSegment->m_cFlags.s.type != 36) { | 1295 if (pSegment->m_cFlags.s.type != 36) { |
1376 if (!m_bBufSpecified) { | 1296 if (!m_bBufSpecified) { |
1377 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1297 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1378 if ((pPageInfo->m_bIsStriped == 1) && | 1298 if ((pPageInfo->m_bIsStriped == 1) && |
1379 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1299 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
1380 m_pPage->expand(m_ri.y + m_ri.height, | 1300 m_pPage->expand(m_ri.y + m_ri.height, |
1381 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1301 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1382 } | 1302 } |
1383 } | 1303 } |
1384 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1304 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
1385 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1305 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
1386 pSegment->m_Result.im, | 1306 pSegment->m_Result.im, |
1387 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1307 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
1388 delete pSegment->m_Result.im; | 1308 delete pSegment->m_Result.im; |
1389 pSegment->m_Result.im = NULL; | 1309 pSegment->m_Result.im = NULL; |
1390 } | 1310 } |
1391 delete m_pGRD; | 1311 m_pGRD.reset(); |
1392 m_pGRD = NULL; | |
1393 return JBIG2_SUCCESS; | 1312 return JBIG2_SUCCESS; |
1394 failed: | 1313 failed: |
1395 delete m_pGRD; | 1314 m_pGRD.reset(); |
1396 m_pGRD = NULL; | |
1397 return nRet; | 1315 return nRet; |
1398 } | 1316 } |
1399 | 1317 |
1400 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { | 1318 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { |
1401 FX_DWORD dwTemp; | 1319 FX_DWORD dwTemp; |
1402 JBig2RegionInfo ri; | 1320 JBig2RegionInfo ri; |
1403 CJBig2_Segment* pSeg; | 1321 CJBig2_Segment* pSeg; |
1404 int32_t i, nRet; | 1322 int32_t i, nRet; |
1405 uint8_t cFlags; | 1323 uint8_t cFlags; |
1406 JBig2ArithCtx* grContext; | 1324 JBig2ArithCtx* grContext; |
(...skipping 28 matching lines...) Expand all Loading... |
1435 (pSeg->m_cFlags.s.type == 36) || (pSeg->m_cFlags.s.type == 40)) { | 1353 (pSeg->m_cFlags.s.type == 36) || (pSeg->m_cFlags.s.type == 40)) { |
1436 break; | 1354 break; |
1437 } | 1355 } |
1438 } | 1356 } |
1439 if (i >= pSegment->m_nReferred_to_segment_count) { | 1357 if (i >= pSegment->m_nReferred_to_segment_count) { |
1440 nRet = JBIG2_ERROR_FATAL; | 1358 nRet = JBIG2_ERROR_FATAL; |
1441 goto failed; | 1359 goto failed; |
1442 } | 1360 } |
1443 pGRRD->GRREFERENCE = pSeg->m_Result.im; | 1361 pGRRD->GRREFERENCE = pSeg->m_Result.im; |
1444 } else { | 1362 } else { |
1445 pGRRD->GRREFERENCE = m_pPage; | 1363 pGRRD->GRREFERENCE = m_pPage.get(); |
1446 } | 1364 } |
1447 pGRRD->GRREFERENCEDX = 0; | 1365 pGRRD->GRREFERENCEDX = 0; |
1448 pGRRD->GRREFERENCEDY = 0; | 1366 pGRRD->GRREFERENCEDY = 0; |
1449 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; | 1367 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; |
1450 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1368 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1451 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1369 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1452 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1370 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1453 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1371 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1454 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); | 1372 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); |
1455 delete pArithDecoder; | 1373 delete pArithDecoder; |
1456 if (pSegment->m_Result.im == NULL) { | 1374 if (pSegment->m_Result.im == NULL) { |
1457 FX_Free(grContext); | 1375 FX_Free(grContext); |
1458 nRet = JBIG2_ERROR_FATAL; | 1376 nRet = JBIG2_ERROR_FATAL; |
1459 goto failed; | 1377 goto failed; |
1460 } | 1378 } |
1461 FX_Free(grContext); | 1379 FX_Free(grContext); |
1462 m_pStream->alignByte(); | 1380 m_pStream->alignByte(); |
(...skipping 12 matching lines...) Expand all Loading... |
1475 pSegment->m_Result.im = NULL; | 1393 pSegment->m_Result.im = NULL; |
1476 } | 1394 } |
1477 delete pGRRD; | 1395 delete pGRRD; |
1478 return JBIG2_SUCCESS; | 1396 return JBIG2_SUCCESS; |
1479 failed: | 1397 failed: |
1480 delete pGRRD; | 1398 delete pGRRD; |
1481 return nRet; | 1399 return nRet; |
1482 } | 1400 } |
1483 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { | 1401 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { |
1484 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; | 1402 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; |
1485 pSegment->m_Result.ht = new CJBig2_HuffmanTable(m_pStream); | 1403 pSegment->m_Result.ht = new CJBig2_HuffmanTable(m_pStream.get()); |
1486 if (!pSegment->m_Result.ht->isOK()) { | 1404 if (!pSegment->m_Result.ht->isOK()) { |
1487 delete pSegment->m_Result.ht; | 1405 delete pSegment->m_Result.ht; |
1488 pSegment->m_Result.ht = NULL; | 1406 pSegment->m_Result.ht = NULL; |
1489 return JBIG2_ERROR_FATAL; | 1407 return JBIG2_ERROR_FATAL; |
1490 } | 1408 } |
1491 m_pStream->alignByte(); | 1409 m_pStream->alignByte(); |
1492 return JBIG2_SUCCESS; | 1410 return JBIG2_SUCCESS; |
1493 } | 1411 } |
1494 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { | 1412 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { |
1495 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || | 1413 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 SBSYMCODES[CURTEMP].code = CURCODE; | 1564 SBSYMCODES[CURTEMP].code = CURCODE; |
1647 CURCODE = CURCODE + 1; | 1565 CURCODE = CURCODE + 1; |
1648 } | 1566 } |
1649 CURTEMP = CURTEMP + 1; | 1567 CURTEMP = CURTEMP + 1; |
1650 } | 1568 } |
1651 CURLEN = CURLEN + 1; | 1569 CURLEN = CURLEN + 1; |
1652 } | 1570 } |
1653 FX_Free(LENCOUNT); | 1571 FX_Free(LENCOUNT); |
1654 FX_Free(FIRSTCODE); | 1572 FX_Free(FIRSTCODE); |
1655 } | 1573 } |
OLD | NEW |