| OLD | NEW |
| 1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 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_SddProc.h" | 7 #include "core/src/fxcodec/jbig2/JBig2_SddProc.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "core/include/fxcrt/fx_basic.h" | 11 #include "core/include/fxcrt/fx_basic.h" |
| 12 #include "core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.h" | 12 #include "core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.h" |
| 13 #include "core/src/fxcodec/jbig2/JBig2_GrdProc.h" | 13 #include "core/src/fxcodec/jbig2/JBig2_GrdProc.h" |
| 14 #include "core/src/fxcodec/jbig2/JBig2_GrrdProc.h" | 14 #include "core/src/fxcodec/jbig2/JBig2_GrrdProc.h" |
| 15 #include "core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h" | 15 #include "core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h" |
| 16 #include "core/src/fxcodec/jbig2/JBig2_HuffmanTable.h" | 16 #include "core/src/fxcodec/jbig2/JBig2_HuffmanTable.h" |
| 17 #include "core/src/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h" | 17 #include "core/src/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h" |
| 18 #include "core/src/fxcodec/jbig2/JBig2_SymbolDict.h" | 18 #include "core/src/fxcodec/jbig2/JBig2_SymbolDict.h" |
| 19 #include "core/src/fxcodec/jbig2/JBig2_TrdProc.h" | 19 #include "core/src/fxcodec/jbig2/JBig2_TrdProc.h" |
| 20 #include "third_party/base/nonstd_unique_ptr.h" | 20 #include "third_party/base/nonstd_unique_ptr.h" |
| 21 #include "third_party/base/stl_util.h" | |
| 22 | |
| 23 using pdfium::vector_as_array; | |
| 24 | 21 |
| 25 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( | 22 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( |
| 26 CJBig2_ArithDecoder* pArithDecoder, | 23 CJBig2_ArithDecoder* pArithDecoder, |
| 27 std::vector<JBig2ArithCtx>* gbContext, | 24 std::vector<JBig2ArithCtx>* gbContext, |
| 28 std::vector<JBig2ArithCtx>* grContext) { | 25 std::vector<JBig2ArithCtx>* grContext) { |
| 29 CJBig2_Image** SDNEWSYMS; | 26 CJBig2_Image** SDNEWSYMS; |
| 30 FX_DWORD HCHEIGHT, NSYMSDECODED; | 27 FX_DWORD HCHEIGHT, NSYMSDECODED; |
| 31 int32_t HCDH; | 28 int32_t HCDH; |
| 32 FX_DWORD SYMWIDTH, TOTWIDTH; | 29 FX_DWORD SYMWIDTH, TOTWIDTH; |
| 33 int32_t DW; | 30 int32_t DW; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 pGRD->TPGDON = 0; | 100 pGRD->TPGDON = 0; |
| 104 pGRD->USESKIP = 0; | 101 pGRD->USESKIP = 0; |
| 105 pGRD->GBAT[0] = SDAT[0]; | 102 pGRD->GBAT[0] = SDAT[0]; |
| 106 pGRD->GBAT[1] = SDAT[1]; | 103 pGRD->GBAT[1] = SDAT[1]; |
| 107 pGRD->GBAT[2] = SDAT[2]; | 104 pGRD->GBAT[2] = SDAT[2]; |
| 108 pGRD->GBAT[3] = SDAT[3]; | 105 pGRD->GBAT[3] = SDAT[3]; |
| 109 pGRD->GBAT[4] = SDAT[4]; | 106 pGRD->GBAT[4] = SDAT[4]; |
| 110 pGRD->GBAT[5] = SDAT[5]; | 107 pGRD->GBAT[5] = SDAT[5]; |
| 111 pGRD->GBAT[6] = SDAT[6]; | 108 pGRD->GBAT[6] = SDAT[6]; |
| 112 pGRD->GBAT[7] = SDAT[7]; | 109 pGRD->GBAT[7] = SDAT[7]; |
| 113 BS = pGRD->decode_Arith(pArithDecoder, vector_as_array(gbContext)); | 110 BS = pGRD->decode_Arith(pArithDecoder, gbContext->data()); |
| 114 if (!BS) { | 111 if (!BS) { |
| 115 goto failed; | 112 goto failed; |
| 116 } | 113 } |
| 117 } else { | 114 } else { |
| 118 IAAI->decode(pArithDecoder, (int*)&REFAGGNINST); | 115 IAAI->decode(pArithDecoder, (int*)&REFAGGNINST); |
| 119 if (REFAGGNINST > 1) { | 116 if (REFAGGNINST > 1) { |
| 120 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc()); | 117 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc()); |
| 121 pDecoder->SBHUFF = SDHUFF; | 118 pDecoder->SBHUFF = SDHUFF; |
| 122 pDecoder->SBREFINE = 1; | 119 pDecoder->SBREFINE = 1; |
| 123 pDecoder->SBW = SYMWIDTH; | 120 pDecoder->SBW = SYMWIDTH; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 ids.IADT = IADT.get(); | 188 ids.IADT = IADT.get(); |
| 192 ids.IAFS = IAFS.get(); | 189 ids.IAFS = IAFS.get(); |
| 193 ids.IADS = IADS.get(); | 190 ids.IADS = IADS.get(); |
| 194 ids.IAIT = IAIT.get(); | 191 ids.IAIT = IAIT.get(); |
| 195 ids.IARI = IARI.get(); | 192 ids.IARI = IARI.get(); |
| 196 ids.IARDW = IARDW.get(); | 193 ids.IARDW = IARDW.get(); |
| 197 ids.IARDH = IARDH.get(); | 194 ids.IARDH = IARDH.get(); |
| 198 ids.IARDX = IARDX.get(); | 195 ids.IARDX = IARDX.get(); |
| 199 ids.IARDY = IARDY.get(); | 196 ids.IARDY = IARDY.get(); |
| 200 ids.IAID = IAID.get(); | 197 ids.IAID = IAID.get(); |
| 201 BS = pDecoder->decode_Arith(pArithDecoder, vector_as_array(grContext), | 198 BS = pDecoder->decode_Arith(pArithDecoder, grContext->data(), &ids); |
| 202 &ids); | |
| 203 if (!BS) { | 199 if (!BS) { |
| 204 FX_Free(SBSYMS); | 200 FX_Free(SBSYMS); |
| 205 goto failed; | 201 goto failed; |
| 206 } | 202 } |
| 207 FX_Free(SBSYMS); | 203 FX_Free(SBSYMS); |
| 208 } else if (REFAGGNINST == 1) { | 204 } else if (REFAGGNINST == 1) { |
| 209 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; | 205 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; |
| 210 FX_DWORD IDI; | 206 FX_DWORD IDI; |
| 211 IAID->decode(pArithDecoder, &IDI); | 207 IAID->decode(pArithDecoder, &IDI); |
| 212 IARDX->decode(pArithDecoder, &RDXI); | 208 IARDX->decode(pArithDecoder, &RDXI); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 227 pGRRD->GRH = HCHEIGHT; | 223 pGRRD->GRH = HCHEIGHT; |
| 228 pGRRD->GRTEMPLATE = SDRTEMPLATE; | 224 pGRRD->GRTEMPLATE = SDRTEMPLATE; |
| 229 pGRRD->GRREFERENCE = SBSYMS[IDI]; | 225 pGRRD->GRREFERENCE = SBSYMS[IDI]; |
| 230 pGRRD->GRREFERENCEDX = RDXI; | 226 pGRRD->GRREFERENCEDX = RDXI; |
| 231 pGRRD->GRREFERENCEDY = RDYI; | 227 pGRRD->GRREFERENCEDY = RDYI; |
| 232 pGRRD->TPGRON = 0; | 228 pGRRD->TPGRON = 0; |
| 233 pGRRD->GRAT[0] = SDRAT[0]; | 229 pGRRD->GRAT[0] = SDRAT[0]; |
| 234 pGRRD->GRAT[1] = SDRAT[1]; | 230 pGRRD->GRAT[1] = SDRAT[1]; |
| 235 pGRRD->GRAT[2] = SDRAT[2]; | 231 pGRRD->GRAT[2] = SDRAT[2]; |
| 236 pGRRD->GRAT[3] = SDRAT[3]; | 232 pGRRD->GRAT[3] = SDRAT[3]; |
| 237 BS = pGRRD->decode(pArithDecoder, vector_as_array(grContext)); | 233 BS = pGRRD->decode(pArithDecoder, grContext->data()); |
| 238 if (!BS) { | 234 if (!BS) { |
| 239 FX_Free(SBSYMS); | 235 FX_Free(SBSYMS); |
| 240 goto failed; | 236 goto failed; |
| 241 } | 237 } |
| 242 FX_Free(SBSYMS); | 238 FX_Free(SBSYMS); |
| 243 } | 239 } |
| 244 } | 240 } |
| 245 SDNEWSYMS[NSYMSDECODED] = BS; | 241 SDNEWSYMS[NSYMSDECODED] = BS; |
| 246 BS = nullptr; | 242 BS = nullptr; |
| 247 NSYMSDECODED = NSYMSDECODED + 1; | 243 NSYMSDECODED = NSYMSDECODED + 1; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 pDecoder->SBHUFFRDW = SBHUFFRDW.get(); | 437 pDecoder->SBHUFFRDW = SBHUFFRDW.get(); |
| 442 pDecoder->SBHUFFRDH = SBHUFFRDH.get(); | 438 pDecoder->SBHUFFRDH = SBHUFFRDH.get(); |
| 443 pDecoder->SBHUFFRDX = SBHUFFRDX.get(); | 439 pDecoder->SBHUFFRDX = SBHUFFRDX.get(); |
| 444 pDecoder->SBHUFFRDY = SBHUFFRDY.get(); | 440 pDecoder->SBHUFFRDY = SBHUFFRDY.get(); |
| 445 pDecoder->SBHUFFRSIZE = SBHUFFRSIZE.get(); | 441 pDecoder->SBHUFFRSIZE = SBHUFFRSIZE.get(); |
| 446 pDecoder->SBRTEMPLATE = SDRTEMPLATE; | 442 pDecoder->SBRTEMPLATE = SDRTEMPLATE; |
| 447 pDecoder->SBRAT[0] = SDRAT[0]; | 443 pDecoder->SBRAT[0] = SDRAT[0]; |
| 448 pDecoder->SBRAT[1] = SDRAT[1]; | 444 pDecoder->SBRAT[1] = SDRAT[1]; |
| 449 pDecoder->SBRAT[2] = SDRAT[2]; | 445 pDecoder->SBRAT[2] = SDRAT[2]; |
| 450 pDecoder->SBRAT[3] = SDRAT[3]; | 446 pDecoder->SBRAT[3] = SDRAT[3]; |
| 451 BS = pDecoder->decode_Huffman(pStream, vector_as_array(grContext)); | 447 BS = pDecoder->decode_Huffman(pStream, grContext->data()); |
| 452 if (!BS) { | 448 if (!BS) { |
| 453 FX_Free(SBSYMCODES); | 449 FX_Free(SBSYMCODES); |
| 454 FX_Free(SBSYMS); | 450 FX_Free(SBSYMS); |
| 455 goto failed; | 451 goto failed; |
| 456 } | 452 } |
| 457 FX_Free(SBSYMCODES); | 453 FX_Free(SBSYMCODES); |
| 458 FX_Free(SBSYMS); | 454 FX_Free(SBSYMS); |
| 459 } else if (REFAGGNINST == 1) { | 455 } else if (REFAGGNINST == 1) { |
| 460 SBNUMSYMS = SDNUMINSYMS + SDNUMNEWSYMS; | 456 SBNUMSYMS = SDNUMINSYMS + SDNUMNEWSYMS; |
| 461 nTmp = 1; | 457 nTmp = 1; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 pGRRD->GRREFERENCE = SBSYMS[IDI]; | 509 pGRRD->GRREFERENCE = SBSYMS[IDI]; |
| 514 pGRRD->GRREFERENCEDX = RDXI; | 510 pGRRD->GRREFERENCEDX = RDXI; |
| 515 pGRRD->GRREFERENCEDY = RDYI; | 511 pGRRD->GRREFERENCEDY = RDYI; |
| 516 pGRRD->TPGRON = 0; | 512 pGRRD->TPGRON = 0; |
| 517 pGRRD->GRAT[0] = SDRAT[0]; | 513 pGRRD->GRAT[0] = SDRAT[0]; |
| 518 pGRRD->GRAT[1] = SDRAT[1]; | 514 pGRRD->GRAT[1] = SDRAT[1]; |
| 519 pGRRD->GRAT[2] = SDRAT[2]; | 515 pGRRD->GRAT[2] = SDRAT[2]; |
| 520 pGRRD->GRAT[3] = SDRAT[3]; | 516 pGRRD->GRAT[3] = SDRAT[3]; |
| 521 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 517 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
| 522 new CJBig2_ArithDecoder(pStream)); | 518 new CJBig2_ArithDecoder(pStream)); |
| 523 BS = pGRRD->decode(pArithDecoder.get(), vector_as_array(grContext)); | 519 BS = pGRRD->decode(pArithDecoder.get(), grContext->data()); |
| 524 if (!BS) { | 520 if (!BS) { |
| 525 FX_Free(SBSYMS); | 521 FX_Free(SBSYMS); |
| 526 goto failed; | 522 goto failed; |
| 527 } | 523 } |
| 528 pStream->alignByte(); | 524 pStream->alignByte(); |
| 529 pStream->offset(2); | 525 pStream->offset(2); |
| 530 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { | 526 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { |
| 531 delete BS; | 527 delete BS; |
| 532 FX_Free(SBSYMS); | 528 FX_Free(SBSYMS); |
| 533 goto failed; | 529 goto failed; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 failed: | 621 failed: |
| 626 for (I = 0; I < NSYMSDECODED; I++) { | 622 for (I = 0; I < NSYMSDECODED; I++) { |
| 627 delete SDNEWSYMS[I]; | 623 delete SDNEWSYMS[I]; |
| 628 } | 624 } |
| 629 FX_Free(SDNEWSYMS); | 625 FX_Free(SDNEWSYMS); |
| 630 if (SDREFAGG == 0) { | 626 if (SDREFAGG == 0) { |
| 631 FX_Free(SDNEWSYMWIDTHS); | 627 FX_Free(SDNEWSYMWIDTHS); |
| 632 } | 628 } |
| 633 return nullptr; | 629 return nullptr; |
| 634 } | 630 } |
| OLD | NEW |