| 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 "JBig2_TrdProc.h" | 7 #include "JBig2_TrdProc.h" |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "JBig2_ArithDecoder.h" | 11 #include "JBig2_ArithDecoder.h" |
| 10 #include "JBig2_ArithIntDecoder.h" | 12 #include "JBig2_ArithIntDecoder.h" |
| 11 #include "JBig2_GrrdProc.h" | 13 #include "JBig2_GrrdProc.h" |
| 12 #include "JBig2_HuffmanDecoder.h" | 14 #include "JBig2_HuffmanDecoder.h" |
| 13 #include "third_party/base/nonstd_unique_ptr.h" | |
| 14 | 15 |
| 15 CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, | 16 CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, |
| 16 JBig2ArithCtx* grContext) { | 17 JBig2ArithCtx* grContext) { |
| 17 int32_t STRIPT, FIRSTS; | 18 int32_t STRIPT, FIRSTS; |
| 18 FX_DWORD NINSTANCES; | 19 FX_DWORD NINSTANCES; |
| 19 int32_t DT, DFS, CURS; | 20 int32_t DT, DFS, CURS; |
| 20 int32_t SI, TI; | 21 int32_t SI, TI; |
| 21 CJBig2_Image* IBI; | 22 CJBig2_Image* IBI; |
| 22 FX_DWORD WI, HI; | 23 FX_DWORD WI, HI; |
| 23 int32_t IDS; | 24 int32_t IDS; |
| 24 FX_BOOL RI; | 25 FX_BOOL RI; |
| 25 int32_t RDWI, RDHI, RDXI, RDYI; | 26 int32_t RDWI, RDHI, RDXI, RDYI; |
| 26 CJBig2_Image* IBOI; | 27 CJBig2_Image* IBOI; |
| 27 FX_DWORD WOI, HOI; | 28 FX_DWORD WOI, HOI; |
| 28 FX_BOOL bFirst; | 29 FX_BOOL bFirst; |
| 29 FX_DWORD nTmp; | 30 FX_DWORD nTmp; |
| 30 int32_t nVal, nBits; | 31 int32_t nVal, nBits; |
| 31 nonstd::unique_ptr<CJBig2_HuffmanDecoder> pHuffmanDecoder( | 32 std::unique_ptr<CJBig2_HuffmanDecoder> pHuffmanDecoder( |
| 32 new CJBig2_HuffmanDecoder(pStream)); | 33 new CJBig2_HuffmanDecoder(pStream)); |
| 33 nonstd::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); | 34 std::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); |
| 34 SBREG->fill(SBDEFPIXEL); | 35 SBREG->fill(SBDEFPIXEL); |
| 35 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) | 36 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) |
| 36 return nullptr; | 37 return nullptr; |
| 37 | 38 |
| 38 STRIPT *= SBSTRIPS; | 39 STRIPT *= SBSTRIPS; |
| 39 STRIPT = -STRIPT; | 40 STRIPT = -STRIPT; |
| 40 FIRSTS = 0; | 41 FIRSTS = 0; |
| 41 NINSTANCES = 0; | 42 NINSTANCES = 0; |
| 42 while (NINSTANCES < SBNUMINSTANCES) { | 43 while (NINSTANCES < SBNUMINSTANCES) { |
| 43 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &DT) != 0) | 44 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &DT) != 0) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 nTmp = pStream->getOffset(); | 117 nTmp = pStream->getOffset(); |
| 117 IBOI = SBSYMS[IDI]; | 118 IBOI = SBSYMS[IDI]; |
| 118 if (!IBOI) | 119 if (!IBOI) |
| 119 return nullptr; | 120 return nullptr; |
| 120 | 121 |
| 121 WOI = IBOI->m_nWidth; | 122 WOI = IBOI->m_nWidth; |
| 122 HOI = IBOI->m_nHeight; | 123 HOI = IBOI->m_nHeight; |
| 123 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) | 124 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) |
| 124 return nullptr; | 125 return nullptr; |
| 125 | 126 |
| 126 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); | 127 std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); |
| 127 pGRRD->GRW = WOI + RDWI; | 128 pGRRD->GRW = WOI + RDWI; |
| 128 pGRRD->GRH = HOI + RDHI; | 129 pGRRD->GRH = HOI + RDHI; |
| 129 pGRRD->GRTEMPLATE = SBRTEMPLATE; | 130 pGRRD->GRTEMPLATE = SBRTEMPLATE; |
| 130 pGRRD->GRREFERENCE = IBOI; | 131 pGRRD->GRREFERENCE = IBOI; |
| 131 pGRRD->GRREFERENCEDX = (RDWI >> 2) + RDXI; | 132 pGRRD->GRREFERENCEDX = (RDWI >> 2) + RDXI; |
| 132 pGRRD->GRREFERENCEDY = (RDHI >> 2) + RDYI; | 133 pGRRD->GRREFERENCEDY = (RDHI >> 2) + RDYI; |
| 133 pGRRD->TPGRON = 0; | 134 pGRRD->TPGRON = 0; |
| 134 pGRRD->GRAT[0] = SBRAT[0]; | 135 pGRRD->GRAT[0] = SBRAT[0]; |
| 135 pGRRD->GRAT[1] = SBRAT[1]; | 136 pGRRD->GRAT[1] = SBRAT[1]; |
| 136 pGRRD->GRAT[2] = SBRAT[2]; | 137 pGRRD->GRAT[2] = SBRAT[2]; |
| 137 pGRRD->GRAT[3] = SBRAT[3]; | 138 pGRRD->GRAT[3] = SBRAT[3]; |
| 138 | 139 |
| 139 { | 140 { |
| 140 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 141 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
| 141 new CJBig2_ArithDecoder(pStream)); | 142 new CJBig2_ArithDecoder(pStream)); |
| 142 IBI = pGRRD->decode(pArithDecoder.get(), grContext); | 143 IBI = pGRRD->decode(pArithDecoder.get(), grContext); |
| 143 if (!IBI) | 144 if (!IBI) |
| 144 return nullptr; | 145 return nullptr; |
| 145 } | 146 } |
| 146 | 147 |
| 147 pStream->alignByte(); | 148 pStream->alignByte(); |
| 148 pStream->offset(2); | 149 pStream->offset(2); |
| 149 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { | 150 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { |
| 150 delete IBI; | 151 delete IBI; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 IADS = new CJBig2_ArithIntDecoder(); | 249 IADS = new CJBig2_ArithIntDecoder(); |
| 249 IAIT = new CJBig2_ArithIntDecoder(); | 250 IAIT = new CJBig2_ArithIntDecoder(); |
| 250 IARI = new CJBig2_ArithIntDecoder(); | 251 IARI = new CJBig2_ArithIntDecoder(); |
| 251 IARDW = new CJBig2_ArithIntDecoder(); | 252 IARDW = new CJBig2_ArithIntDecoder(); |
| 252 IARDH = new CJBig2_ArithIntDecoder(); | 253 IARDH = new CJBig2_ArithIntDecoder(); |
| 253 IARDX = new CJBig2_ArithIntDecoder(); | 254 IARDX = new CJBig2_ArithIntDecoder(); |
| 254 IARDY = new CJBig2_ArithIntDecoder(); | 255 IARDY = new CJBig2_ArithIntDecoder(); |
| 255 IAID = new CJBig2_ArithIaidDecoder(SBSYMCODELEN); | 256 IAID = new CJBig2_ArithIaidDecoder(SBSYMCODELEN); |
| 256 bRetained = FALSE; | 257 bRetained = FALSE; |
| 257 } | 258 } |
| 258 nonstd::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); | 259 std::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); |
| 259 SBREG->fill(SBDEFPIXEL); | 260 SBREG->fill(SBDEFPIXEL); |
| 260 IADT->decode(pArithDecoder, &STRIPT); | 261 IADT->decode(pArithDecoder, &STRIPT); |
| 261 STRIPT *= SBSTRIPS; | 262 STRIPT *= SBSTRIPS; |
| 262 STRIPT = -STRIPT; | 263 STRIPT = -STRIPT; |
| 263 FIRSTS = 0; | 264 FIRSTS = 0; |
| 264 NINSTANCES = 0; | 265 NINSTANCES = 0; |
| 265 while (NINSTANCES < SBNUMINSTANCES) { | 266 while (NINSTANCES < SBNUMINSTANCES) { |
| 266 IADT->decode(pArithDecoder, &DT); | 267 IADT->decode(pArithDecoder, &DT); |
| 267 DT *= SBSTRIPS; | 268 DT *= SBSTRIPS; |
| 268 STRIPT = STRIPT + DT; | 269 STRIPT = STRIPT + DT; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 IARDW->decode(pArithDecoder, &RDWI); | 306 IARDW->decode(pArithDecoder, &RDWI); |
| 306 IARDH->decode(pArithDecoder, &RDHI); | 307 IARDH->decode(pArithDecoder, &RDHI); |
| 307 IARDX->decode(pArithDecoder, &RDXI); | 308 IARDX->decode(pArithDecoder, &RDXI); |
| 308 IARDY->decode(pArithDecoder, &RDYI); | 309 IARDY->decode(pArithDecoder, &RDYI); |
| 309 IBOI = SBSYMS[IDI]; | 310 IBOI = SBSYMS[IDI]; |
| 310 WOI = IBOI->m_nWidth; | 311 WOI = IBOI->m_nWidth; |
| 311 HOI = IBOI->m_nHeight; | 312 HOI = IBOI->m_nHeight; |
| 312 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) { | 313 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) { |
| 313 goto failed; | 314 goto failed; |
| 314 } | 315 } |
| 315 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); | 316 std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); |
| 316 pGRRD->GRW = WOI + RDWI; | 317 pGRRD->GRW = WOI + RDWI; |
| 317 pGRRD->GRH = HOI + RDHI; | 318 pGRRD->GRH = HOI + RDHI; |
| 318 pGRRD->GRTEMPLATE = SBRTEMPLATE; | 319 pGRRD->GRTEMPLATE = SBRTEMPLATE; |
| 319 pGRRD->GRREFERENCE = IBOI; | 320 pGRRD->GRREFERENCE = IBOI; |
| 320 pGRRD->GRREFERENCEDX = (RDWI >> 1) + RDXI; | 321 pGRRD->GRREFERENCEDX = (RDWI >> 1) + RDXI; |
| 321 pGRRD->GRREFERENCEDY = (RDHI >> 1) + RDYI; | 322 pGRRD->GRREFERENCEDY = (RDHI >> 1) + RDYI; |
| 322 pGRRD->TPGRON = 0; | 323 pGRRD->TPGRON = 0; |
| 323 pGRRD->GRAT[0] = SBRAT[0]; | 324 pGRRD->GRAT[0] = SBRAT[0]; |
| 324 pGRRD->GRAT[1] = SBRAT[1]; | 325 pGRRD->GRAT[1] = SBRAT[1]; |
| 325 pGRRD->GRAT[2] = SBRAT[2]; | 326 pGRRD->GRAT[2] = SBRAT[2]; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 delete IAIT; | 404 delete IAIT; |
| 404 delete IARI; | 405 delete IARI; |
| 405 delete IARDW; | 406 delete IARDW; |
| 406 delete IARDH; | 407 delete IARDH; |
| 407 delete IARDX; | 408 delete IARDX; |
| 408 delete IARDY; | 409 delete IARDY; |
| 409 delete IAID; | 410 delete IAID; |
| 410 } | 411 } |
| 411 return nullptr; | 412 return nullptr; |
| 412 } | 413 } |
| OLD | NEW |