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/src/fxcodec/jbig2/JBig2_Context.h" | 7 #include "core/src/fxcodec/jbig2/JBig2_Context.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 131 } |
132 } | 132 } |
133 return JBIG2_SUCCESS; | 133 return JBIG2_SUCCESS; |
134 } | 134 } |
135 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { | 135 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { |
136 return decode_SquentialOrgnazation(pPause); | 136 return decode_SquentialOrgnazation(pPause); |
137 } | 137 } |
138 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { | 138 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { |
139 int32_t nRet; | 139 int32_t nRet; |
140 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { | 140 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { |
141 nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); | 141 std::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); |
142 nRet = parseSegmentHeader(pSegment.get()); | 142 nRet = parseSegmentHeader(pSegment.get()); |
143 if (nRet != JBIG2_SUCCESS) { | 143 if (nRet != JBIG2_SUCCESS) { |
144 return nRet; | 144 return nRet; |
145 } else if (pSegment->m_cFlags.s.type == 51) { | 145 } else if (pSegment->m_cFlags.s.type == 51) { |
146 break; | 146 break; |
147 } | 147 } |
148 m_SegmentList.push_back(pSegment.release()); | 148 m_SegmentList.push_back(pSegment.release()); |
149 if (pPause && m_pPause && pPause->NeedToPauseNow()) { | 149 if (pPause && m_pPause && pPause->NeedToPauseNow()) { |
150 m_PauseStep = 3; | 150 m_PauseStep = 3; |
151 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 151 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 return JBIG2_ERROR_FATAL; | 370 return JBIG2_ERROR_FATAL; |
371 return parseGenericRegion(pSegment, pPause); | 371 return parseGenericRegion(pSegment, pPause); |
372 case 40: | 372 case 40: |
373 case 42: | 373 case 42: |
374 case 43: | 374 case 43: |
375 if (!m_bInPage) | 375 if (!m_bInPage) |
376 return JBIG2_ERROR_FATAL; | 376 return JBIG2_ERROR_FATAL; |
377 return parseGenericRefinementRegion(pSegment); | 377 return parseGenericRefinementRegion(pSegment); |
378 case 48: { | 378 case 48: { |
379 FX_WORD wTemp; | 379 FX_WORD wTemp; |
380 nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); | 380 std::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); |
381 if (m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0 || | 381 if (m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0 || |
382 m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0 || | 382 m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0 || |
383 m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0 || | 383 m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0 || |
384 m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0 || | 384 m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0 || |
385 m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0 || | 385 m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0 || |
386 m_pStream->readShortInteger(&wTemp) != 0) { | 386 m_pStream->readShortInteger(&wTemp) != 0) { |
387 return JBIG2_ERROR_TOO_SHORT; | 387 return JBIG2_ERROR_TOO_SHORT; |
388 } | 388 } |
389 pPageInfo->m_bIsStriped = !!(wTemp & 0x8000); | 389 pPageInfo->m_bIsStriped = !!(wTemp & 0x8000); |
390 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; | 390 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 429 } |
430 return JBIG2_SUCCESS; | 430 return JBIG2_SUCCESS; |
431 } | 431 } |
432 | 432 |
433 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, | 433 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, |
434 IFX_Pause* pPause) { | 434 IFX_Pause* pPause) { |
435 FX_WORD wFlags; | 435 FX_WORD wFlags; |
436 if (m_pStream->readShortInteger(&wFlags) != 0) | 436 if (m_pStream->readShortInteger(&wFlags) != 0) |
437 return JBIG2_ERROR_TOO_SHORT; | 437 return JBIG2_ERROR_TOO_SHORT; |
438 | 438 |
439 nonstd::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc); | 439 std::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc); |
440 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; | 440 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; |
441 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; | 441 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; |
442 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; | 442 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; |
443 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; | 443 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; |
444 uint8_t cSDHUFFDH = (wFlags >> 2) & 0x0003; | 444 uint8_t cSDHUFFDH = (wFlags >> 2) & 0x0003; |
445 uint8_t cSDHUFFDW = (wFlags >> 4) & 0x0003; | 445 uint8_t cSDHUFFDW = (wFlags >> 4) & 0x0003; |
446 uint8_t cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001; | 446 uint8_t cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001; |
447 uint8_t cSDHUFFAGGINST = (wFlags >> 7) & 0x0001; | 447 uint8_t cSDHUFFAGGINST = (wFlags >> 7) & 0x0001; |
448 if (pSymbolDictDecoder->SDHUFF == 0) { | 448 if (pSymbolDictDecoder->SDHUFF == 0) { |
449 const FX_DWORD dwTemp = (pSymbolDictDecoder->SDTEMPLATE == 0) ? 8 : 2; | 449 const FX_DWORD dwTemp = (pSymbolDictDecoder->SDTEMPLATE == 0) ? 8 : 2; |
(...skipping 25 matching lines...) Expand all Loading... |
475 pSymbolDictDecoder->SDNUMINSYMS = 0; | 475 pSymbolDictDecoder->SDNUMINSYMS = 0; |
476 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { | 476 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { |
477 CJBig2_Segment* pSeg = | 477 CJBig2_Segment* pSeg = |
478 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 478 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
479 if (pSeg->m_cFlags.s.type == 0) { | 479 if (pSeg->m_cFlags.s.type == 0) { |
480 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages(); | 480 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages(); |
481 pLRSeg = pSeg; | 481 pLRSeg = pSeg; |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> SDINSYMS; | 485 std::unique_ptr<CJBig2_Image*, FxFreeDeleter> SDINSYMS; |
486 if (pSymbolDictDecoder->SDNUMINSYMS != 0) { | 486 if (pSymbolDictDecoder->SDNUMINSYMS != 0) { |
487 SDINSYMS.reset(FX_Alloc(CJBig2_Image*, pSymbolDictDecoder->SDNUMINSYMS)); | 487 SDINSYMS.reset(FX_Alloc(CJBig2_Image*, pSymbolDictDecoder->SDNUMINSYMS)); |
488 FX_DWORD dwTemp = 0; | 488 FX_DWORD dwTemp = 0; |
489 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { | 489 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { |
490 CJBig2_Segment* pSeg = | 490 CJBig2_Segment* pSeg = |
491 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 491 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
492 if (pSeg->m_cFlags.s.type == 0) { | 492 if (pSeg->m_cFlags.s.type == 0) { |
493 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; | 493 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; |
494 for (size_t j = 0; j < dict.NumImages(); ++j) | 494 for (size_t j = 0; j < dict.NumImages(); ++j) |
495 SDINSYMS.get()[dwTemp + j] = dict.GetImage(j); | 495 SDINSYMS.get()[dwTemp + j] = dict.GetImage(j); |
496 dwTemp += dict.NumImages(); | 496 dwTemp += dict.NumImages(); |
497 } | 497 } |
498 } | 498 } |
499 } | 499 } |
500 pSymbolDictDecoder->SDINSYMS = SDINSYMS.get(); | 500 pSymbolDictDecoder->SDINSYMS = SDINSYMS.get(); |
501 | 501 |
502 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B1; | 502 std::unique_ptr<CJBig2_HuffmanTable> Table_B1; |
503 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B2; | 503 std::unique_ptr<CJBig2_HuffmanTable> Table_B2; |
504 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B3; | 504 std::unique_ptr<CJBig2_HuffmanTable> Table_B3; |
505 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B4; | 505 std::unique_ptr<CJBig2_HuffmanTable> Table_B4; |
506 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B5; | 506 std::unique_ptr<CJBig2_HuffmanTable> Table_B5; |
507 if (pSymbolDictDecoder->SDHUFF == 1) { | 507 if (pSymbolDictDecoder->SDHUFF == 1) { |
508 if (cSDHUFFDH == 2 || cSDHUFFDW == 2) | 508 if (cSDHUFFDH == 2 || cSDHUFFDW == 2) |
509 return JBIG2_ERROR_FATAL; | 509 return JBIG2_ERROR_FATAL; |
510 | 510 |
511 int32_t nIndex = 0; | 511 int32_t nIndex = 0; |
512 if (cSDHUFFDH == 0) { | 512 if (cSDHUFFDH == 0) { |
513 Table_B4.reset(new CJBig2_HuffmanTable(HuffmanTable_B4, | 513 Table_B4.reset(new CJBig2_HuffmanTable(HuffmanTable_B4, |
514 FX_ArraySize(HuffmanTable_B4), | 514 FX_ArraySize(HuffmanTable_B4), |
515 HuffmanTable_HTOOB_B4)); | 515 HuffmanTable_HTOOB_B4)); |
516 pSymbolDictDecoder->SDHUFFDH = Table_B4.get(); | 516 pSymbolDictDecoder->SDHUFFDH = Table_B4.get(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 } | 600 } |
601 | 601 |
602 CJBig2_CacheKey key = | 602 CJBig2_CacheKey key = |
603 CJBig2_CacheKey(pSegment->m_dwObjNum, pSegment->m_dwDataOffset); | 603 CJBig2_CacheKey(pSegment->m_dwObjNum, pSegment->m_dwDataOffset); |
604 FX_BOOL cache_hit = false; | 604 FX_BOOL cache_hit = false; |
605 pSegment->m_nResultType = JBIG2_SYMBOL_DICT_POINTER; | 605 pSegment->m_nResultType = JBIG2_SYMBOL_DICT_POINTER; |
606 if (m_bIsGlobal && key.first != 0) { | 606 if (m_bIsGlobal && key.first != 0) { |
607 for (auto it = m_pSymbolDictCache->begin(); it != m_pSymbolDictCache->end(); | 607 for (auto it = m_pSymbolDictCache->begin(); it != m_pSymbolDictCache->end(); |
608 ++it) { | 608 ++it) { |
609 if (it->first == key) { | 609 if (it->first == key) { |
610 nonstd::unique_ptr<CJBig2_SymbolDict> copy(it->second->DeepCopy()); | 610 std::unique_ptr<CJBig2_SymbolDict> copy(it->second->DeepCopy()); |
611 pSegment->m_Result.sd = copy.release(); | 611 pSegment->m_Result.sd = copy.release(); |
612 m_pSymbolDictCache->push_front(*it); | 612 m_pSymbolDictCache->push_front(*it); |
613 m_pSymbolDictCache->erase(it); | 613 m_pSymbolDictCache->erase(it); |
614 cache_hit = true; | 614 cache_hit = true; |
615 break; | 615 break; |
616 } | 616 } |
617 } | 617 } |
618 } | 618 } |
619 if (!cache_hit) { | 619 if (!cache_hit) { |
620 if (bUseGbContext) { | 620 if (bUseGbContext) { |
621 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 621 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
622 new CJBig2_ArithDecoder(m_pStream.get())); | 622 new CJBig2_ArithDecoder(m_pStream.get())); |
623 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Arith( | 623 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Arith( |
624 pArithDecoder.get(), &gbContext, &grContext); | 624 pArithDecoder.get(), &gbContext, &grContext); |
625 if (!pSegment->m_Result.sd) | 625 if (!pSegment->m_Result.sd) |
626 return JBIG2_ERROR_FATAL; | 626 return JBIG2_ERROR_FATAL; |
627 | 627 |
628 m_pStream->alignByte(); | 628 m_pStream->alignByte(); |
629 m_pStream->offset(2); | 629 m_pStream->offset(2); |
630 } else { | 630 } else { |
631 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman( | 631 pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman( |
632 m_pStream.get(), &gbContext, &grContext, pPause); | 632 m_pStream.get(), &gbContext, &grContext, pPause); |
633 if (!pSegment->m_Result.sd) | 633 if (!pSegment->m_Result.sd) |
634 return JBIG2_ERROR_FATAL; | 634 return JBIG2_ERROR_FATAL; |
635 m_pStream->alignByte(); | 635 m_pStream->alignByte(); |
636 } | 636 } |
637 if (m_bIsGlobal && kSymbolDictCacheMaxSize > 0) { | 637 if (m_bIsGlobal && kSymbolDictCacheMaxSize > 0) { |
638 nonstd::unique_ptr<CJBig2_SymbolDict> value = | 638 std::unique_ptr<CJBig2_SymbolDict> value = |
639 pSegment->m_Result.sd->DeepCopy(); | 639 pSegment->m_Result.sd->DeepCopy(); |
640 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { | 640 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { |
641 delete m_pSymbolDictCache->back().second; | 641 delete m_pSymbolDictCache->back().second; |
642 m_pSymbolDictCache->pop_back(); | 642 m_pSymbolDictCache->pop_back(); |
643 } | 643 } |
644 m_pSymbolDictCache->push_front(CJBig2_CachePair(key, value.release())); | 644 m_pSymbolDictCache->push_front(CJBig2_CachePair(key, value.release())); |
645 } | 645 } |
646 } | 646 } |
647 if (wFlags & 0x0200) { | 647 if (wFlags & 0x0200) { |
648 if (bUseGbContext) | 648 if (bUseGbContext) |
649 pSegment->m_Result.sd->SetGbContext(gbContext); | 649 pSegment->m_Result.sd->SetGbContext(gbContext); |
650 if (bUseGrContext) | 650 if (bUseGrContext) |
651 pSegment->m_Result.sd->SetGrContext(grContext); | 651 pSegment->m_Result.sd->SetGrContext(grContext); |
652 } | 652 } |
653 return JBIG2_SUCCESS; | 653 return JBIG2_SUCCESS; |
654 } | 654 } |
655 | 655 |
656 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { | 656 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { |
657 FX_WORD wFlags; | 657 FX_WORD wFlags; |
658 JBig2RegionInfo ri; | 658 JBig2RegionInfo ri; |
659 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || | 659 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || |
660 m_pStream->readShortInteger(&wFlags) != 0) { | 660 m_pStream->readShortInteger(&wFlags) != 0) { |
661 return JBIG2_ERROR_TOO_SHORT; | 661 return JBIG2_ERROR_TOO_SHORT; |
662 } | 662 } |
663 | 663 |
664 nonstd::unique_ptr<CJBig2_TRDProc> pTRD(new CJBig2_TRDProc); | 664 std::unique_ptr<CJBig2_TRDProc> pTRD(new CJBig2_TRDProc); |
665 pTRD->SBW = ri.width; | 665 pTRD->SBW = ri.width; |
666 pTRD->SBH = ri.height; | 666 pTRD->SBH = ri.height; |
667 pTRD->SBHUFF = wFlags & 0x0001; | 667 pTRD->SBHUFF = wFlags & 0x0001; |
668 pTRD->SBREFINE = (wFlags >> 1) & 0x0001; | 668 pTRD->SBREFINE = (wFlags >> 1) & 0x0001; |
669 FX_DWORD dwTemp = (wFlags >> 2) & 0x0003; | 669 FX_DWORD dwTemp = (wFlags >> 2) & 0x0003; |
670 pTRD->SBSTRIPS = 1 << dwTemp; | 670 pTRD->SBSTRIPS = 1 << dwTemp; |
671 pTRD->REFCORNER = (JBig2Corner)((wFlags >> 4) & 0x0003); | 671 pTRD->REFCORNER = (JBig2Corner)((wFlags >> 4) & 0x0003); |
672 pTRD->TRANSPOSED = (wFlags >> 6) & 0x0001; | 672 pTRD->TRANSPOSED = (wFlags >> 6) & 0x0001; |
673 pTRD->SBCOMBOP = (JBig2ComposeOp)((wFlags >> 7) & 0x0003); | 673 pTRD->SBCOMBOP = (JBig2ComposeOp)((wFlags >> 7) & 0x0003); |
674 pTRD->SBDEFPIXEL = (wFlags >> 9) & 0x0001; | 674 pTRD->SBDEFPIXEL = (wFlags >> 9) & 0x0001; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 | 715 |
716 pTRD->SBNUMSYMS = 0; | 716 pTRD->SBNUMSYMS = 0; |
717 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { | 717 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { |
718 CJBig2_Segment* pSeg = | 718 CJBig2_Segment* pSeg = |
719 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 719 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
720 if (pSeg->m_cFlags.s.type == 0) { | 720 if (pSeg->m_cFlags.s.type == 0) { |
721 pTRD->SBNUMSYMS += pSeg->m_Result.sd->NumImages(); | 721 pTRD->SBNUMSYMS += pSeg->m_Result.sd->NumImages(); |
722 } | 722 } |
723 } | 723 } |
724 | 724 |
725 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> SBSYMS; | 725 std::unique_ptr<CJBig2_Image*, FxFreeDeleter> SBSYMS; |
726 if (pTRD->SBNUMSYMS > 0) { | 726 if (pTRD->SBNUMSYMS > 0) { |
727 SBSYMS.reset(FX_Alloc(CJBig2_Image*, pTRD->SBNUMSYMS)); | 727 SBSYMS.reset(FX_Alloc(CJBig2_Image*, pTRD->SBNUMSYMS)); |
728 dwTemp = 0; | 728 dwTemp = 0; |
729 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { | 729 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { |
730 CJBig2_Segment* pSeg = | 730 CJBig2_Segment* pSeg = |
731 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 731 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
732 if (pSeg->m_cFlags.s.type == 0) { | 732 if (pSeg->m_cFlags.s.type == 0) { |
733 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; | 733 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; |
734 for (size_t j = 0; j < dict.NumImages(); ++j) | 734 for (size_t j = 0; j < dict.NumImages(); ++j) |
735 SBSYMS.get()[dwTemp + j] = dict.GetImage(j); | 735 SBSYMS.get()[dwTemp + j] = dict.GetImage(j); |
736 dwTemp += dict.NumImages(); | 736 dwTemp += dict.NumImages(); |
737 } | 737 } |
738 } | 738 } |
739 pTRD->SBSYMS = SBSYMS.get(); | 739 pTRD->SBSYMS = SBSYMS.get(); |
740 } else { | 740 } else { |
741 pTRD->SBSYMS = NULL; | 741 pTRD->SBSYMS = NULL; |
742 } | 742 } |
743 | 743 |
744 nonstd::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES; | 744 std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES; |
745 if (pTRD->SBHUFF == 1) { | 745 if (pTRD->SBHUFF == 1) { |
746 SBSYMCODES.reset( | 746 SBSYMCODES.reset( |
747 decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS)); | 747 decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS)); |
748 if (!SBSYMCODES) | 748 if (!SBSYMCODES) |
749 return JBIG2_ERROR_FATAL; | 749 return JBIG2_ERROR_FATAL; |
750 | 750 |
751 m_pStream->alignByte(); | 751 m_pStream->alignByte(); |
752 pTRD->SBSYMCODES = SBSYMCODES.get(); | 752 pTRD->SBSYMCODES = SBSYMCODES.get(); |
753 } else { | 753 } else { |
754 dwTemp = 0; | 754 dwTemp = 0; |
755 while ((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { | 755 while ((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { |
756 ++dwTemp; | 756 ++dwTemp; |
757 } | 757 } |
758 pTRD->SBSYMCODELEN = (uint8_t)dwTemp; | 758 pTRD->SBSYMCODELEN = (uint8_t)dwTemp; |
759 } | 759 } |
760 | 760 |
761 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B1; | 761 std::unique_ptr<CJBig2_HuffmanTable> Table_B1; |
762 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B6; | 762 std::unique_ptr<CJBig2_HuffmanTable> Table_B6; |
763 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B7; | 763 std::unique_ptr<CJBig2_HuffmanTable> Table_B7; |
764 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B8; | 764 std::unique_ptr<CJBig2_HuffmanTable> Table_B8; |
765 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B9; | 765 std::unique_ptr<CJBig2_HuffmanTable> Table_B9; |
766 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B10; | 766 std::unique_ptr<CJBig2_HuffmanTable> Table_B10; |
767 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B11; | 767 std::unique_ptr<CJBig2_HuffmanTable> Table_B11; |
768 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B12; | 768 std::unique_ptr<CJBig2_HuffmanTable> Table_B12; |
769 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B13; | 769 std::unique_ptr<CJBig2_HuffmanTable> Table_B13; |
770 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B14; | 770 std::unique_ptr<CJBig2_HuffmanTable> Table_B14; |
771 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B15; | 771 std::unique_ptr<CJBig2_HuffmanTable> Table_B15; |
772 if (pTRD->SBHUFF == 1) { | 772 if (pTRD->SBHUFF == 1) { |
773 if (cSBHUFFFS == 2 || cSBHUFFRDW == 2 || cSBHUFFRDH == 2 || | 773 if (cSBHUFFFS == 2 || cSBHUFFRDW == 2 || cSBHUFFRDH == 2 || |
774 cSBHUFFRDX == 2 || cSBHUFFRDY == 2) { | 774 cSBHUFFRDX == 2 || cSBHUFFRDY == 2) { |
775 return JBIG2_ERROR_FATAL; | 775 return JBIG2_ERROR_FATAL; |
776 } | 776 } |
777 int32_t nIndex = 0; | 777 int32_t nIndex = 0; |
778 if (cSBHUFFFS == 0) { | 778 if (cSBHUFFFS == 0) { |
779 Table_B6.reset(new CJBig2_HuffmanTable(HuffmanTable_B6, | 779 Table_B6.reset(new CJBig2_HuffmanTable(HuffmanTable_B6, |
780 FX_ArraySize(HuffmanTable_B6), | 780 FX_ArraySize(HuffmanTable_B6), |
781 HuffmanTable_HTOOB_B6)); | 781 HuffmanTable_HTOOB_B6)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 HuffmanTable_HTOOB_B1)); | 922 HuffmanTable_HTOOB_B1)); |
923 pTRD->SBHUFFRSIZE = Table_B1.get(); | 923 pTRD->SBHUFFRSIZE = Table_B1.get(); |
924 } else { | 924 } else { |
925 CJBig2_Segment* pSeg = | 925 CJBig2_Segment* pSeg = |
926 findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 926 findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
927 if (!pSeg) | 927 if (!pSeg) |
928 return JBIG2_ERROR_FATAL; | 928 return JBIG2_ERROR_FATAL; |
929 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; | 929 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; |
930 } | 930 } |
931 } | 931 } |
932 nonstd::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext; | 932 std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext; |
933 if (pTRD->SBREFINE == 1) { | 933 if (pTRD->SBREFINE == 1) { |
934 const size_t size = GetRefAggContextSize(pTRD->SBRTEMPLATE); | 934 const size_t size = GetRefAggContextSize(pTRD->SBRTEMPLATE); |
935 grContext.reset(FX_Alloc(JBig2ArithCtx, size)); | 935 grContext.reset(FX_Alloc(JBig2ArithCtx, size)); |
936 JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); | 936 JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); |
937 } | 937 } |
938 if (pTRD->SBHUFF == 0) { | 938 if (pTRD->SBHUFF == 0) { |
939 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 939 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
940 new CJBig2_ArithDecoder(m_pStream.get())); | 940 new CJBig2_ArithDecoder(m_pStream.get())); |
941 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 941 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
942 pSegment->m_Result.im = | 942 pSegment->m_Result.im = |
943 pTRD->decode_Arith(pArithDecoder.get(), grContext.get()); | 943 pTRD->decode_Arith(pArithDecoder.get(), grContext.get()); |
944 if (!pSegment->m_Result.im) | 944 if (!pSegment->m_Result.im) |
945 return JBIG2_ERROR_FATAL; | 945 return JBIG2_ERROR_FATAL; |
946 m_pStream->alignByte(); | 946 m_pStream->alignByte(); |
947 m_pStream->offset(2); | 947 m_pStream->offset(2); |
948 } else { | 948 } else { |
949 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 949 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
(...skipping 15 matching lines...) Expand all Loading... |
965 (JBig2ComposeOp)(ri.flags & 0x03)); | 965 (JBig2ComposeOp)(ri.flags & 0x03)); |
966 delete pSegment->m_Result.im; | 966 delete pSegment->m_Result.im; |
967 pSegment->m_Result.im = NULL; | 967 pSegment->m_Result.im = NULL; |
968 } | 968 } |
969 return JBIG2_SUCCESS; | 969 return JBIG2_SUCCESS; |
970 } | 970 } |
971 | 971 |
972 int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, | 972 int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, |
973 IFX_Pause* pPause) { | 973 IFX_Pause* pPause) { |
974 uint8_t cFlags; | 974 uint8_t cFlags; |
975 nonstd::unique_ptr<CJBig2_PDDProc> pPDD(new CJBig2_PDDProc); | 975 std::unique_ptr<CJBig2_PDDProc> pPDD(new CJBig2_PDDProc); |
976 if (m_pStream->read1Byte(&cFlags) != 0 || | 976 if (m_pStream->read1Byte(&cFlags) != 0 || |
977 m_pStream->read1Byte(&pPDD->HDPW) != 0 || | 977 m_pStream->read1Byte(&pPDD->HDPW) != 0 || |
978 m_pStream->read1Byte(&pPDD->HDPH) != 0 || | 978 m_pStream->read1Byte(&pPDD->HDPH) != 0 || |
979 m_pStream->readInteger(&pPDD->GRAYMAX) != 0) { | 979 m_pStream->readInteger(&pPDD->GRAYMAX) != 0) { |
980 return JBIG2_ERROR_TOO_SHORT; | 980 return JBIG2_ERROR_TOO_SHORT; |
981 } | 981 } |
982 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) | 982 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) |
983 return JBIG2_ERROR_LIMIT; | 983 return JBIG2_ERROR_LIMIT; |
984 | 984 |
985 pPDD->HDMMR = cFlags & 0x01; | 985 pPDD->HDMMR = cFlags & 0x01; |
986 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; | 986 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; |
987 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; | 987 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; |
988 if (pPDD->HDMMR == 0) { | 988 if (pPDD->HDMMR == 0) { |
989 const size_t size = GetHuffContextSize(pPDD->HDTEMPLATE); | 989 const size_t size = GetHuffContextSize(pPDD->HDTEMPLATE); |
990 nonstd::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( | 990 std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( |
991 FX_Alloc(JBig2ArithCtx, size)); | 991 FX_Alloc(JBig2ArithCtx, size)); |
992 JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); | 992 JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); |
993 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 993 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
994 new CJBig2_ArithDecoder(m_pStream.get())); | 994 new CJBig2_ArithDecoder(m_pStream.get())); |
995 pSegment->m_Result.pd = | 995 pSegment->m_Result.pd = |
996 pPDD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); | 996 pPDD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); |
997 if (!pSegment->m_Result.pd) | 997 if (!pSegment->m_Result.pd) |
998 return JBIG2_ERROR_FATAL; | 998 return JBIG2_ERROR_FATAL; |
999 | 999 |
1000 m_pStream->alignByte(); | 1000 m_pStream->alignByte(); |
1001 m_pStream->offset(2); | 1001 m_pStream->offset(2); |
1002 } else { | 1002 } else { |
1003 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream.get(), pPause); | 1003 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream.get(), pPause); |
1004 if (!pSegment->m_Result.pd) | 1004 if (!pSegment->m_Result.pd) |
1005 return JBIG2_ERROR_FATAL; | 1005 return JBIG2_ERROR_FATAL; |
1006 m_pStream->alignByte(); | 1006 m_pStream->alignByte(); |
1007 } | 1007 } |
1008 return JBIG2_SUCCESS; | 1008 return JBIG2_SUCCESS; |
1009 } | 1009 } |
1010 | 1010 |
1011 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, | 1011 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, |
1012 IFX_Pause* pPause) { | 1012 IFX_Pause* pPause) { |
1013 uint8_t cFlags; | 1013 uint8_t cFlags; |
1014 JBig2RegionInfo ri; | 1014 JBig2RegionInfo ri; |
1015 nonstd::unique_ptr<CJBig2_HTRDProc> pHRD(new CJBig2_HTRDProc); | 1015 std::unique_ptr<CJBig2_HTRDProc> pHRD(new CJBig2_HTRDProc); |
1016 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || | 1016 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || |
1017 m_pStream->read1Byte(&cFlags) != 0 || | 1017 m_pStream->read1Byte(&cFlags) != 0 || |
1018 m_pStream->readInteger(&pHRD->HGW) != 0 || | 1018 m_pStream->readInteger(&pHRD->HGW) != 0 || |
1019 m_pStream->readInteger(&pHRD->HGH) != 0 || | 1019 m_pStream->readInteger(&pHRD->HGH) != 0 || |
1020 m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0 || | 1020 m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0 || |
1021 m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0 || | 1021 m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0 || |
1022 m_pStream->readShortInteger(&pHRD->HRX) != 0 || | 1022 m_pStream->readShortInteger(&pHRD->HRX) != 0 || |
1023 m_pStream->readShortInteger(&pHRD->HRY) != 0) { | 1023 m_pStream->readShortInteger(&pHRD->HRY) != 0) { |
1024 return JBIG2_ERROR_TOO_SHORT; | 1024 return JBIG2_ERROR_TOO_SHORT; |
1025 } | 1025 } |
(...skipping 20 matching lines...) Expand all Loading... |
1046 if (!pPatternDict || (pPatternDict->NUMPATS == 0)) | 1046 if (!pPatternDict || (pPatternDict->NUMPATS == 0)) |
1047 return JBIG2_ERROR_FATAL; | 1047 return JBIG2_ERROR_FATAL; |
1048 | 1048 |
1049 pHRD->HNUMPATS = pPatternDict->NUMPATS; | 1049 pHRD->HNUMPATS = pPatternDict->NUMPATS; |
1050 pHRD->HPATS = pPatternDict->HDPATS; | 1050 pHRD->HPATS = pPatternDict->HDPATS; |
1051 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; | 1051 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; |
1052 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; | 1052 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; |
1053 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1053 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1054 if (pHRD->HMMR == 0) { | 1054 if (pHRD->HMMR == 0) { |
1055 const size_t size = GetHuffContextSize(pHRD->HTEMPLATE); | 1055 const size_t size = GetHuffContextSize(pHRD->HTEMPLATE); |
1056 nonstd::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( | 1056 std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( |
1057 FX_Alloc(JBig2ArithCtx, size)); | 1057 FX_Alloc(JBig2ArithCtx, size)); |
1058 JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); | 1058 JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); |
1059 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 1059 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
1060 new CJBig2_ArithDecoder(m_pStream.get())); | 1060 new CJBig2_ArithDecoder(m_pStream.get())); |
1061 pSegment->m_Result.im = | 1061 pSegment->m_Result.im = |
1062 pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); | 1062 pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); |
1063 if (!pSegment->m_Result.im) | 1063 if (!pSegment->m_Result.im) |
1064 return JBIG2_ERROR_FATAL; | 1064 return JBIG2_ERROR_FATAL; |
1065 | 1065 |
1066 m_pStream->alignByte(); | 1066 m_pStream->alignByte(); |
1067 m_pStream->offset(2); | 1067 m_pStream->offset(2); |
1068 } else { | 1068 } else { |
1069 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get(), pPause); | 1069 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get(), pPause); |
(...skipping 13 matching lines...) Expand all Loading... |
1083 (JBig2ComposeOp)(ri.flags & 0x03)); | 1083 (JBig2ComposeOp)(ri.flags & 0x03)); |
1084 delete pSegment->m_Result.im; | 1084 delete pSegment->m_Result.im; |
1085 pSegment->m_Result.im = NULL; | 1085 pSegment->m_Result.im = NULL; |
1086 } | 1086 } |
1087 return JBIG2_SUCCESS; | 1087 return JBIG2_SUCCESS; |
1088 } | 1088 } |
1089 | 1089 |
1090 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, | 1090 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, |
1091 IFX_Pause* pPause) { | 1091 IFX_Pause* pPause) { |
1092 if (!m_pGRD) { | 1092 if (!m_pGRD) { |
1093 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc); | 1093 std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc); |
1094 uint8_t cFlags; | 1094 uint8_t cFlags; |
1095 if (parseRegionInfo(&m_ri) != JBIG2_SUCCESS || | 1095 if (parseRegionInfo(&m_ri) != JBIG2_SUCCESS || |
1096 m_pStream->read1Byte(&cFlags) != 0) { | 1096 m_pStream->read1Byte(&cFlags) != 0) { |
1097 return JBIG2_ERROR_TOO_SHORT; | 1097 return JBIG2_ERROR_TOO_SHORT; |
1098 } | 1098 } |
1099 if (m_ri.height < 0 || m_ri.width < 0) | 1099 if (m_ri.height < 0 || m_ri.width < 0) |
1100 return JBIG2_FAILED; | 1100 return JBIG2_FAILED; |
1101 | 1101 |
1102 pGRD->GBW = m_ri.width; | 1102 pGRD->GBW = m_ri.width; |
1103 pGRD->GBH = m_ri.height; | 1103 pGRD->GBH = m_ri.height; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 return JBIG2_SUCCESS; | 1196 return JBIG2_SUCCESS; |
1197 } | 1197 } |
1198 | 1198 |
1199 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { | 1199 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { |
1200 JBig2RegionInfo ri; | 1200 JBig2RegionInfo ri; |
1201 uint8_t cFlags; | 1201 uint8_t cFlags; |
1202 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || | 1202 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || |
1203 m_pStream->read1Byte(&cFlags) != 0) { | 1203 m_pStream->read1Byte(&cFlags) != 0) { |
1204 return JBIG2_ERROR_TOO_SHORT; | 1204 return JBIG2_ERROR_TOO_SHORT; |
1205 } | 1205 } |
1206 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc); | 1206 std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc); |
1207 pGRRD->GRW = ri.width; | 1207 pGRRD->GRW = ri.width; |
1208 pGRRD->GRH = ri.height; | 1208 pGRRD->GRH = ri.height; |
1209 pGRRD->GRTEMPLATE = cFlags & 0x01; | 1209 pGRRD->GRTEMPLATE = cFlags & 0x01; |
1210 pGRRD->TPGRON = (cFlags >> 1) & 0x01; | 1210 pGRRD->TPGRON = (cFlags >> 1) & 0x01; |
1211 if (pGRRD->GRTEMPLATE == 0) { | 1211 if (pGRRD->GRTEMPLATE == 0) { |
1212 for (int32_t i = 0; i < 4; ++i) { | 1212 for (int32_t i = 0; i < 4; ++i) { |
1213 if (m_pStream->read1Byte((uint8_t*)&pGRRD->GRAT[i]) != 0) | 1213 if (m_pStream->read1Byte((uint8_t*)&pGRRD->GRAT[i]) != 0) |
1214 return JBIG2_ERROR_TOO_SHORT; | 1214 return JBIG2_ERROR_TOO_SHORT; |
1215 } | 1215 } |
1216 } | 1216 } |
(...skipping 13 matching lines...) Expand all Loading... |
1230 if (i >= pSegment->m_nReferred_to_segment_count) | 1230 if (i >= pSegment->m_nReferred_to_segment_count) |
1231 return JBIG2_ERROR_FATAL; | 1231 return JBIG2_ERROR_FATAL; |
1232 | 1232 |
1233 pGRRD->GRREFERENCE = pSeg->m_Result.im; | 1233 pGRRD->GRREFERENCE = pSeg->m_Result.im; |
1234 } else { | 1234 } else { |
1235 pGRRD->GRREFERENCE = m_pPage.get(); | 1235 pGRRD->GRREFERENCE = m_pPage.get(); |
1236 } | 1236 } |
1237 pGRRD->GRREFERENCEDX = 0; | 1237 pGRRD->GRREFERENCEDX = 0; |
1238 pGRRD->GRREFERENCEDY = 0; | 1238 pGRRD->GRREFERENCEDY = 0; |
1239 const size_t size = GetRefAggContextSize(pGRRD->GRTEMPLATE); | 1239 const size_t size = GetRefAggContextSize(pGRRD->GRTEMPLATE); |
1240 nonstd::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext( | 1240 std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext( |
1241 FX_Alloc(JBig2ArithCtx, size)); | 1241 FX_Alloc(JBig2ArithCtx, size)); |
1242 JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); | 1242 JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); |
1243 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 1243 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
1244 new CJBig2_ArithDecoder(m_pStream.get())); | 1244 new CJBig2_ArithDecoder(m_pStream.get())); |
1245 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1245 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1246 pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get()); | 1246 pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get()); |
1247 if (!pSegment->m_Result.im) | 1247 if (!pSegment->m_Result.im) |
1248 return JBIG2_ERROR_FATAL; | 1248 return JBIG2_ERROR_FATAL; |
1249 | 1249 |
1250 m_pStream->alignByte(); | 1250 m_pStream->alignByte(); |
1251 m_pStream->offset(2); | 1251 m_pStream->offset(2); |
1252 if (pSegment->m_cFlags.s.type != 40) { | 1252 if (pSegment->m_cFlags.s.type != 40) { |
1253 if (!m_bBufSpecified) { | 1253 if (!m_bBufSpecified) { |
1254 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1254 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1255 if ((pPageInfo->m_bIsStriped == 1) && | 1255 if ((pPageInfo->m_bIsStriped == 1) && |
1256 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1256 (ri.y + ri.height > m_pPage->m_nHeight)) { |
1257 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1257 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1258 } | 1258 } |
1259 } | 1259 } |
1260 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1260 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
1261 (JBig2ComposeOp)(ri.flags & 0x03)); | 1261 (JBig2ComposeOp)(ri.flags & 0x03)); |
1262 delete pSegment->m_Result.im; | 1262 delete pSegment->m_Result.im; |
1263 pSegment->m_Result.im = NULL; | 1263 pSegment->m_Result.im = NULL; |
1264 } | 1264 } |
1265 return JBIG2_SUCCESS; | 1265 return JBIG2_SUCCESS; |
1266 } | 1266 } |
1267 | 1267 |
1268 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { | 1268 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { |
1269 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; | 1269 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; |
1270 pSegment->m_Result.ht = nullptr; | 1270 pSegment->m_Result.ht = nullptr; |
1271 nonstd::unique_ptr<CJBig2_HuffmanTable> pHuff( | 1271 std::unique_ptr<CJBig2_HuffmanTable> pHuff( |
1272 new CJBig2_HuffmanTable(m_pStream.get())); | 1272 new CJBig2_HuffmanTable(m_pStream.get())); |
1273 if (!pHuff->IsOK()) | 1273 if (!pHuff->IsOK()) |
1274 return JBIG2_ERROR_FATAL; | 1274 return JBIG2_ERROR_FATAL; |
1275 | 1275 |
1276 pSegment->m_Result.ht = pHuff.release(); | 1276 pSegment->m_Result.ht = pHuff.release(); |
1277 m_pStream->alignByte(); | 1277 m_pStream->alignByte(); |
1278 return JBIG2_SUCCESS; | 1278 return JBIG2_SUCCESS; |
1279 } | 1279 } |
1280 | 1280 |
1281 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { | 1281 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { |
(...skipping 12 matching lines...) Expand all Loading... |
1294 FX_DWORD SBNUMSYMS) { | 1294 FX_DWORD SBNUMSYMS) { |
1295 const size_t kRunCodesSize = 35; | 1295 const size_t kRunCodesSize = 35; |
1296 int32_t runcodes[kRunCodesSize]; | 1296 int32_t runcodes[kRunCodesSize]; |
1297 int32_t runcodes_len[kRunCodesSize]; | 1297 int32_t runcodes_len[kRunCodesSize]; |
1298 for (int32_t i = 0; i < kRunCodesSize; ++i) { | 1298 for (int32_t i = 0; i < kRunCodesSize; ++i) { |
1299 if (pStream->readNBits(4, &runcodes_len[i]) != 0) | 1299 if (pStream->readNBits(4, &runcodes_len[i]) != 0) |
1300 return nullptr; | 1300 return nullptr; |
1301 } | 1301 } |
1302 huffman_assign_code(runcodes, runcodes_len, kRunCodesSize); | 1302 huffman_assign_code(runcodes, runcodes_len, kRunCodesSize); |
1303 | 1303 |
1304 nonstd::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES( | 1304 std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES( |
1305 FX_Alloc(JBig2HuffmanCode, SBNUMSYMS)); | 1305 FX_Alloc(JBig2HuffmanCode, SBNUMSYMS)); |
1306 int32_t run; | 1306 int32_t run; |
1307 int32_t i = 0; | 1307 int32_t i = 0; |
1308 while (i < (int)SBNUMSYMS) { | 1308 while (i < (int)SBNUMSYMS) { |
1309 int32_t j; | 1309 int32_t j; |
1310 int32_t nVal = 0; | 1310 int32_t nVal = 0; |
1311 int32_t nBits = 0; | 1311 int32_t nBits = 0; |
1312 FX_DWORD nTemp; | 1312 FX_DWORD nTemp; |
1313 while (true) { | 1313 while (true) { |
1314 if (pStream->read1Bit(&nTemp) != 0) | 1314 if (pStream->read1Bit(&nTemp) != 0) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 SBSYMCODES[CURTEMP].code = CURCODE; | 1426 SBSYMCODES[CURTEMP].code = CURCODE; |
1427 CURCODE = CURCODE + 1; | 1427 CURCODE = CURCODE + 1; |
1428 } | 1428 } |
1429 CURTEMP = CURTEMP + 1; | 1429 CURTEMP = CURTEMP + 1; |
1430 } | 1430 } |
1431 CURLEN = CURLEN + 1; | 1431 CURLEN = CURLEN + 1; |
1432 } | 1432 } |
1433 FX_Free(LENCOUNT); | 1433 FX_Free(LENCOUNT); |
1434 FX_Free(FIRSTCODE); | 1434 FX_Free(FIRSTCODE); |
1435 } | 1435 } |
OLD | NEW |