| 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 "core/fxcodec/jbig2/JBig2_Context.h" | 7 #include "core/fxcodec/jbig2/JBig2_Context.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 return JBIG2_SUCCESS; | 223 return JBIG2_SUCCESS; |
| 224 } | 224 } |
| 225 if (nRet == JBIG2_SUCCESS) { | 225 if (nRet == JBIG2_SUCCESS) { |
| 226 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; | 226 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 227 } else { | 227 } else { |
| 228 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 228 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 229 } | 229 } |
| 230 return nRet; | 230 return nRet; |
| 231 } | 231 } |
| 232 | 232 |
| 233 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { | 233 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(uint32_t dwNumber) { |
| 234 if (m_pGlobalContext) { | 234 if (m_pGlobalContext) { |
| 235 CJBig2_Segment* pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); | 235 CJBig2_Segment* pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); |
| 236 if (pSeg) { | 236 if (pSeg) { |
| 237 return pSeg; | 237 return pSeg; |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 for (size_t i = 0; i < m_SegmentList.size(); ++i) { | 240 for (size_t i = 0; i < m_SegmentList.size(); ++i) { |
| 241 CJBig2_Segment* pSeg = m_SegmentList.get(i); | 241 CJBig2_Segment* pSeg = m_SegmentList.get(i); |
| 242 if (pSeg->m_dwNumber == dwNumber) { | 242 if (pSeg->m_dwNumber == dwNumber) { |
| 243 return pSeg; | 243 return pSeg; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 return NULL; | 262 return NULL; |
| 263 } | 263 } |
| 264 int32_t CJBig2_Context::parseSegmentHeader(CJBig2_Segment* pSegment) { | 264 int32_t CJBig2_Context::parseSegmentHeader(CJBig2_Segment* pSegment) { |
| 265 if (m_pStream->readInteger(&pSegment->m_dwNumber) != 0 || | 265 if (m_pStream->readInteger(&pSegment->m_dwNumber) != 0 || |
| 266 m_pStream->read1Byte(&pSegment->m_cFlags.c) != 0) { | 266 m_pStream->read1Byte(&pSegment->m_cFlags.c) != 0) { |
| 267 return JBIG2_ERROR_TOO_SHORT; | 267 return JBIG2_ERROR_TOO_SHORT; |
| 268 } | 268 } |
| 269 | 269 |
| 270 FX_DWORD dwTemp; | 270 uint32_t dwTemp; |
| 271 uint8_t cTemp = m_pStream->getCurByte(); | 271 uint8_t cTemp = m_pStream->getCurByte(); |
| 272 if ((cTemp >> 5) == 7) { | 272 if ((cTemp >> 5) == 7) { |
| 273 if (m_pStream->readInteger( | 273 if (m_pStream->readInteger( |
| 274 (FX_DWORD*)&pSegment->m_nReferred_to_segment_count) != 0) { | 274 (uint32_t*)&pSegment->m_nReferred_to_segment_count) != 0) { |
| 275 return JBIG2_ERROR_TOO_SHORT; | 275 return JBIG2_ERROR_TOO_SHORT; |
| 276 } | 276 } |
| 277 pSegment->m_nReferred_to_segment_count &= 0x1fffffff; | 277 pSegment->m_nReferred_to_segment_count &= 0x1fffffff; |
| 278 if (pSegment->m_nReferred_to_segment_count > | 278 if (pSegment->m_nReferred_to_segment_count > |
| 279 JBIG2_MAX_REFERRED_SEGMENT_COUNT) { | 279 JBIG2_MAX_REFERRED_SEGMENT_COUNT) { |
| 280 return JBIG2_ERROR_LIMIT; | 280 return JBIG2_ERROR_LIMIT; |
| 281 } | 281 } |
| 282 dwTemp = 5 + 4 + (pSegment->m_nReferred_to_segment_count + 1) / 8; | 282 dwTemp = 5 + 4 + (pSegment->m_nReferred_to_segment_count + 1) / 8; |
| 283 } else { | 283 } else { |
| 284 if (m_pStream->read1Byte(&cTemp) != 0) | 284 if (m_pStream->read1Byte(&cTemp) != 0) |
| 285 return JBIG2_ERROR_TOO_SHORT; | 285 return JBIG2_ERROR_TOO_SHORT; |
| 286 | 286 |
| 287 pSegment->m_nReferred_to_segment_count = cTemp >> 5; | 287 pSegment->m_nReferred_to_segment_count = cTemp >> 5; |
| 288 dwTemp = 5 + 1; | 288 dwTemp = 5 + 1; |
| 289 } | 289 } |
| 290 uint8_t cSSize = | 290 uint8_t cSSize = |
| 291 pSegment->m_dwNumber > 65536 ? 4 : pSegment->m_dwNumber > 256 ? 2 : 1; | 291 pSegment->m_dwNumber > 65536 ? 4 : pSegment->m_dwNumber > 256 ? 2 : 1; |
| 292 uint8_t cPSize = pSegment->m_cFlags.s.page_association_size ? 4 : 1; | 292 uint8_t cPSize = pSegment->m_cFlags.s.page_association_size ? 4 : 1; |
| 293 if (pSegment->m_nReferred_to_segment_count) { | 293 if (pSegment->m_nReferred_to_segment_count) { |
| 294 pSegment->m_pReferred_to_segment_numbers = | 294 pSegment->m_pReferred_to_segment_numbers = |
| 295 FX_Alloc(FX_DWORD, pSegment->m_nReferred_to_segment_count); | 295 FX_Alloc(uint32_t, pSegment->m_nReferred_to_segment_count); |
| 296 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { | 296 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { |
| 297 switch (cSSize) { | 297 switch (cSSize) { |
| 298 case 1: | 298 case 1: |
| 299 if (m_pStream->read1Byte(&cTemp) != 0) | 299 if (m_pStream->read1Byte(&cTemp) != 0) |
| 300 return JBIG2_ERROR_TOO_SHORT; | 300 return JBIG2_ERROR_TOO_SHORT; |
| 301 | 301 |
| 302 pSegment->m_pReferred_to_segment_numbers[i] = cTemp; | 302 pSegment->m_pReferred_to_segment_numbers[i] = cTemp; |
| 303 break; | 303 break; |
| 304 case 2: | 304 case 2: |
| 305 uint16_t wTemp; | 305 uint16_t wTemp; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 m_pStream->readShortInteger(&wTemp) != 0) { | 389 m_pStream->readShortInteger(&wTemp) != 0) { |
| 390 return JBIG2_ERROR_TOO_SHORT; | 390 return JBIG2_ERROR_TOO_SHORT; |
| 391 } | 391 } |
| 392 pPageInfo->m_bIsStriped = !!(wTemp & 0x8000); | 392 pPageInfo->m_bIsStriped = !!(wTemp & 0x8000); |
| 393 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; | 393 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; |
| 394 bool bMaxHeight = (pPageInfo->m_dwHeight == 0xffffffff); | 394 bool bMaxHeight = (pPageInfo->m_dwHeight == 0xffffffff); |
| 395 if (bMaxHeight && pPageInfo->m_bIsStriped != TRUE) | 395 if (bMaxHeight && pPageInfo->m_bIsStriped != TRUE) |
| 396 pPageInfo->m_bIsStriped = TRUE; | 396 pPageInfo->m_bIsStriped = TRUE; |
| 397 | 397 |
| 398 if (!m_bBufSpecified) { | 398 if (!m_bBufSpecified) { |
| 399 FX_DWORD height = | 399 uint32_t height = |
| 400 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; | 400 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; |
| 401 m_pPage.reset(new CJBig2_Image(pPageInfo->m_dwWidth, height)); | 401 m_pPage.reset(new CJBig2_Image(pPageInfo->m_dwWidth, height)); |
| 402 } | 402 } |
| 403 | 403 |
| 404 if (!m_pPage->m_pData) { | 404 if (!m_pPage->m_pData) { |
| 405 m_ProcessingStatus = FXCODEC_STATUS_ERROR; | 405 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 406 return JBIG2_ERROR_TOO_SHORT; | 406 return JBIG2_ERROR_TOO_SHORT; |
| 407 } | 407 } |
| 408 | 408 |
| 409 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); | 409 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 std::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc); | 442 std::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc); |
| 443 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; | 443 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; |
| 444 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; | 444 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; |
| 445 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; | 445 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; |
| 446 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; | 446 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; |
| 447 uint8_t cSDHUFFDH = (wFlags >> 2) & 0x0003; | 447 uint8_t cSDHUFFDH = (wFlags >> 2) & 0x0003; |
| 448 uint8_t cSDHUFFDW = (wFlags >> 4) & 0x0003; | 448 uint8_t cSDHUFFDW = (wFlags >> 4) & 0x0003; |
| 449 uint8_t cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001; | 449 uint8_t cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001; |
| 450 uint8_t cSDHUFFAGGINST = (wFlags >> 7) & 0x0001; | 450 uint8_t cSDHUFFAGGINST = (wFlags >> 7) & 0x0001; |
| 451 if (pSymbolDictDecoder->SDHUFF == 0) { | 451 if (pSymbolDictDecoder->SDHUFF == 0) { |
| 452 const FX_DWORD dwTemp = (pSymbolDictDecoder->SDTEMPLATE == 0) ? 8 : 2; | 452 const uint32_t dwTemp = (pSymbolDictDecoder->SDTEMPLATE == 0) ? 8 : 2; |
| 453 for (FX_DWORD i = 0; i < dwTemp; ++i) { | 453 for (uint32_t i = 0; i < dwTemp; ++i) { |
| 454 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDAT[i]) != 0) | 454 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDAT[i]) != 0) |
| 455 return JBIG2_ERROR_TOO_SHORT; | 455 return JBIG2_ERROR_TOO_SHORT; |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 if (pSymbolDictDecoder->SDREFAGG == 1 && | 458 if (pSymbolDictDecoder->SDREFAGG == 1 && |
| 459 pSymbolDictDecoder->SDRTEMPLATE == 0) { | 459 pSymbolDictDecoder->SDRTEMPLATE == 0) { |
| 460 for (int32_t i = 0; i < 4; ++i) { | 460 for (int32_t i = 0; i < 4; ++i) { |
| 461 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDRAT[i]) != 0) | 461 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDRAT[i]) != 0) |
| 462 return JBIG2_ERROR_TOO_SHORT; | 462 return JBIG2_ERROR_TOO_SHORT; |
| 463 } | 463 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 481 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 481 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
| 482 if (pSeg->m_cFlags.s.type == 0) { | 482 if (pSeg->m_cFlags.s.type == 0) { |
| 483 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages(); | 483 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages(); |
| 484 pLRSeg = pSeg; | 484 pLRSeg = pSeg; |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 | 487 |
| 488 std::unique_ptr<CJBig2_Image*, FxFreeDeleter> SDINSYMS; | 488 std::unique_ptr<CJBig2_Image*, FxFreeDeleter> SDINSYMS; |
| 489 if (pSymbolDictDecoder->SDNUMINSYMS != 0) { | 489 if (pSymbolDictDecoder->SDNUMINSYMS != 0) { |
| 490 SDINSYMS.reset(FX_Alloc(CJBig2_Image*, pSymbolDictDecoder->SDNUMINSYMS)); | 490 SDINSYMS.reset(FX_Alloc(CJBig2_Image*, pSymbolDictDecoder->SDNUMINSYMS)); |
| 491 FX_DWORD dwTemp = 0; | 491 uint32_t dwTemp = 0; |
| 492 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { | 492 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { |
| 493 CJBig2_Segment* pSeg = | 493 CJBig2_Segment* pSeg = |
| 494 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 494 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
| 495 if (pSeg->m_cFlags.s.type == 0) { | 495 if (pSeg->m_cFlags.s.type == 0) { |
| 496 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; | 496 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; |
| 497 for (size_t j = 0; j < dict.NumImages(); ++j) | 497 for (size_t j = 0; j < dict.NumImages(); ++j) |
| 498 SDINSYMS.get()[dwTemp + j] = dict.GetImage(j); | 498 SDINSYMS.get()[dwTemp + j] = dict.GetImage(j); |
| 499 dwTemp += dict.NumImages(); | 499 dwTemp += dict.NumImages(); |
| 500 } | 500 } |
| 501 } | 501 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || | 658 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || |
| 659 m_pStream->readShortInteger(&wFlags) != 0) { | 659 m_pStream->readShortInteger(&wFlags) != 0) { |
| 660 return JBIG2_ERROR_TOO_SHORT; | 660 return JBIG2_ERROR_TOO_SHORT; |
| 661 } | 661 } |
| 662 | 662 |
| 663 std::unique_ptr<CJBig2_TRDProc> pTRD(new CJBig2_TRDProc); | 663 std::unique_ptr<CJBig2_TRDProc> pTRD(new CJBig2_TRDProc); |
| 664 pTRD->SBW = ri.width; | 664 pTRD->SBW = ri.width; |
| 665 pTRD->SBH = ri.height; | 665 pTRD->SBH = ri.height; |
| 666 pTRD->SBHUFF = wFlags & 0x0001; | 666 pTRD->SBHUFF = wFlags & 0x0001; |
| 667 pTRD->SBREFINE = (wFlags >> 1) & 0x0001; | 667 pTRD->SBREFINE = (wFlags >> 1) & 0x0001; |
| 668 FX_DWORD dwTemp = (wFlags >> 2) & 0x0003; | 668 uint32_t dwTemp = (wFlags >> 2) & 0x0003; |
| 669 pTRD->SBSTRIPS = 1 << dwTemp; | 669 pTRD->SBSTRIPS = 1 << dwTemp; |
| 670 pTRD->REFCORNER = (JBig2Corner)((wFlags >> 4) & 0x0003); | 670 pTRD->REFCORNER = (JBig2Corner)((wFlags >> 4) & 0x0003); |
| 671 pTRD->TRANSPOSED = (wFlags >> 6) & 0x0001; | 671 pTRD->TRANSPOSED = (wFlags >> 6) & 0x0001; |
| 672 pTRD->SBCOMBOP = (JBig2ComposeOp)((wFlags >> 7) & 0x0003); | 672 pTRD->SBCOMBOP = (JBig2ComposeOp)((wFlags >> 7) & 0x0003); |
| 673 pTRD->SBDEFPIXEL = (wFlags >> 9) & 0x0001; | 673 pTRD->SBDEFPIXEL = (wFlags >> 9) & 0x0001; |
| 674 pTRD->SBDSOFFSET = (wFlags >> 10) & 0x001f; | 674 pTRD->SBDSOFFSET = (wFlags >> 10) & 0x001f; |
| 675 if (pTRD->SBDSOFFSET >= 0x0010) { | 675 if (pTRD->SBDSOFFSET >= 0x0010) { |
| 676 pTRD->SBDSOFFSET = pTRD->SBDSOFFSET - 0x0020; | 676 pTRD->SBDSOFFSET = pTRD->SBDSOFFSET - 0x0020; |
| 677 } | 677 } |
| 678 pTRD->SBRTEMPLATE = (wFlags >> 15) & 0x0001; | 678 pTRD->SBRTEMPLATE = (wFlags >> 15) & 0x0001; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 if (pTRD->SBHUFF == 1) { | 744 if (pTRD->SBHUFF == 1) { |
| 745 SBSYMCODES.reset( | 745 SBSYMCODES.reset( |
| 746 decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS)); | 746 decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS)); |
| 747 if (!SBSYMCODES) | 747 if (!SBSYMCODES) |
| 748 return JBIG2_ERROR_FATAL; | 748 return JBIG2_ERROR_FATAL; |
| 749 | 749 |
| 750 m_pStream->alignByte(); | 750 m_pStream->alignByte(); |
| 751 pTRD->SBSYMCODES = SBSYMCODES.get(); | 751 pTRD->SBSYMCODES = SBSYMCODES.get(); |
| 752 } else { | 752 } else { |
| 753 dwTemp = 0; | 753 dwTemp = 0; |
| 754 while ((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { | 754 while ((uint32_t)(1 << dwTemp) < pTRD->SBNUMSYMS) { |
| 755 ++dwTemp; | 755 ++dwTemp; |
| 756 } | 756 } |
| 757 pTRD->SBSYMCODELEN = (uint8_t)dwTemp; | 757 pTRD->SBSYMCODELEN = (uint8_t)dwTemp; |
| 758 } | 758 } |
| 759 | 759 |
| 760 std::unique_ptr<CJBig2_HuffmanTable> Table_B1; | 760 std::unique_ptr<CJBig2_HuffmanTable> Table_B1; |
| 761 std::unique_ptr<CJBig2_HuffmanTable> Table_B6; | 761 std::unique_ptr<CJBig2_HuffmanTable> Table_B6; |
| 762 std::unique_ptr<CJBig2_HuffmanTable> Table_B7; | 762 std::unique_ptr<CJBig2_HuffmanTable> Table_B7; |
| 763 std::unique_ptr<CJBig2_HuffmanTable> Table_B8; | 763 std::unique_ptr<CJBig2_HuffmanTable> Table_B8; |
| 764 std::unique_ptr<CJBig2_HuffmanTable> Table_B9; | 764 std::unique_ptr<CJBig2_HuffmanTable> Table_B9; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 | 992 |
| 993 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, | 993 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, |
| 994 IFX_Pause* pPause) { | 994 IFX_Pause* pPause) { |
| 995 uint8_t cFlags; | 995 uint8_t cFlags; |
| 996 JBig2RegionInfo ri; | 996 JBig2RegionInfo ri; |
| 997 std::unique_ptr<CJBig2_HTRDProc> pHRD(new CJBig2_HTRDProc); | 997 std::unique_ptr<CJBig2_HTRDProc> pHRD(new CJBig2_HTRDProc); |
| 998 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || | 998 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || |
| 999 m_pStream->read1Byte(&cFlags) != 0 || | 999 m_pStream->read1Byte(&cFlags) != 0 || |
| 1000 m_pStream->readInteger(&pHRD->HGW) != 0 || | 1000 m_pStream->readInteger(&pHRD->HGW) != 0 || |
| 1001 m_pStream->readInteger(&pHRD->HGH) != 0 || | 1001 m_pStream->readInteger(&pHRD->HGH) != 0 || |
| 1002 m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0 || | 1002 m_pStream->readInteger((uint32_t*)&pHRD->HGX) != 0 || |
| 1003 m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0 || | 1003 m_pStream->readInteger((uint32_t*)&pHRD->HGY) != 0 || |
| 1004 m_pStream->readShortInteger(&pHRD->HRX) != 0 || | 1004 m_pStream->readShortInteger(&pHRD->HRX) != 0 || |
| 1005 m_pStream->readShortInteger(&pHRD->HRY) != 0) { | 1005 m_pStream->readShortInteger(&pHRD->HRY) != 0) { |
| 1006 return JBIG2_ERROR_TOO_SHORT; | 1006 return JBIG2_ERROR_TOO_SHORT; |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 if (pHRD->HGW == 0 || pHRD->HGH == 0) | 1009 if (pHRD->HGW == 0 || pHRD->HGH == 0) |
| 1010 return JBIG2_ERROR_FATAL; | 1010 return JBIG2_ERROR_FATAL; |
| 1011 | 1011 |
| 1012 pHRD->HBW = ri.width; | 1012 pHRD->HBW = ri.width; |
| 1013 pHRD->HBH = ri.height; | 1013 pHRD->HBH = ri.height; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 new CJBig2_HuffmanTable(m_pStream.get())); | 1254 new CJBig2_HuffmanTable(m_pStream.get())); |
| 1255 if (!pHuff->IsOK()) | 1255 if (!pHuff->IsOK()) |
| 1256 return JBIG2_ERROR_FATAL; | 1256 return JBIG2_ERROR_FATAL; |
| 1257 | 1257 |
| 1258 pSegment->m_Result.ht = pHuff.release(); | 1258 pSegment->m_Result.ht = pHuff.release(); |
| 1259 m_pStream->alignByte(); | 1259 m_pStream->alignByte(); |
| 1260 return JBIG2_SUCCESS; | 1260 return JBIG2_SUCCESS; |
| 1261 } | 1261 } |
| 1262 | 1262 |
| 1263 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { | 1263 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { |
| 1264 if (m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0 || | 1264 if (m_pStream->readInteger((uint32_t*)&pRI->width) != 0 || |
| 1265 m_pStream->readInteger((FX_DWORD*)&pRI->height) != 0 || | 1265 m_pStream->readInteger((uint32_t*)&pRI->height) != 0 || |
| 1266 m_pStream->readInteger((FX_DWORD*)&pRI->x) != 0 || | 1266 m_pStream->readInteger((uint32_t*)&pRI->x) != 0 || |
| 1267 m_pStream->readInteger((FX_DWORD*)&pRI->y) != 0 || | 1267 m_pStream->readInteger((uint32_t*)&pRI->y) != 0 || |
| 1268 m_pStream->read1Byte(&pRI->flags) != 0) { | 1268 m_pStream->read1Byte(&pRI->flags) != 0) { |
| 1269 return JBIG2_ERROR_TOO_SHORT; | 1269 return JBIG2_ERROR_TOO_SHORT; |
| 1270 } | 1270 } |
| 1271 return JBIG2_SUCCESS; | 1271 return JBIG2_SUCCESS; |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( | 1274 JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( |
| 1275 CJBig2_BitStream* pStream, | 1275 CJBig2_BitStream* pStream, |
| 1276 FX_DWORD SBNUMSYMS) { | 1276 uint32_t SBNUMSYMS) { |
| 1277 const size_t kRunCodesSize = 35; | 1277 const size_t kRunCodesSize = 35; |
| 1278 int32_t runcodes[kRunCodesSize]; | 1278 int32_t runcodes[kRunCodesSize]; |
| 1279 int32_t runcodes_len[kRunCodesSize]; | 1279 int32_t runcodes_len[kRunCodesSize]; |
| 1280 for (int32_t i = 0; i < kRunCodesSize; ++i) { | 1280 for (int32_t i = 0; i < kRunCodesSize; ++i) { |
| 1281 if (pStream->readNBits(4, &runcodes_len[i]) != 0) | 1281 if (pStream->readNBits(4, &runcodes_len[i]) != 0) |
| 1282 return nullptr; | 1282 return nullptr; |
| 1283 } | 1283 } |
| 1284 huffman_assign_code(runcodes, runcodes_len, kRunCodesSize); | 1284 huffman_assign_code(runcodes, runcodes_len, kRunCodesSize); |
| 1285 | 1285 |
| 1286 std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES( | 1286 std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES( |
| 1287 FX_Alloc(JBig2HuffmanCode, SBNUMSYMS)); | 1287 FX_Alloc(JBig2HuffmanCode, SBNUMSYMS)); |
| 1288 int32_t run; | 1288 int32_t run; |
| 1289 int32_t i = 0; | 1289 int32_t i = 0; |
| 1290 while (i < (int)SBNUMSYMS) { | 1290 while (i < (int)SBNUMSYMS) { |
| 1291 int32_t j; | 1291 int32_t j; |
| 1292 int32_t nVal = 0; | 1292 int32_t nVal = 0; |
| 1293 int32_t nBits = 0; | 1293 int32_t nBits = 0; |
| 1294 FX_DWORD nTemp; | 1294 uint32_t nTemp; |
| 1295 while (true) { | 1295 while (true) { |
| 1296 if (pStream->read1Bit(&nTemp) != 0) | 1296 if (pStream->read1Bit(&nTemp) != 0) |
| 1297 return nullptr; | 1297 return nullptr; |
| 1298 | 1298 |
| 1299 nVal = (nVal << 1) | nTemp; | 1299 nVal = (nVal << 1) | nTemp; |
| 1300 ++nBits; | 1300 ++nBits; |
| 1301 for (j = 0; j < kRunCodesSize; ++j) { | 1301 for (j = 0; j < kRunCodesSize; ++j) { |
| 1302 if (nBits == runcodes_len[j] && nVal == runcodes[j]) { | 1302 if (nBits == runcodes_len[j] && nVal == runcodes[j]) { |
| 1303 break; | 1303 break; |
| 1304 } | 1304 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 SBSYMCODES[CURTEMP].code = CURCODE; | 1408 SBSYMCODES[CURTEMP].code = CURCODE; |
| 1409 CURCODE = CURCODE + 1; | 1409 CURCODE = CURCODE + 1; |
| 1410 } | 1410 } |
| 1411 CURTEMP = CURTEMP + 1; | 1411 CURTEMP = CURTEMP + 1; |
| 1412 } | 1412 } |
| 1413 CURLEN = CURLEN + 1; | 1413 CURLEN = CURLEN + 1; |
| 1414 } | 1414 } |
| 1415 FX_Free(LENCOUNT); | 1415 FX_Free(LENCOUNT); |
| 1416 FX_Free(FIRSTCODE); | 1416 FX_Free(FIRSTCODE); |
| 1417 } | 1417 } |
| OLD | NEW |