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 <list> | 7 #include <list> |
8 #include "JBig2_Context.h" | 8 #include "JBig2_Context.h" |
9 | 9 |
10 // 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 |
11 // 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, |
12 // 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 |
13 // 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 |
14 // list keeps track of the freshness of entries, with freshest ones | 14 // list keeps track of the freshness of entries, with freshest ones |
15 // 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 |
16 // difference for typical JBIG2 documents. | 16 // difference for typical JBIG2 documents. |
17 const int kSymbolDictCacheMaxSize = 2; | 17 const int kSymbolDictCacheMaxSize = 2; |
18 | 18 |
19 CJBig2_Context* CJBig2_Context::CreateContext( | 19 CJBig2_Context* CJBig2_Context::CreateContext( |
20 const uint8_t* pGlobalData, | 20 const uint8_t* pGlobalData, |
21 FX_DWORD dwGlobalLength, | 21 FX_DWORD dwGlobalLength, |
22 const uint8_t* pData, | 22 const uint8_t* pData, |
23 FX_DWORD dwLength, | 23 FX_DWORD dwLength, |
24 int32_t nStreamType, | |
25 std::list<CJBig2_CachePair>* pSymbolDictCache, | 24 std::list<CJBig2_CachePair>* pSymbolDictCache, |
26 IFX_Pause* pPause) { | 25 IFX_Pause* pPause) { |
27 return new CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, | 26 return new CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, |
28 nStreamType, pSymbolDictCache, pPause); | 27 pSymbolDictCache, pPause); |
29 } | 28 } |
| 29 |
30 void CJBig2_Context::DestroyContext(CJBig2_Context* pContext) { | 30 void CJBig2_Context::DestroyContext(CJBig2_Context* pContext) { |
31 delete pContext; | 31 delete pContext; |
32 } | 32 } |
| 33 |
33 CJBig2_Context::CJBig2_Context(const uint8_t* pGlobalData, | 34 CJBig2_Context::CJBig2_Context(const uint8_t* pGlobalData, |
34 FX_DWORD dwGlobalLength, | 35 FX_DWORD dwGlobalLength, |
35 const uint8_t* pData, | 36 const uint8_t* pData, |
36 FX_DWORD dwLength, | 37 FX_DWORD dwLength, |
37 int32_t nStreamType, | |
38 std::list<CJBig2_CachePair>* pSymbolDictCache, | 38 std::list<CJBig2_CachePair>* pSymbolDictCache, |
39 IFX_Pause* pPause) { | 39 IFX_Pause* pPause) |
| 40 : m_bInPage(false), m_bBufSpecified(false) { |
40 if (pGlobalData && (dwGlobalLength > 0)) { | 41 if (pGlobalData && (dwGlobalLength > 0)) { |
41 m_pGlobalContext = | 42 m_pGlobalContext = new CJBig2_Context( |
42 new CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength, | 43 nullptr, 0, pGlobalData, dwGlobalLength, pSymbolDictCache, pPause); |
43 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause); | |
44 } else { | 44 } else { |
45 m_pGlobalContext = NULL; | 45 m_pGlobalContext = nullptr; |
46 } | 46 } |
47 m_pStream = new CJBig2_BitStream(pData, dwLength); | 47 |
48 m_nStreamType = nStreamType; | 48 m_pStream.reset(new CJBig2_BitStream(pData, dwLength)); |
49 m_nState = JBIG2_OUT_OF_PAGE; | |
50 m_pPage = NULL; | |
51 m_bBufSpecified = FALSE; | |
52 m_pPause = pPause; | 49 m_pPause = pPause; |
53 m_nSegmentDecoded = 0; | 50 m_nSegmentDecoded = 0; |
54 m_PauseStep = 10; | 51 m_PauseStep = 10; |
55 m_pArithDecoder = NULL; | 52 m_pArithDecoder = NULL; |
56 m_pGRD = NULL; | |
57 m_gbContext = NULL; | 53 m_gbContext = NULL; |
58 m_dwOffset = 0; | 54 m_dwOffset = 0; |
59 m_ProcessingStatus = FXCODEC_STATUS_FRAME_READY; | 55 m_ProcessingStatus = FXCODEC_STATUS_FRAME_READY; |
60 m_pSymbolDictCache = pSymbolDictCache; | 56 m_pSymbolDictCache = pSymbolDictCache; |
61 } | 57 } |
| 58 |
62 CJBig2_Context::~CJBig2_Context() { | 59 CJBig2_Context::~CJBig2_Context() { |
63 delete m_pArithDecoder; | 60 delete m_pArithDecoder; |
64 m_pArithDecoder = NULL; | 61 m_pArithDecoder = NULL; |
65 delete m_pGRD; | |
66 m_pGRD = NULL; | |
67 FX_Free(m_gbContext); | 62 FX_Free(m_gbContext); |
68 m_gbContext = NULL; | 63 m_gbContext = NULL; |
69 delete m_pGlobalContext; | 64 delete m_pGlobalContext; |
70 m_pGlobalContext = NULL; | 65 m_pGlobalContext = NULL; |
71 if (m_bBufSpecified) { | |
72 delete m_pPage; | |
73 } | |
74 m_pPage = NULL; | |
75 delete m_pStream; | |
76 m_pStream = NULL; | |
77 } | |
78 | |
79 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) { | |
80 if (m_pStream->getByteLeft() < 8) | |
81 return JBIG2_ERROR_TOO_SHORT; | |
82 | |
83 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; | |
84 if (JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) | |
85 return JBIG2_ERROR_FILE_FORMAT; | |
86 | |
87 m_pStream->offset(8); | |
88 | |
89 uint8_t cFlags; | |
90 if (m_pStream->read1Byte(&cFlags) != 0) | |
91 return JBIG2_ERROR_TOO_SHORT; | |
92 | |
93 if (!(cFlags & 0x02)) { | |
94 FX_DWORD dwTemp; | |
95 if (m_pStream->readInteger(&dwTemp) != 0) | |
96 return JBIG2_ERROR_TOO_SHORT; | |
97 | |
98 if (dwTemp > 0) { | |
99 m_PageInfoList.clear(); | |
100 m_PageInfoList.resize(dwTemp); | |
101 } | |
102 } | |
103 | |
104 if (cFlags & 0x01) { | |
105 m_nStreamType = JBIG2_SQUENTIAL_STREAM; | |
106 return decode_SquentialOrgnazation(pPause); | |
107 } | |
108 | |
109 m_nStreamType = JBIG2_RANDOM_STREAM; | |
110 return decode_RandomOrgnazation_FirstPage(pPause); | |
111 } | 66 } |
112 | 67 |
113 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { | 68 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { |
114 int32_t nRet; | 69 int32_t nRet; |
115 if (m_pStream->getByteLeft() <= 0) | 70 if (m_pStream->getByteLeft() <= 0) |
116 return JBIG2_END_OF_FILE; | 71 return JBIG2_END_OF_FILE; |
117 | 72 |
118 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { | 73 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { |
119 if (!m_pSegment) { | 74 if (!m_pSegment) { |
120 m_pSegment.reset(new CJBig2_Segment); | 75 m_pSegment.reset(new CJBig2_Segment); |
(...skipping 12 matching lines...) Expand all Loading... |
133 } | 88 } |
134 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | 89 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { |
135 m_pSegment.reset(); | 90 m_pSegment.reset(); |
136 return JBIG2_SUCCESS; | 91 return JBIG2_SUCCESS; |
137 } | 92 } |
138 if (nRet != JBIG2_SUCCESS) { | 93 if (nRet != JBIG2_SUCCESS) { |
139 m_pSegment.reset(); | 94 m_pSegment.reset(); |
140 return nRet; | 95 return nRet; |
141 } | 96 } |
142 if (m_pSegment->m_dwData_length != 0xffffffff) { | 97 if (m_pSegment->m_dwData_length != 0xffffffff) { |
143 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; | 98 m_dwOffset += m_pSegment->m_dwData_length; |
144 m_pStream->setOffset(m_dwOffset); | 99 m_pStream->setOffset(m_dwOffset); |
145 } else { | 100 } else { |
146 m_pStream->offset(4); | 101 m_pStream->offset(4); |
147 } | 102 } |
148 m_SegmentList.push_back(m_pSegment.release()); | 103 m_SegmentList.push_back(m_pSegment.release()); |
149 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && | 104 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && |
150 pPause->NeedToPauseNow()) { | 105 pPause->NeedToPauseNow()) { |
151 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 106 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
152 m_PauseStep = 2; | 107 m_PauseStep = 2; |
153 return JBIG2_SUCCESS; | 108 return JBIG2_SUCCESS; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 int32_t stride, | 157 int32_t stride, |
203 IFX_Pause* pPause) { | 158 IFX_Pause* pPause) { |
204 int32_t nRet = 0; | 159 int32_t nRet = 0; |
205 if (m_pGlobalContext) { | 160 if (m_pGlobalContext) { |
206 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 161 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
207 if (nRet != JBIG2_SUCCESS) { | 162 if (nRet != JBIG2_SUCCESS) { |
208 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 163 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
209 return nRet; | 164 return nRet; |
210 } | 165 } |
211 } | 166 } |
212 m_bFirstPage = TRUE; | |
213 m_PauseStep = 0; | 167 m_PauseStep = 0; |
214 delete m_pPage; | 168 m_pPage.reset(new CJBig2_Image(width, height, stride, pBuf)); |
215 m_pPage = new CJBig2_Image(width, height, stride, pBuf); | 169 m_bBufSpecified = true; |
216 m_bBufSpecified = TRUE; | 170 if (pPause && pPause->NeedToPauseNow()) { |
217 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | |
218 m_PauseStep = 1; | 171 m_PauseStep = 1; |
219 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 172 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
220 return nRet; | 173 return nRet; |
221 } | 174 } |
222 int ret = Continue(pPause); | 175 return Continue(pPause); |
223 return ret; | |
224 } | 176 } |
225 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { | 177 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { |
226 m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; | 178 m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; |
227 int32_t nRet; | 179 int32_t nRet; |
228 if (m_PauseStep <= 1) { | 180 if (m_PauseStep <= 1) { |
229 switch (m_nStreamType) { | 181 nRet = decode_EmbedOrgnazation(pPause); |
230 case JBIG2_FILE_STREAM: | |
231 nRet = decodeFile(pPause); | |
232 break; | |
233 case JBIG2_SQUENTIAL_STREAM: | |
234 nRet = decode_SquentialOrgnazation(pPause); | |
235 break; | |
236 case JBIG2_RANDOM_STREAM: | |
237 if (m_bFirstPage) { | |
238 nRet = decode_RandomOrgnazation_FirstPage(pPause); | |
239 } else { | |
240 nRet = decode_RandomOrgnazation(pPause); | |
241 } | |
242 break; | |
243 case JBIG2_EMBED_STREAM: | |
244 nRet = decode_EmbedOrgnazation(pPause); | |
245 break; | |
246 default: | |
247 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | |
248 return JBIG2_ERROR_STREAM_TYPE; | |
249 } | |
250 } else if (m_PauseStep == 2) { | 182 } else if (m_PauseStep == 2) { |
251 nRet = decode_SquentialOrgnazation(pPause); | 183 nRet = decode_SquentialOrgnazation(pPause); |
252 } else if (m_PauseStep == 3) { | 184 } else if (m_PauseStep == 3) { |
253 nRet = decode_RandomOrgnazation_FirstPage(pPause); | 185 nRet = decode_RandomOrgnazation_FirstPage(pPause); |
254 } else if (m_PauseStep == 4) { | 186 } else if (m_PauseStep == 4) { |
255 nRet = decode_RandomOrgnazation(pPause); | 187 nRet = decode_RandomOrgnazation(pPause); |
256 } else if (m_PauseStep == 5) { | 188 } else if (m_PauseStep == 5) { |
257 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; | 189 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
258 return JBIG2_SUCCESS; | 190 return JBIG2_SUCCESS; |
259 } | 191 } |
260 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 192 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
261 return nRet; | 193 return nRet; |
262 } | 194 } |
263 m_PauseStep = 5; | 195 m_PauseStep = 5; |
264 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { | 196 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { |
265 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; | 197 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
266 return JBIG2_SUCCESS; | 198 return JBIG2_SUCCESS; |
267 } | 199 } |
268 if (nRet == JBIG2_SUCCESS) { | 200 if (nRet == JBIG2_SUCCESS) { |
269 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; | 201 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
270 } else { | 202 } else { |
271 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 203 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
272 } | 204 } |
273 return nRet; | 205 return nRet; |
274 } | 206 } |
275 int32_t CJBig2_Context::getFirstPage(CJBig2_Image** image, IFX_Pause* pPause) { | 207 |
276 int32_t nRet; | |
277 m_bFirstPage = TRUE; | |
278 m_PauseStep = 0; | |
279 if (m_pGlobalContext) { | |
280 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | |
281 if (nRet != JBIG2_SUCCESS) { | |
282 return nRet; | |
283 } | |
284 } | |
285 m_bBufSpecified = FALSE; | |
286 return Continue(pPause); | |
287 } | |
288 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { | 208 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { |
289 CJBig2_Segment* pSeg; | 209 CJBig2_Segment* pSeg; |
290 if (m_pGlobalContext) { | 210 if (m_pGlobalContext) { |
291 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); | 211 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); |
292 if (pSeg) { | 212 if (pSeg) { |
293 return pSeg; | 213 return pSeg; |
294 } | 214 } |
295 } | 215 } |
296 for (size_t i = 0; i < m_SegmentList.size(); ++i) { | 216 for (size_t i = 0; i < m_SegmentList.size(); ++i) { |
297 pSeg = m_SegmentList.get(i); | 217 pSeg = m_SegmentList.get(i); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 326 } |
407 | 327 |
408 int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, | 328 int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, |
409 IFX_Pause* pPause) { | 329 IFX_Pause* pPause) { |
410 switch (pSegment->m_cFlags.s.type) { | 330 switch (pSegment->m_cFlags.s.type) { |
411 case 0: | 331 case 0: |
412 return parseSymbolDict(pSegment, pPause); | 332 return parseSymbolDict(pSegment, pPause); |
413 case 4: | 333 case 4: |
414 case 6: | 334 case 6: |
415 case 7: | 335 case 7: |
416 if (m_nState == JBIG2_OUT_OF_PAGE) | 336 if (!m_bInPage) |
417 return JBIG2_ERROR_FATAL; | 337 return JBIG2_ERROR_FATAL; |
418 return parseTextRegion(pSegment); | 338 return parseTextRegion(pSegment); |
419 case 16: | 339 case 16: |
420 return parsePatternDict(pSegment, pPause); | 340 return parsePatternDict(pSegment, pPause); |
421 case 20: | 341 case 20: |
422 case 22: | 342 case 22: |
423 case 23: | 343 case 23: |
424 if (m_nState == JBIG2_OUT_OF_PAGE) | 344 if (!m_bInPage) |
425 return JBIG2_ERROR_FATAL; | 345 return JBIG2_ERROR_FATAL; |
426 return parseHalftoneRegion(pSegment, pPause); | 346 return parseHalftoneRegion(pSegment, pPause); |
427 case 36: | 347 case 36: |
428 case 38: | 348 case 38: |
429 case 39: | 349 case 39: |
430 if (m_nState == JBIG2_OUT_OF_PAGE) | 350 if (!m_bInPage) |
431 return JBIG2_ERROR_FATAL; | 351 return JBIG2_ERROR_FATAL; |
432 return parseGenericRegion(pSegment, pPause); | 352 return parseGenericRegion(pSegment, pPause); |
433 case 40: | 353 case 40: |
434 case 42: | 354 case 42: |
435 case 43: | 355 case 43: |
436 if (m_nState == JBIG2_OUT_OF_PAGE) | 356 if (!m_bInPage) |
437 return JBIG2_ERROR_FATAL; | 357 return JBIG2_ERROR_FATAL; |
438 return parseGenericRefinementRegion(pSegment); | 358 return parseGenericRefinementRegion(pSegment); |
439 case 48: { | 359 case 48: { |
440 FX_WORD wTemp; | 360 FX_WORD wTemp; |
441 nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); | 361 nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); |
442 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || | 362 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || |
443 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || | 363 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || |
444 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || | 364 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || |
445 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || | 365 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || |
446 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || | 366 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || |
447 (m_pStream->readShortInteger(&wTemp) != 0)) { | 367 (m_pStream->readShortInteger(&wTemp) != 0)) { |
448 return JBIG2_ERROR_TOO_SHORT; | 368 return JBIG2_ERROR_TOO_SHORT; |
449 } | 369 } |
450 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? TRUE : FALSE; | 370 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? TRUE : FALSE; |
451 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; | 371 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; |
452 bool bMaxHeight = (pPageInfo->m_dwHeight == 0xffffffff); | 372 bool bMaxHeight = (pPageInfo->m_dwHeight == 0xffffffff); |
453 if (bMaxHeight && pPageInfo->m_bIsStriped != TRUE) | 373 if (bMaxHeight && pPageInfo->m_bIsStriped != TRUE) |
454 pPageInfo->m_bIsStriped = TRUE; | 374 pPageInfo->m_bIsStriped = TRUE; |
455 | 375 |
456 if (!m_bBufSpecified) { | 376 if (!m_bBufSpecified) { |
457 delete m_pPage; | |
458 FX_DWORD height = | 377 FX_DWORD height = |
459 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; | 378 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; |
460 m_pPage = new CJBig2_Image(pPageInfo->m_dwWidth, height); | 379 m_pPage.reset(new CJBig2_Image(pPageInfo->m_dwWidth, height)); |
461 } | 380 } |
462 | 381 |
463 if (!m_pPage->m_pData) { | 382 if (!m_pPage->m_pData) { |
464 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 383 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
465 return JBIG2_ERROR_TOO_SHORT; | 384 return JBIG2_ERROR_TOO_SHORT; |
466 } | 385 } |
467 | 386 |
468 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); | 387 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); |
469 m_PageInfoList.push_back(pPageInfo.release()); | 388 m_PageInfoList.push_back(pPageInfo.release()); |
470 m_nState = JBIG2_IN_PAGE; | 389 m_bInPage = true; |
471 } break; | 390 } break; |
472 case 49: | 391 case 49: |
473 m_nState = JBIG2_OUT_OF_PAGE; | 392 m_bInPage = false; |
474 return JBIG2_END_OF_PAGE; | 393 return JBIG2_END_OF_PAGE; |
475 break; | 394 break; |
476 case 50: | 395 case 50: |
477 m_pStream->offset(pSegment->m_dwData_length); | 396 m_pStream->offset(pSegment->m_dwData_length); |
478 break; | 397 break; |
479 case 51: | 398 case 51: |
480 return JBIG2_END_OF_FILE; | 399 return JBIG2_END_OF_FILE; |
481 case 52: | 400 case 52: |
482 m_pStream->offset(pSegment->m_dwData_length); | 401 m_pStream->offset(pSegment->m_dwData_length); |
483 break; | 402 break; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 if (it->first == key) { | 608 if (it->first == key) { |
690 pSegment->m_Result.sd = it->second->DeepCopy(); | 609 pSegment->m_Result.sd = it->second->DeepCopy(); |
691 m_pSymbolDictCache->push_front(*it); | 610 m_pSymbolDictCache->push_front(*it); |
692 m_pSymbolDictCache->erase(it); | 611 m_pSymbolDictCache->erase(it); |
693 cache_hit = true; | 612 cache_hit = true; |
694 break; | 613 break; |
695 } | 614 } |
696 } | 615 } |
697 if (!cache_hit) { | 616 if (!cache_hit) { |
698 if (pSymbolDictDecoder->SDHUFF == 0) { | 617 if (pSymbolDictDecoder->SDHUFF == 0) { |
699 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 618 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
700 pSegment->m_Result.sd = | 619 pSegment->m_Result.sd = |
701 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); | 620 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); |
702 delete pArithDecoder; | 621 delete pArithDecoder; |
703 if (pSegment->m_Result.sd == NULL) { | 622 if (pSegment->m_Result.sd == NULL) { |
704 nRet = JBIG2_ERROR_FATAL; | 623 nRet = JBIG2_ERROR_FATAL; |
705 goto failed; | 624 goto failed; |
706 } | 625 } |
707 m_pStream->alignByte(); | 626 m_pStream->alignByte(); |
708 m_pStream->offset(2); | 627 m_pStream->offset(2); |
709 } else { | 628 } else { |
710 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman( | 629 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman( |
711 m_pStream, gbContext, grContext, pPause); | 630 m_pStream.get(), gbContext, grContext, pPause); |
712 if (pSegment->m_Result.sd == NULL) { | 631 if (pSegment->m_Result.sd == NULL) { |
713 nRet = JBIG2_ERROR_FATAL; | 632 nRet = JBIG2_ERROR_FATAL; |
714 goto failed; | 633 goto failed; |
715 } | 634 } |
716 m_pStream->alignByte(); | 635 m_pStream->alignByte(); |
717 } | 636 } |
718 CJBig2_SymbolDict* value = pSegment->m_Result.sd->DeepCopy(); | 637 CJBig2_SymbolDict* value = pSegment->m_Result.sd->DeepCopy(); |
719 if (value && kSymbolDictCacheMaxSize > 0) { | 638 if (value && kSymbolDictCacheMaxSize > 0) { |
720 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { | 639 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { |
721 delete m_pSymbolDictCache->back().second; | 640 delete m_pSymbolDictCache->back().second; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, | 765 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, |
847 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); | 766 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); |
848 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; | 767 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; |
849 } | 768 } |
850 } | 769 } |
851 pTRD->SBSYMS = SBSYMS; | 770 pTRD->SBSYMS = SBSYMS; |
852 } else { | 771 } else { |
853 pTRD->SBSYMS = NULL; | 772 pTRD->SBSYMS = NULL; |
854 } | 773 } |
855 if (pTRD->SBHUFF == 1) { | 774 if (pTRD->SBHUFF == 1) { |
856 SBSYMCODES = decodeSymbolIDHuffmanTable(m_pStream, pTRD->SBNUMSYMS); | 775 SBSYMCODES = decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS); |
857 if (SBSYMCODES == NULL) { | 776 if (SBSYMCODES == NULL) { |
858 nRet = JBIG2_ERROR_FATAL; | 777 nRet = JBIG2_ERROR_FATAL; |
859 goto failed; | 778 goto failed; |
860 } | 779 } |
861 m_pStream->alignByte(); | 780 m_pStream->alignByte(); |
862 pTRD->SBSYMCODES = SBSYMCODES; | 781 pTRD->SBSYMCODES = SBSYMCODES; |
863 } else { | 782 } else { |
864 dwTemp = 0; | 783 dwTemp = 0; |
865 while ((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { | 784 while ((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { |
866 dwTemp++; | 785 dwTemp++; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 } | 954 } |
1036 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; | 955 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; |
1037 } | 956 } |
1038 } | 957 } |
1039 if (pTRD->SBREFINE == 1) { | 958 if (pTRD->SBREFINE == 1) { |
1040 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; | 959 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; |
1041 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 960 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1042 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 961 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1043 } | 962 } |
1044 if (pTRD->SBHUFF == 0) { | 963 if (pTRD->SBHUFF == 0) { |
1045 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 964 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1046 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 965 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1047 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); | 966 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); |
1048 delete pArithDecoder; | 967 delete pArithDecoder; |
1049 if (pSegment->m_Result.im == NULL) { | 968 if (pSegment->m_Result.im == NULL) { |
1050 nRet = JBIG2_ERROR_FATAL; | 969 nRet = JBIG2_ERROR_FATAL; |
1051 goto failed; | 970 goto failed; |
1052 } | 971 } |
1053 m_pStream->alignByte(); | 972 m_pStream->alignByte(); |
1054 m_pStream->offset(2); | 973 m_pStream->offset(2); |
1055 } else { | 974 } else { |
1056 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 975 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1057 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream, grContext); | 976 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream.get(), grContext); |
1058 if (pSegment->m_Result.im == NULL) { | 977 if (pSegment->m_Result.im == NULL) { |
1059 nRet = JBIG2_ERROR_FATAL; | 978 nRet = JBIG2_ERROR_FATAL; |
1060 goto failed; | 979 goto failed; |
1061 } | 980 } |
1062 m_pStream->alignByte(); | 981 m_pStream->alignByte(); |
1063 } | 982 } |
1064 if (pSegment->m_cFlags.s.type != 4) { | 983 if (pSegment->m_cFlags.s.type != 4) { |
1065 if (!m_bBufSpecified) { | 984 if (!m_bBufSpecified) { |
1066 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 985 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1067 if ((pPageInfo->m_bIsStriped == 1) && | 986 if ((pPageInfo->m_bIsStriped == 1) && |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 goto failed; | 1048 goto failed; |
1130 } | 1049 } |
1131 pPDD->HDMMR = cFlags & 0x01; | 1050 pPDD->HDMMR = cFlags & 0x01; |
1132 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; | 1051 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; |
1133 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; | 1052 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; |
1134 if (pPDD->HDMMR == 0) { | 1053 if (pPDD->HDMMR == 0) { |
1135 dwTemp = | 1054 dwTemp = |
1136 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; | 1055 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; |
1137 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1056 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1138 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1057 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1139 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1058 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1140 pSegment->m_Result.pd = | 1059 pSegment->m_Result.pd = |
1141 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); | 1060 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); |
1142 delete pArithDecoder; | 1061 delete pArithDecoder; |
1143 if (pSegment->m_Result.pd == NULL) { | 1062 if (pSegment->m_Result.pd == NULL) { |
1144 FX_Free(gbContext); | 1063 FX_Free(gbContext); |
1145 nRet = JBIG2_ERROR_FATAL; | 1064 nRet = JBIG2_ERROR_FATAL; |
1146 goto failed; | 1065 goto failed; |
1147 } | 1066 } |
1148 FX_Free(gbContext); | 1067 FX_Free(gbContext); |
1149 m_pStream->alignByte(); | 1068 m_pStream->alignByte(); |
1150 m_pStream->offset(2); | 1069 m_pStream->offset(2); |
1151 } else { | 1070 } else { |
1152 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream, pPause); | 1071 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream.get(), pPause); |
1153 if (pSegment->m_Result.pd == NULL) { | 1072 if (pSegment->m_Result.pd == NULL) { |
1154 nRet = JBIG2_ERROR_FATAL; | 1073 nRet = JBIG2_ERROR_FATAL; |
1155 goto failed; | 1074 goto failed; |
1156 } | 1075 } |
1157 m_pStream->alignByte(); | 1076 m_pStream->alignByte(); |
1158 } | 1077 } |
1159 delete pPDD; | 1078 delete pPDD; |
1160 return JBIG2_SUCCESS; | 1079 return JBIG2_SUCCESS; |
1161 failed: | 1080 failed: |
1162 delete pPDD; | 1081 delete pPDD; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 } | 1126 } |
1208 pHRD->HNUMPATS = pPatternDict->NUMPATS; | 1127 pHRD->HNUMPATS = pPatternDict->NUMPATS; |
1209 pHRD->HPATS = pPatternDict->HDPATS; | 1128 pHRD->HPATS = pPatternDict->HDPATS; |
1210 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; | 1129 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; |
1211 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; | 1130 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; |
1212 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1131 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1213 if (pHRD->HMMR == 0) { | 1132 if (pHRD->HMMR == 0) { |
1214 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; | 1133 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; |
1215 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1134 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1216 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1135 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1217 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1136 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1218 pSegment->m_Result.im = | 1137 pSegment->m_Result.im = |
1219 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); | 1138 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); |
1220 delete pArithDecoder; | 1139 delete pArithDecoder; |
1221 if (pSegment->m_Result.im == NULL) { | 1140 if (pSegment->m_Result.im == NULL) { |
1222 FX_Free(gbContext); | 1141 FX_Free(gbContext); |
1223 nRet = JBIG2_ERROR_FATAL; | 1142 nRet = JBIG2_ERROR_FATAL; |
1224 goto failed; | 1143 goto failed; |
1225 } | 1144 } |
1226 FX_Free(gbContext); | 1145 FX_Free(gbContext); |
1227 m_pStream->alignByte(); | 1146 m_pStream->alignByte(); |
1228 m_pStream->offset(2); | 1147 m_pStream->offset(2); |
1229 } else { | 1148 } else { |
1230 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); | 1149 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get(), pPause); |
1231 if (pSegment->m_Result.im == NULL) { | 1150 if (pSegment->m_Result.im == NULL) { |
1232 nRet = JBIG2_ERROR_FATAL; | 1151 nRet = JBIG2_ERROR_FATAL; |
1233 goto failed; | 1152 goto failed; |
1234 } | 1153 } |
1235 m_pStream->alignByte(); | 1154 m_pStream->alignByte(); |
1236 } | 1155 } |
1237 if (pSegment->m_cFlags.s.type != 20) { | 1156 if (pSegment->m_cFlags.s.type != 20) { |
1238 if (!m_bBufSpecified) { | 1157 if (!m_bBufSpecified) { |
1239 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1158 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1240 if ((pPageInfo->m_bIsStriped == 1) && | 1159 if ((pPageInfo->m_bIsStriped == 1) && |
(...skipping 11 matching lines...) Expand all Loading... |
1252 failed: | 1171 failed: |
1253 delete pHRD; | 1172 delete pHRD; |
1254 return nRet; | 1173 return nRet; |
1255 } | 1174 } |
1256 | 1175 |
1257 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, | 1176 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, |
1258 IFX_Pause* pPause) { | 1177 IFX_Pause* pPause) { |
1259 FX_DWORD dwTemp; | 1178 FX_DWORD dwTemp; |
1260 uint8_t cFlags; | 1179 uint8_t cFlags; |
1261 int32_t i, nRet; | 1180 int32_t i, nRet; |
1262 if (m_pGRD == NULL) { | 1181 if (!m_pGRD) { |
1263 m_pGRD = new CJBig2_GRDProc(); | 1182 m_pGRD.reset(new CJBig2_GRDProc); |
1264 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) || | 1183 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) || |
1265 (m_pStream->read1Byte(&cFlags) != 0)) { | 1184 (m_pStream->read1Byte(&cFlags) != 0)) { |
1266 nRet = JBIG2_ERROR_TOO_SHORT; | 1185 nRet = JBIG2_ERROR_TOO_SHORT; |
1267 goto failed; | 1186 goto failed; |
1268 } | 1187 } |
1269 if (m_ri.height < 0 || m_ri.width < 0) { | 1188 if (m_ri.height < 0 || m_ri.width < 0) { |
1270 nRet = JBIG2_FAILED; | 1189 nRet = JBIG2_FAILED; |
1271 goto failed; | 1190 goto failed; |
1272 } | 1191 } |
1273 m_pGRD->GBW = m_ri.width; | 1192 m_pGRD->GBW = m_ri.width; |
(...skipping 22 matching lines...) Expand all Loading... |
1296 } | 1215 } |
1297 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1216 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1298 if (m_pGRD->MMR == 0) { | 1217 if (m_pGRD->MMR == 0) { |
1299 dwTemp = | 1218 dwTemp = |
1300 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; | 1219 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; |
1301 if (m_gbContext == NULL) { | 1220 if (m_gbContext == NULL) { |
1302 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1221 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1303 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1222 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1304 } | 1223 } |
1305 if (m_pArithDecoder == NULL) { | 1224 if (m_pArithDecoder == NULL) { |
1306 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1225 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1307 m_ProcessingStatus = m_pGRD->Start_decode_Arith( | 1226 m_ProcessingStatus = m_pGRD->Start_decode_Arith( |
1308 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); | 1227 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); |
1309 } else { | 1228 } else { |
1310 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); | 1229 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); |
1311 } | 1230 } |
1312 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1231 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
1313 if (pSegment->m_cFlags.s.type != 36) { | 1232 if (pSegment->m_cFlags.s.type != 36) { |
1314 if (!m_bBufSpecified) { | 1233 if (!m_bBufSpecified) { |
1315 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1234 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1316 if ((pPageInfo->m_bIsStriped == 1) && | 1235 if ((pPageInfo->m_bIsStriped == 1) && |
(...skipping 17 matching lines...) Expand all Loading... |
1334 m_gbContext = NULL; | 1253 m_gbContext = NULL; |
1335 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 1254 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
1336 goto failed; | 1255 goto failed; |
1337 } | 1256 } |
1338 FX_Free(m_gbContext); | 1257 FX_Free(m_gbContext); |
1339 m_gbContext = NULL; | 1258 m_gbContext = NULL; |
1340 m_pStream->alignByte(); | 1259 m_pStream->alignByte(); |
1341 m_pStream->offset(2); | 1260 m_pStream->offset(2); |
1342 } | 1261 } |
1343 } else { | 1262 } else { |
1344 FXCODEC_STATUS status = | 1263 FXCODEC_STATUS status = m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, |
1345 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); | 1264 m_pStream.get(), pPause); |
1346 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1265 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
1347 m_pGRD->Continue_decode(pPause); | 1266 m_pGRD->Continue_decode(pPause); |
1348 } | 1267 } |
1349 if (pSegment->m_Result.im == NULL) { | 1268 if (pSegment->m_Result.im == NULL) { |
1350 nRet = JBIG2_ERROR_FATAL; | 1269 nRet = JBIG2_ERROR_FATAL; |
1351 goto failed; | 1270 goto failed; |
1352 } | 1271 } |
1353 m_pStream->alignByte(); | 1272 m_pStream->alignByte(); |
1354 } | 1273 } |
1355 if (pSegment->m_cFlags.s.type != 36) { | 1274 if (pSegment->m_cFlags.s.type != 36) { |
1356 if (!m_bBufSpecified) { | 1275 if (!m_bBufSpecified) { |
1357 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1276 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1358 if ((pPageInfo->m_bIsStriped == 1) && | 1277 if ((pPageInfo->m_bIsStriped == 1) && |
1359 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1278 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
1360 m_pPage->expand(m_ri.y + m_ri.height, | 1279 m_pPage->expand(m_ri.y + m_ri.height, |
1361 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1280 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1362 } | 1281 } |
1363 } | 1282 } |
1364 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1283 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
1365 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1284 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
1366 pSegment->m_Result.im, | 1285 pSegment->m_Result.im, |
1367 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1286 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
1368 delete pSegment->m_Result.im; | 1287 delete pSegment->m_Result.im; |
1369 pSegment->m_Result.im = NULL; | 1288 pSegment->m_Result.im = NULL; |
1370 } | 1289 } |
1371 delete m_pGRD; | 1290 m_pGRD.reset(); |
1372 m_pGRD = NULL; | |
1373 return JBIG2_SUCCESS; | 1291 return JBIG2_SUCCESS; |
1374 failed: | 1292 failed: |
1375 delete m_pGRD; | 1293 m_pGRD.reset(); |
1376 m_pGRD = NULL; | |
1377 return nRet; | 1294 return nRet; |
1378 } | 1295 } |
1379 | 1296 |
1380 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { | 1297 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { |
1381 FX_DWORD dwTemp; | 1298 FX_DWORD dwTemp; |
1382 JBig2RegionInfo ri; | 1299 JBig2RegionInfo ri; |
1383 CJBig2_Segment* pSeg; | 1300 CJBig2_Segment* pSeg; |
1384 int32_t i, nRet; | 1301 int32_t i, nRet; |
1385 uint8_t cFlags; | 1302 uint8_t cFlags; |
1386 JBig2ArithCtx* grContext; | 1303 JBig2ArithCtx* grContext; |
(...skipping 28 matching lines...) Expand all Loading... |
1415 (pSeg->m_cFlags.s.type == 36) || (pSeg->m_cFlags.s.type == 40)) { | 1332 (pSeg->m_cFlags.s.type == 36) || (pSeg->m_cFlags.s.type == 40)) { |
1416 break; | 1333 break; |
1417 } | 1334 } |
1418 } | 1335 } |
1419 if (i >= pSegment->m_nReferred_to_segment_count) { | 1336 if (i >= pSegment->m_nReferred_to_segment_count) { |
1420 nRet = JBIG2_ERROR_FATAL; | 1337 nRet = JBIG2_ERROR_FATAL; |
1421 goto failed; | 1338 goto failed; |
1422 } | 1339 } |
1423 pGRRD->GRREFERENCE = pSeg->m_Result.im; | 1340 pGRRD->GRREFERENCE = pSeg->m_Result.im; |
1424 } else { | 1341 } else { |
1425 pGRRD->GRREFERENCE = m_pPage; | 1342 pGRRD->GRREFERENCE = m_pPage.get(); |
1426 } | 1343 } |
1427 pGRRD->GRREFERENCEDX = 0; | 1344 pGRRD->GRREFERENCEDX = 0; |
1428 pGRRD->GRREFERENCEDY = 0; | 1345 pGRRD->GRREFERENCEDY = 0; |
1429 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; | 1346 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; |
1430 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1347 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
1431 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1348 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1432 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1349 pArithDecoder = new CJBig2_ArithDecoder(m_pStream.get()); |
1433 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1350 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1434 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); | 1351 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); |
1435 delete pArithDecoder; | 1352 delete pArithDecoder; |
1436 if (pSegment->m_Result.im == NULL) { | 1353 if (pSegment->m_Result.im == NULL) { |
1437 FX_Free(grContext); | 1354 FX_Free(grContext); |
1438 nRet = JBIG2_ERROR_FATAL; | 1355 nRet = JBIG2_ERROR_FATAL; |
1439 goto failed; | 1356 goto failed; |
1440 } | 1357 } |
1441 FX_Free(grContext); | 1358 FX_Free(grContext); |
1442 m_pStream->alignByte(); | 1359 m_pStream->alignByte(); |
(...skipping 12 matching lines...) Expand all Loading... |
1455 pSegment->m_Result.im = NULL; | 1372 pSegment->m_Result.im = NULL; |
1456 } | 1373 } |
1457 delete pGRRD; | 1374 delete pGRRD; |
1458 return JBIG2_SUCCESS; | 1375 return JBIG2_SUCCESS; |
1459 failed: | 1376 failed: |
1460 delete pGRRD; | 1377 delete pGRRD; |
1461 return nRet; | 1378 return nRet; |
1462 } | 1379 } |
1463 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { | 1380 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { |
1464 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; | 1381 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; |
1465 pSegment->m_Result.ht = new CJBig2_HuffmanTable(m_pStream); | 1382 pSegment->m_Result.ht = new CJBig2_HuffmanTable(m_pStream.get()); |
1466 if (!pSegment->m_Result.ht->isOK()) { | 1383 if (!pSegment->m_Result.ht->isOK()) { |
1467 delete pSegment->m_Result.ht; | 1384 delete pSegment->m_Result.ht; |
1468 pSegment->m_Result.ht = NULL; | 1385 pSegment->m_Result.ht = NULL; |
1469 return JBIG2_ERROR_FATAL; | 1386 return JBIG2_ERROR_FATAL; |
1470 } | 1387 } |
1471 m_pStream->alignByte(); | 1388 m_pStream->alignByte(); |
1472 return JBIG2_SUCCESS; | 1389 return JBIG2_SUCCESS; |
1473 } | 1390 } |
1474 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { | 1391 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { |
1475 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || | 1392 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 SBSYMCODES[CURTEMP].code = CURCODE; | 1543 SBSYMCODES[CURTEMP].code = CURCODE; |
1627 CURCODE = CURCODE + 1; | 1544 CURCODE = CURCODE + 1; |
1628 } | 1545 } |
1629 CURTEMP = CURTEMP + 1; | 1546 CURTEMP = CURTEMP + 1; |
1630 } | 1547 } |
1631 CURLEN = CURLEN + 1; | 1548 CURLEN = CURLEN + 1; |
1632 } | 1549 } |
1633 FX_Free(LENCOUNT); | 1550 FX_Free(LENCOUNT); |
1634 FX_Free(FIRSTCODE); | 1551 FX_Free(FIRSTCODE); |
1635 } | 1552 } |
OLD | NEW |