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

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

Issue 2450393004: Change some ints to bools in JBIG2 code. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | core/fxcodec/jbig2/JBig2_GrrdProc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 12 matching lines...) Expand all
23 #include "core/fxcodec/jbig2/JBig2_SddProc.h" 23 #include "core/fxcodec/jbig2/JBig2_SddProc.h"
24 #include "core/fxcodec/jbig2/JBig2_TrdProc.h" 24 #include "core/fxcodec/jbig2/JBig2_TrdProc.h"
25 #include "third_party/base/stl_util.h" 25 #include "third_party/base/stl_util.h"
26 26
27 namespace { 27 namespace {
28 28
29 size_t GetHuffContextSize(uint8_t val) { 29 size_t GetHuffContextSize(uint8_t val) {
30 return val == 0 ? 65536 : val == 1 ? 8192 : 1024; 30 return val == 0 ? 65536 : val == 1 ? 8192 : 1024;
31 } 31 }
32 32
33 size_t GetRefAggContextSize(FX_BOOL val) { 33 size_t GetRefAggContextSize(bool val) {
34 return val ? 1024 : 8192; 34 return val ? 1024 : 8192;
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 // Implement a very small least recently used (LRU) cache. It is very 39 // Implement a very small least recently used (LRU) cache. It is very
40 // common for a JBIG2 dictionary to span multiple pages in a PDF file, 40 // common for a JBIG2 dictionary to span multiple pages in a PDF file,
41 // and we do not want to decode the same dictionary over and over 41 // and we do not want to decode the same dictionary over and over
42 // again. We key off of the memory location of the dictionary. The 42 // again. We key off of the memory location of the dictionary. The
43 // list keeps track of the freshness of entries, with freshest ones 43 // list keeps track of the freshness of entries, with freshest ones
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, 421 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
422 IFX_Pause* pPause) { 422 IFX_Pause* pPause) {
423 uint16_t wFlags; 423 uint16_t wFlags;
424 if (m_pStream->readShortInteger(&wFlags) != 0) 424 if (m_pStream->readShortInteger(&wFlags) != 0)
425 return JBIG2_ERROR_TOO_SHORT; 425 return JBIG2_ERROR_TOO_SHORT;
426 426
427 std::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc); 427 std::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc);
428 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; 428 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001;
429 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; 429 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001;
430 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; 430 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003;
431 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; 431 pSymbolDictDecoder->SDRTEMPLATE = !!((wFlags >> 12) & 0x0003);
432 uint8_t cSDHUFFDH = (wFlags >> 2) & 0x0003; 432 uint8_t cSDHUFFDH = (wFlags >> 2) & 0x0003;
433 uint8_t cSDHUFFDW = (wFlags >> 4) & 0x0003; 433 uint8_t cSDHUFFDW = (wFlags >> 4) & 0x0003;
434 uint8_t cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001; 434 uint8_t cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001;
435 uint8_t cSDHUFFAGGINST = (wFlags >> 7) & 0x0001; 435 uint8_t cSDHUFFAGGINST = (wFlags >> 7) & 0x0001;
436 if (pSymbolDictDecoder->SDHUFF == 0) { 436 if (pSymbolDictDecoder->SDHUFF == 0) {
437 const uint32_t dwTemp = (pSymbolDictDecoder->SDTEMPLATE == 0) ? 8 : 2; 437 const uint32_t dwTemp = (pSymbolDictDecoder->SDTEMPLATE == 0) ? 8 : 2;
438 for (uint32_t i = 0; i < dwTemp; ++i) { 438 for (uint32_t i = 0; i < dwTemp; ++i) {
439 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDAT[i]) != 0) 439 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDAT[i]) != 0)
440 return JBIG2_ERROR_TOO_SHORT; 440 return JBIG2_ERROR_TOO_SHORT;
441 } 441 }
442 } 442 }
443 if (pSymbolDictDecoder->SDREFAGG == 1 && 443 if (pSymbolDictDecoder->SDREFAGG == 1 && !pSymbolDictDecoder->SDRTEMPLATE) {
444 pSymbolDictDecoder->SDRTEMPLATE == 0) {
445 for (int32_t i = 0; i < 4; ++i) { 444 for (int32_t i = 0; i < 4; ++i) {
446 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDRAT[i]) != 0) 445 if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDRAT[i]) != 0)
447 return JBIG2_ERROR_TOO_SHORT; 446 return JBIG2_ERROR_TOO_SHORT;
448 } 447 }
449 } 448 }
450 if (m_pStream->readInteger(&pSymbolDictDecoder->SDNUMEXSYMS) != 0 || 449 if (m_pStream->readInteger(&pSymbolDictDecoder->SDNUMEXSYMS) != 0 ||
451 m_pStream->readInteger(&pSymbolDictDecoder->SDNUMNEWSYMS) != 0) { 450 m_pStream->readInteger(&pSymbolDictDecoder->SDNUMNEWSYMS) != 0) {
452 return JBIG2_ERROR_TOO_SHORT; 451 return JBIG2_ERROR_TOO_SHORT;
453 } 452 }
454 if (pSymbolDictDecoder->SDNUMEXSYMS > JBIG2_MAX_EXPORT_SYSMBOLS || 453 if (pSymbolDictDecoder->SDNUMEXSYMS > JBIG2_MAX_EXPORT_SYSMBOLS ||
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 uint32_t dwTemp = (wFlags >> 2) & 0x0003; 652 uint32_t dwTemp = (wFlags >> 2) & 0x0003;
654 pTRD->SBSTRIPS = 1 << dwTemp; 653 pTRD->SBSTRIPS = 1 << dwTemp;
655 pTRD->REFCORNER = (JBig2Corner)((wFlags >> 4) & 0x0003); 654 pTRD->REFCORNER = (JBig2Corner)((wFlags >> 4) & 0x0003);
656 pTRD->TRANSPOSED = (wFlags >> 6) & 0x0001; 655 pTRD->TRANSPOSED = (wFlags >> 6) & 0x0001;
657 pTRD->SBCOMBOP = (JBig2ComposeOp)((wFlags >> 7) & 0x0003); 656 pTRD->SBCOMBOP = (JBig2ComposeOp)((wFlags >> 7) & 0x0003);
658 pTRD->SBDEFPIXEL = (wFlags >> 9) & 0x0001; 657 pTRD->SBDEFPIXEL = (wFlags >> 9) & 0x0001;
659 pTRD->SBDSOFFSET = (wFlags >> 10) & 0x001f; 658 pTRD->SBDSOFFSET = (wFlags >> 10) & 0x001f;
660 if (pTRD->SBDSOFFSET >= 0x0010) { 659 if (pTRD->SBDSOFFSET >= 0x0010) {
661 pTRD->SBDSOFFSET = pTRD->SBDSOFFSET - 0x0020; 660 pTRD->SBDSOFFSET = pTRD->SBDSOFFSET - 0x0020;
662 } 661 }
663 pTRD->SBRTEMPLATE = (wFlags >> 15) & 0x0001; 662 pTRD->SBRTEMPLATE = !!((wFlags >> 15) & 0x0001);
664 663
665 uint8_t cSBHUFFFS = 0; 664 uint8_t cSBHUFFFS = 0;
666 uint8_t cSBHUFFDS = 0; 665 uint8_t cSBHUFFDS = 0;
667 uint8_t cSBHUFFDT = 0; 666 uint8_t cSBHUFFDT = 0;
668 uint8_t cSBHUFFRDW = 0; 667 uint8_t cSBHUFFRDW = 0;
669 uint8_t cSBHUFFRDH = 0; 668 uint8_t cSBHUFFRDH = 0;
670 uint8_t cSBHUFFRDX = 0; 669 uint8_t cSBHUFFRDX = 0;
671 uint8_t cSBHUFFRDY = 0; 670 uint8_t cSBHUFFRDY = 0;
672 uint8_t cSBHUFFRSIZE = 0; 671 uint8_t cSBHUFFRSIZE = 0;
673 if (pTRD->SBHUFF == 1) { 672 if (pTRD->SBHUFF == 1) {
674 if (m_pStream->readShortInteger(&wFlags) != 0) 673 if (m_pStream->readShortInteger(&wFlags) != 0)
675 return JBIG2_ERROR_TOO_SHORT; 674 return JBIG2_ERROR_TOO_SHORT;
676 675
677 cSBHUFFFS = wFlags & 0x0003; 676 cSBHUFFFS = wFlags & 0x0003;
678 cSBHUFFDS = (wFlags >> 2) & 0x0003; 677 cSBHUFFDS = (wFlags >> 2) & 0x0003;
679 cSBHUFFDT = (wFlags >> 4) & 0x0003; 678 cSBHUFFDT = (wFlags >> 4) & 0x0003;
680 cSBHUFFRDW = (wFlags >> 6) & 0x0003; 679 cSBHUFFRDW = (wFlags >> 6) & 0x0003;
681 cSBHUFFRDH = (wFlags >> 8) & 0x0003; 680 cSBHUFFRDH = (wFlags >> 8) & 0x0003;
682 cSBHUFFRDX = (wFlags >> 10) & 0x0003; 681 cSBHUFFRDX = (wFlags >> 10) & 0x0003;
683 cSBHUFFRDY = (wFlags >> 12) & 0x0003; 682 cSBHUFFRDY = (wFlags >> 12) & 0x0003;
684 cSBHUFFRSIZE = (wFlags >> 14) & 0x0001; 683 cSBHUFFRSIZE = (wFlags >> 14) & 0x0001;
685 } 684 }
686 if (pTRD->SBREFINE == 1 && pTRD->SBRTEMPLATE == 0) { 685 if (pTRD->SBREFINE == 1 && !pTRD->SBRTEMPLATE) {
687 for (int32_t i = 0; i < 4; ++i) { 686 for (int32_t i = 0; i < 4; ++i) {
688 if (m_pStream->read1Byte((uint8_t*)&pTRD->SBRAT[i]) != 0) 687 if (m_pStream->read1Byte((uint8_t*)&pTRD->SBRAT[i]) != 0)
689 return JBIG2_ERROR_TOO_SHORT; 688 return JBIG2_ERROR_TOO_SHORT;
690 } 689 }
691 } 690 }
692 if (m_pStream->readInteger(&pTRD->SBNUMINSTANCES) != 0) 691 if (m_pStream->readInteger(&pTRD->SBNUMINSTANCES) != 0)
693 return JBIG2_ERROR_TOO_SHORT; 692 return JBIG2_ERROR_TOO_SHORT;
694 693
695 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 694 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
696 if (!findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i])) 695 if (!findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]))
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { 1160 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
1162 JBig2RegionInfo ri; 1161 JBig2RegionInfo ri;
1163 uint8_t cFlags; 1162 uint8_t cFlags;
1164 if (parseRegionInfo(&ri) != JBIG2_SUCCESS || 1163 if (parseRegionInfo(&ri) != JBIG2_SUCCESS ||
1165 m_pStream->read1Byte(&cFlags) != 0) { 1164 m_pStream->read1Byte(&cFlags) != 0) {
1166 return JBIG2_ERROR_TOO_SHORT; 1165 return JBIG2_ERROR_TOO_SHORT;
1167 } 1166 }
1168 std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc); 1167 std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc);
1169 pGRRD->GRW = ri.width; 1168 pGRRD->GRW = ri.width;
1170 pGRRD->GRH = ri.height; 1169 pGRRD->GRH = ri.height;
1171 pGRRD->GRTEMPLATE = cFlags & 0x01; 1170 pGRRD->GRTEMPLATE = !!(cFlags & 0x01);
1172 pGRRD->TPGRON = (cFlags >> 1) & 0x01; 1171 pGRRD->TPGRON = (cFlags >> 1) & 0x01;
1173 if (pGRRD->GRTEMPLATE == 0) { 1172 if (!pGRRD->GRTEMPLATE) {
1174 for (int32_t i = 0; i < 4; ++i) { 1173 for (int32_t i = 0; i < 4; ++i) {
1175 if (m_pStream->read1Byte((uint8_t*)&pGRRD->GRAT[i]) != 0) 1174 if (m_pStream->read1Byte((uint8_t*)&pGRRD->GRAT[i]) != 0)
1176 return JBIG2_ERROR_TOO_SHORT; 1175 return JBIG2_ERROR_TOO_SHORT;
1177 } 1176 }
1178 } 1177 }
1179 CJBig2_Segment* pSeg = nullptr; 1178 CJBig2_Segment* pSeg = nullptr;
1180 if (pSegment->m_nReferred_to_segment_count > 0) { 1179 if (pSegment->m_nReferred_to_segment_count > 0) {
1181 int32_t i; 1180 int32_t i;
1182 for (i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) { 1181 for (i = 0; i < pSegment->m_nReferred_to_segment_count; ++i) {
1183 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[0]); 1182 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[0]);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 SBSYMCODES[CURTEMP].code = CURCODE; 1386 SBSYMCODES[CURTEMP].code = CURCODE;
1388 CURCODE = CURCODE + 1; 1387 CURCODE = CURCODE + 1;
1389 } 1388 }
1390 CURTEMP = CURTEMP + 1; 1389 CURTEMP = CURTEMP + 1;
1391 } 1390 }
1392 CURLEN = CURLEN + 1; 1391 CURLEN = CURLEN + 1;
1393 } 1392 }
1394 FX_Free(LENCOUNT); 1393 FX_Free(LENCOUNT);
1395 FX_Free(FIRSTCODE); 1394 FX_Free(FIRSTCODE);
1396 } 1395 }
OLDNEW
« no previous file with comments | « no previous file | core/fxcodec/jbig2/JBig2_GrrdProc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698