Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: core/src/fxcodec/jbig2/JBig2_Context.cpp

Issue 1395613003: Put CJBig2_SymbolDict's images in a CJBig2_List container. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "JBig2_Context.h" 7 #include "JBig2_Context.h"
8 8
9 #include <list> 9 #include <list>
10 10
11 #include "JBig2_ArithDecoder.h"
11 #include "JBig2_GrdProc.h" 12 #include "JBig2_GrdProc.h"
12 #include "JBig2_GrrdProc.h" 13 #include "JBig2_GrrdProc.h"
13 #include "JBig2_HtrdProc.h" 14 #include "JBig2_HtrdProc.h"
14 #include "JBig2_PddProc.h" 15 #include "JBig2_PddProc.h"
15 #include "JBig2_SddProc.h" 16 #include "JBig2_SddProc.h"
16 #include "JBig2_TrdProc.h" 17 #include "JBig2_TrdProc.h"
17 18
18 namespace { 19 namespace {
19 20
20 size_t GetHuffContextSize(uint8_t val) { 21 size_t GetHuffContextSize(uint8_t val) {
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 472 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
472 if (!findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i])) 473 if (!findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]))
473 return JBIG2_ERROR_FATAL; 474 return JBIG2_ERROR_FATAL;
474 } 475 }
475 CJBig2_Segment* pLRSeg = nullptr; 476 CJBig2_Segment* pLRSeg = nullptr;
476 pSymbolDictDecoder->SDNUMINSYMS = 0; 477 pSymbolDictDecoder->SDNUMINSYMS = 0;
477 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 478 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
478 CJBig2_Segment* pSeg = 479 CJBig2_Segment* pSeg =
479 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 480 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
480 if (pSeg->m_cFlags.s.type == 0) { 481 if (pSeg->m_cFlags.s.type == 0) {
481 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; 482 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages();
482 pLRSeg = pSeg; 483 pLRSeg = pSeg;
483 } 484 }
484 } 485 }
485 486
486 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> SDINSYMS; 487 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> SDINSYMS;
487 if (pSymbolDictDecoder->SDNUMINSYMS != 0) { 488 if (pSymbolDictDecoder->SDNUMINSYMS != 0) {
488 SDINSYMS.reset(FX_Alloc(CJBig2_Image*, pSymbolDictDecoder->SDNUMINSYMS)); 489 SDINSYMS.reset(FX_Alloc(CJBig2_Image*, pSymbolDictDecoder->SDNUMINSYMS));
489 FX_DWORD dwTemp = 0; 490 FX_DWORD dwTemp = 0;
490 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 491 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
491 CJBig2_Segment* pSeg = 492 CJBig2_Segment* pSeg =
492 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 493 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
493 if (pSeg->m_cFlags.s.type == 0) { 494 if (pSeg->m_cFlags.s.type == 0) {
494 JBIG2_memcpy(SDINSYMS.get() + dwTemp, pSeg->m_Result.sd->SDEXSYMS, 495 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd;
495 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); 496 for (size_t j = 0; j < dict.NumImages(); ++j)
496 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; 497 SDINSYMS.get()[dwTemp + j] = dict.GetImage(j);
498 dwTemp += dict.NumImages();
497 } 499 }
498 } 500 }
499 } 501 }
500 pSymbolDictDecoder->SDINSYMS = SDINSYMS.get(); 502 pSymbolDictDecoder->SDINSYMS = SDINSYMS.get();
501 503
502 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B1; 504 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B1;
503 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B2; 505 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B2;
504 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B3; 506 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B3;
505 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B4; 507 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B4;
506 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B5; 508 nonstd::unique_ptr<CJBig2_HuffmanTable> Table_B5;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 716 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
715 if (!findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i])) 717 if (!findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]))
716 return JBIG2_ERROR_FATAL; 718 return JBIG2_ERROR_FATAL;
717 } 719 }
718 720
719 pTRD->SBNUMSYMS = 0; 721 pTRD->SBNUMSYMS = 0;
720 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 722 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
721 CJBig2_Segment* pSeg = 723 CJBig2_Segment* pSeg =
722 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 724 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
723 if (pSeg->m_cFlags.s.type == 0) { 725 if (pSeg->m_cFlags.s.type == 0) {
724 pTRD->SBNUMSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; 726 pTRD->SBNUMSYMS += pSeg->m_Result.sd->NumImages();
725 } 727 }
726 } 728 }
727 729
728 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> SBSYMS; 730 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> SBSYMS;
Tom Sepez 2015/10/07 19:20:01 should this and pTURD->SBSYMS be list<>s as well?
Lei Zhang 2015/10/08 04:52:04 No, |dict| below owns the images. |SBSYMS| does no
729 if (pTRD->SBNUMSYMS > 0) { 731 if (pTRD->SBNUMSYMS > 0) {
730 SBSYMS.reset(FX_Alloc(CJBig2_Image*, pTRD->SBNUMSYMS)); 732 SBSYMS.reset(FX_Alloc(CJBig2_Image*, pTRD->SBNUMSYMS));
731 dwTemp = 0; 733 dwTemp = 0;
732 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 734 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
733 CJBig2_Segment* pSeg = 735 CJBig2_Segment* pSeg =
734 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 736 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
735 if (pSeg->m_cFlags.s.type == 0) { 737 if (pSeg->m_cFlags.s.type == 0) {
736 JBIG2_memcpy(SBSYMS.get() + dwTemp, pSeg->m_Result.sd->SDEXSYMS, 738 const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd;
737 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); 739 for (size_t j = 0; j < dict.NumImages(); ++j)
738 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; 740 SBSYMS.get()[dwTemp + j] = dict.GetImage(j);
741 dwTemp += dict.NumImages();
739 } 742 }
740 } 743 }
741 pTRD->SBSYMS = SBSYMS.get(); 744 pTRD->SBSYMS = SBSYMS.get();
742 } else { 745 } else {
743 pTRD->SBSYMS = NULL; 746 pTRD->SBSYMS = NULL;
744 } 747 }
745 748
746 nonstd::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES; 749 nonstd::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES;
747 if (pTRD->SBHUFF == 1) { 750 if (pTRD->SBHUFF == 1) {
748 SBSYMCODES.reset( 751 SBSYMCODES.reset(
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 SBSYMCODES[CURTEMP].code = CURCODE; 1430 SBSYMCODES[CURTEMP].code = CURCODE;
1428 CURCODE = CURCODE + 1; 1431 CURCODE = CURCODE + 1;
1429 } 1432 }
1430 CURTEMP = CURTEMP + 1; 1433 CURTEMP = CURTEMP + 1;
1431 } 1434 }
1432 CURLEN = CURLEN + 1; 1435 CURLEN = CURLEN + 1;
1433 } 1436 }
1434 FX_Free(LENCOUNT); 1437 FX_Free(LENCOUNT);
1435 FX_Free(FIRSTCODE); 1438 FX_Free(FIRSTCODE);
1436 } 1439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698