| 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 "../../../../third_party/base/nonstd_unique_ptr.h" | 9 #include "../../../../third_party/base/nonstd_unique_ptr.h" |
| 10 #include "JBig2_ArithDecoder.h" | 10 #include "JBig2_ArithDecoder.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 int32_t DT, DFS, CURS; | 219 int32_t DT, DFS, CURS; |
| 220 int32_t SI, TI; | 220 int32_t SI, TI; |
| 221 CJBig2_Image* IBI; | 221 CJBig2_Image* IBI; |
| 222 FX_DWORD WI, HI; | 222 FX_DWORD WI, HI; |
| 223 int32_t IDS; | 223 int32_t IDS; |
| 224 int RI; | 224 int RI; |
| 225 int32_t RDWI, RDHI, RDXI, RDYI; | 225 int32_t RDWI, RDHI, RDXI, RDYI; |
| 226 CJBig2_Image* IBOI; | 226 CJBig2_Image* IBOI; |
| 227 FX_DWORD WOI, HOI; | 227 FX_DWORD WOI, HOI; |
| 228 FX_BOOL bFirst; | 228 FX_BOOL bFirst; |
| 229 int32_t nRet; | |
| 230 int32_t bRetained; | 229 int32_t bRetained; |
| 231 CJBig2_ArithIntDecoder* IADT, *IAFS, *IADS, *IAIT, *IARI, *IARDW, *IARDH, | 230 CJBig2_ArithIntDecoder* IADT, *IAFS, *IADS, *IAIT, *IARI, *IARDW, *IARDH, |
| 232 *IARDX, *IARDY; | 231 *IARDX, *IARDY; |
| 233 CJBig2_ArithIaidDecoder* IAID; | 232 CJBig2_ArithIaidDecoder* IAID; |
| 234 if (pIDS) { | 233 if (pIDS) { |
| 235 IADT = pIDS->IADT; | 234 IADT = pIDS->IADT; |
| 236 IAFS = pIDS->IAFS; | 235 IAFS = pIDS->IAFS; |
| 237 IADS = pIDS->IADS; | 236 IADS = pIDS->IADS; |
| 238 IAIT = pIDS->IAIT; | 237 IAIT = pIDS->IAIT; |
| 239 IARI = pIDS->IARI; | 238 IARI = pIDS->IARI; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 251 IARI = new CJBig2_ArithIntDecoder(); | 250 IARI = new CJBig2_ArithIntDecoder(); |
| 252 IARDW = new CJBig2_ArithIntDecoder(); | 251 IARDW = new CJBig2_ArithIntDecoder(); |
| 253 IARDH = new CJBig2_ArithIntDecoder(); | 252 IARDH = new CJBig2_ArithIntDecoder(); |
| 254 IARDX = new CJBig2_ArithIntDecoder(); | 253 IARDX = new CJBig2_ArithIntDecoder(); |
| 255 IARDY = new CJBig2_ArithIntDecoder(); | 254 IARDY = new CJBig2_ArithIntDecoder(); |
| 256 IAID = new CJBig2_ArithIaidDecoder(SBSYMCODELEN); | 255 IAID = new CJBig2_ArithIaidDecoder(SBSYMCODELEN); |
| 257 bRetained = FALSE; | 256 bRetained = FALSE; |
| 258 } | 257 } |
| 259 nonstd::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); | 258 nonstd::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); |
| 260 SBREG->fill(SBDEFPIXEL); | 259 SBREG->fill(SBDEFPIXEL); |
| 261 if (!IADT->decode(pArithDecoder, &STRIPT)) { | 260 IADT->decode(pArithDecoder, &STRIPT); |
| 262 goto failed; | |
| 263 } | |
| 264 STRIPT *= SBSTRIPS; | 261 STRIPT *= SBSTRIPS; |
| 265 STRIPT = -STRIPT; | 262 STRIPT = -STRIPT; |
| 266 FIRSTS = 0; | 263 FIRSTS = 0; |
| 267 NINSTANCES = 0; | 264 NINSTANCES = 0; |
| 268 while (NINSTANCES < SBNUMINSTANCES) { | 265 while (NINSTANCES < SBNUMINSTANCES) { |
| 269 if (!IADT->decode(pArithDecoder, &DT)) { | 266 IADT->decode(pArithDecoder, &DT); |
| 270 goto failed; | |
| 271 } | |
| 272 DT *= SBSTRIPS; | 267 DT *= SBSTRIPS; |
| 273 STRIPT = STRIPT + DT; | 268 STRIPT = STRIPT + DT; |
| 274 bFirst = TRUE; | 269 bFirst = TRUE; |
| 275 for (;;) { | 270 for (;;) { |
| 276 if (bFirst) { | 271 if (bFirst) { |
| 277 if (!IAFS->decode(pArithDecoder, &DFS)) { | 272 IAFS->decode(pArithDecoder, &DFS); |
| 278 goto failed; | |
| 279 } | |
| 280 FIRSTS = FIRSTS + DFS; | 273 FIRSTS = FIRSTS + DFS; |
| 281 CURS = FIRSTS; | 274 CURS = FIRSTS; |
| 282 bFirst = FALSE; | 275 bFirst = FALSE; |
| 283 } else { | 276 } else { |
| 284 nRet = IADS->decode(pArithDecoder, &IDS); | 277 if (!IADS->decode(pArithDecoder, &IDS)) |
| 285 if (nRet == JBIG2_OOB) { | |
| 286 break; | 278 break; |
| 287 } else if (nRet != 0) { | 279 CURS = CURS + IDS + SBDSOFFSET; |
| 288 goto failed; | |
| 289 } else { | |
| 290 CURS = CURS + IDS + SBDSOFFSET; | |
| 291 } | |
| 292 } | 280 } |
| 293 if (NINSTANCES >= SBNUMINSTANCES) { | 281 if (NINSTANCES >= SBNUMINSTANCES) { |
| 294 break; | 282 break; |
| 295 } | 283 } |
| 296 int CURT = 0; | 284 int CURT = 0; |
| 297 if (SBSTRIPS != 1) { | 285 if (SBSTRIPS != 1) |
| 298 if (!IAIT->decode(pArithDecoder, &CURT)) { | 286 IAIT->decode(pArithDecoder, &CURT); |
| 299 goto failed; | 287 |
| 300 } | |
| 301 } | |
| 302 TI = STRIPT + CURT; | 288 TI = STRIPT + CURT; |
| 303 FX_DWORD IDI; | 289 FX_DWORD IDI; |
| 304 IAID->decode(pArithDecoder, &IDI); | 290 IAID->decode(pArithDecoder, &IDI); |
| 305 if (IDI >= SBNUMSYMS) { | 291 if (IDI >= SBNUMSYMS) |
| 306 goto failed; | 292 goto failed; |
| 307 } | 293 |
| 308 if (SBREFINE == 0) { | 294 if (SBREFINE == 0) |
| 309 RI = 0; | 295 RI = 0; |
| 310 } else { | 296 else |
| 311 if (!IARI->decode(pArithDecoder, &RI)) { | 297 IARI->decode(pArithDecoder, &RI); |
| 312 goto failed; | 298 |
| 313 } | 299 if (!SBSYMS[IDI]) |
| 314 } | |
| 315 if (!SBSYMS[IDI]) { | |
| 316 goto failed; | 300 goto failed; |
| 317 } | 301 |
| 318 if (RI == 0) { | 302 if (RI == 0) { |
| 319 IBI = SBSYMS[IDI]; | 303 IBI = SBSYMS[IDI]; |
| 320 } else { | 304 } else { |
| 321 if (!IARDW->decode(pArithDecoder, &RDWI) || | 305 IARDW->decode(pArithDecoder, &RDWI); |
| 322 !IARDH->decode(pArithDecoder, &RDHI) || | 306 IARDH->decode(pArithDecoder, &RDHI); |
| 323 !IARDX->decode(pArithDecoder, &RDXI) || | 307 IARDX->decode(pArithDecoder, &RDXI); |
| 324 !IARDY->decode(pArithDecoder, &RDYI)) { | 308 IARDY->decode(pArithDecoder, &RDYI); |
| 325 goto failed; | |
| 326 } | |
| 327 IBOI = SBSYMS[IDI]; | 309 IBOI = SBSYMS[IDI]; |
| 328 WOI = IBOI->m_nWidth; | 310 WOI = IBOI->m_nWidth; |
| 329 HOI = IBOI->m_nHeight; | 311 HOI = IBOI->m_nHeight; |
| 330 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) { | 312 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) { |
| 331 goto failed; | 313 goto failed; |
| 332 } | 314 } |
| 333 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); | 315 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); |
| 334 pGRRD->GRW = WOI + RDWI; | 316 pGRRD->GRW = WOI + RDWI; |
| 335 pGRRD->GRH = HOI + RDHI; | 317 pGRRD->GRH = HOI + RDHI; |
| 336 pGRRD->GRTEMPLATE = SBRTEMPLATE; | 318 pGRRD->GRTEMPLATE = SBRTEMPLATE; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 delete IAIT; | 403 delete IAIT; |
| 422 delete IARI; | 404 delete IARI; |
| 423 delete IARDW; | 405 delete IARDW; |
| 424 delete IARDH; | 406 delete IARDH; |
| 425 delete IARDX; | 407 delete IARDX; |
| 426 delete IARDY; | 408 delete IARDY; |
| 427 delete IAID; | 409 delete IAID; |
| 428 } | 410 } |
| 429 return nullptr; | 411 return nullptr; |
| 430 } | 412 } |
| OLD | NEW |