| OLD | NEW |
| 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_GeneralDecoder.h" | 7 #include "JBig2_GeneralDecoder.h" |
| 8 #include "JBig2_ArithDecoder.h" | 8 #include "JBig2_ArithDecoder.h" |
| 9 #include "JBig2_ArithIntDecoder.h" | 9 #include "JBig2_ArithIntDecoder.h" |
| 10 #include "JBig2_HuffmanDecoder.h" | 10 #include "JBig2_HuffmanDecoder.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return decode_Arith_Template2_unopt(pArithDecoder, gbContext); | 59 return decode_Arith_Template2_unopt(pArithDecoder, gbContext); |
| 60 } | 60 } |
| 61 } else { | 61 } else { |
| 62 if ((GBAT[0] == 2) && (GBAT[1] == (int8_t)-1)) { | 62 if ((GBAT[0] == 2) && (GBAT[1] == (int8_t)-1)) { |
| 63 return decode_Arith_Template3_opt3(pArithDecoder, gbContext); | 63 return decode_Arith_Template3_opt3(pArithDecoder, gbContext); |
| 64 } else { | 64 } else { |
| 65 return decode_Arith_Template3_unopt(pArithDecoder, gbContext); | 65 return decode_Arith_Template3_unopt(pArithDecoder, gbContext); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt( | |
| 70 CJBig2_ArithDecoder* pArithDecoder, | |
| 71 JBig2ArithCtx* gbContext) { | |
| 72 FX_BOOL LTP, SLTP, bVal; | |
| 73 FX_DWORD CONTEXT; | |
| 74 CJBig2_Image* GBREG; | |
| 75 FX_DWORD line1, line2, line3; | |
| 76 LTP = 0; | |
| 77 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 78 GBREG->fill(0); | |
| 79 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 80 if (TPGDON) { | |
| 81 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | |
| 82 LTP = LTP ^ SLTP; | |
| 83 } | |
| 84 if (LTP == 1) { | |
| 85 GBREG->copyLine(h, h - 1); | |
| 86 } else { | |
| 87 line1 = GBREG->getPixel(2, h - 2); | |
| 88 line1 |= GBREG->getPixel(1, h - 2) << 1; | |
| 89 line1 |= GBREG->getPixel(0, h - 2) << 2; | |
| 90 line2 = GBREG->getPixel(3, h - 1); | |
| 91 line2 |= GBREG->getPixel(2, h - 1) << 1; | |
| 92 line2 |= GBREG->getPixel(1, h - 1) << 2; | |
| 93 line2 |= GBREG->getPixel(0, h - 1) << 3; | |
| 94 line3 = 0; | |
| 95 for (FX_DWORD w = 0; w < GBW; w++) { | |
| 96 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 97 bVal = 0; | |
| 98 } else { | |
| 99 CONTEXT = line3; | |
| 100 CONTEXT |= line2 << 4; | |
| 101 CONTEXT |= line1 << 11; | |
| 102 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 103 } | |
| 104 if (bVal) { | |
| 105 GBREG->setPixel(w, h, bVal); | |
| 106 } | |
| 107 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x1f; | |
| 108 line2 = ((line2 << 1) | GBREG->getPixel(w + 4, h - 1)) & 0x7f; | |
| 109 line3 = ((line3 << 1) | bVal) & 0x0f; | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 return GBREG; | |
| 114 } | |
| 115 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt2( | |
| 116 CJBig2_ArithDecoder* pArithDecoder, | |
| 117 JBig2ArithCtx* gbContext) { | |
| 118 FX_BOOL LTP, SLTP, bVal; | |
| 119 FX_DWORD CONTEXT; | |
| 120 CJBig2_Image* GBREG; | |
| 121 FX_DWORD line1, line2; | |
| 122 uint8_t *pLine, cVal; | |
| 123 intptr_t nStride, nStride2; | |
| 124 int32_t nBits, k; | |
| 125 LTP = 0; | |
| 126 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 127 if (GBREG->m_pData == NULL) { | |
| 128 delete GBREG; | |
| 129 m_pModule->JBig2_Error( | |
| 130 "Generic region decoding procedure: Create Image Failed with width = " | |
| 131 "%d, height = %d\n", | |
| 132 GBW, GBH); | |
| 133 return NULL; | |
| 134 } | |
| 135 pLine = GBREG->m_pData; | |
| 136 nStride = GBREG->m_nStride; | |
| 137 nStride2 = nStride << 1; | |
| 138 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 139 if (TPGDON) { | |
| 140 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | |
| 141 LTP = LTP ^ SLTP; | |
| 142 } | |
| 143 if (LTP == 1) { | |
| 144 GBREG->copyLine(h, h - 1); | |
| 145 } else { | |
| 146 line1 = (h > 1) ? pLine[-nStride2] << 6 : 0; | |
| 147 line2 = (h > 0) ? pLine[-nStride] : 0; | |
| 148 CONTEXT = (line1 & 0xf800) | (line2 & 0x07f0); | |
| 149 for (FX_DWORD w = 0; w < GBW; w += 8) { | |
| 150 if (w + 8 < GBW) { | |
| 151 nBits = 8; | |
| 152 if (h > 1) { | |
| 153 line1 = (line1 << 8) | (pLine[-nStride2 + (w >> 3) + 1] << 6); | |
| 154 } | |
| 155 if (h > 0) { | |
| 156 line2 = (line2 << 8) | (pLine[-nStride + (w >> 3) + 1]); | |
| 157 } | |
| 158 } else { | |
| 159 nBits = GBW - w; | |
| 160 if (h > 1) { | |
| 161 line1 <<= 8; | |
| 162 } | |
| 163 if (h > 0) { | |
| 164 line2 <<= 8; | |
| 165 } | |
| 166 } | |
| 167 cVal = 0; | |
| 168 for (k = 0; k < nBits; k++) { | |
| 169 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 170 bVal = 0; | |
| 171 } else { | |
| 172 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 173 } | |
| 174 cVal |= bVal << (7 - k); | |
| 175 CONTEXT = ((CONTEXT & 0x7bf7) << 1) | bVal | | |
| 176 ((line1 >> (7 - k)) & 0x0800) | | |
| 177 ((line2 >> (7 - k)) & 0x0010); | |
| 178 } | |
| 179 pLine[w >> 3] = cVal; | |
| 180 } | |
| 181 } | |
| 182 pLine += nStride; | |
| 183 } | |
| 184 return GBREG; | |
| 185 } | |
| 186 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( | 69 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( |
| 187 CJBig2_ArithDecoder* pArithDecoder, | 70 CJBig2_ArithDecoder* pArithDecoder, |
| 188 JBig2ArithCtx* gbContext) { | 71 JBig2ArithCtx* gbContext) { |
| 189 FX_BOOL LTP, SLTP, bVal; | 72 FX_BOOL LTP, SLTP, bVal; |
| 190 FX_DWORD CONTEXT; | 73 FX_DWORD CONTEXT; |
| 191 CJBig2_Image* GBREG; | 74 CJBig2_Image* GBREG; |
| 192 FX_DWORD line1, line2; | 75 FX_DWORD line1, line2; |
| 193 uint8_t *pLine, *pLine1, *pLine2, cVal; | 76 uint8_t *pLine, *pLine1, *pLine2, cVal; |
| 194 int32_t nStride, nStride2, k; | 77 int32_t nStride, nStride2, k; |
| 195 int32_t nLineBytes, nBitsLeft, cc; | 78 int32_t nLineBytes, nBitsLeft, cc; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 GBREG->setPixel(w, h, bVal); | 202 GBREG->setPixel(w, h, bVal); |
| 320 } | 203 } |
| 321 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; | 204 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; |
| 322 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; | 205 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; |
| 323 line3 = ((line3 << 1) | bVal) & 0x0f; | 206 line3 = ((line3 << 1) | bVal) & 0x0f; |
| 324 } | 207 } |
| 325 } | 208 } |
| 326 } | 209 } |
| 327 return GBREG; | 210 return GBREG; |
| 328 } | 211 } |
| 329 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt( | |
| 330 CJBig2_ArithDecoder* pArithDecoder, | |
| 331 JBig2ArithCtx* gbContext) { | |
| 332 FX_BOOL LTP, SLTP, bVal; | |
| 333 FX_DWORD CONTEXT; | |
| 334 CJBig2_Image* GBREG; | |
| 335 FX_DWORD line1, line2, line3; | |
| 336 LTP = 0; | |
| 337 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 338 GBREG->fill(0); | |
| 339 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 340 if (TPGDON) { | |
| 341 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | |
| 342 LTP = LTP ^ SLTP; | |
| 343 } | |
| 344 if (LTP == 1) { | |
| 345 GBREG->copyLine(h, h - 1); | |
| 346 } else { | |
| 347 line1 = GBREG->getPixel(2, h - 2); | |
| 348 line1 |= GBREG->getPixel(1, h - 2) << 1; | |
| 349 line1 |= GBREG->getPixel(0, h - 2) << 2; | |
| 350 line2 = GBREG->getPixel(3, h - 1); | |
| 351 line2 |= GBREG->getPixel(2, h - 1) << 1; | |
| 352 line2 |= GBREG->getPixel(1, h - 1) << 2; | |
| 353 line2 |= GBREG->getPixel(0, h - 1) << 3; | |
| 354 line3 = 0; | |
| 355 for (FX_DWORD w = 0; w < GBW; w++) { | |
| 356 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 357 bVal = 0; | |
| 358 } else { | |
| 359 CONTEXT = line3; | |
| 360 CONTEXT |= line2 << 3; | |
| 361 CONTEXT |= line1 << 9; | |
| 362 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 363 } | |
| 364 if (bVal) { | |
| 365 GBREG->setPixel(w, h, bVal); | |
| 366 } | |
| 367 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x0f; | |
| 368 line2 = ((line2 << 1) | GBREG->getPixel(w + 4, h - 1)) & 0x3f; | |
| 369 line3 = ((line3 << 1) | bVal) & 0x07; | |
| 370 } | |
| 371 } | |
| 372 } | |
| 373 return GBREG; | |
| 374 } | |
| 375 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt2( | |
| 376 CJBig2_ArithDecoder* pArithDecoder, | |
| 377 JBig2ArithCtx* gbContext) { | |
| 378 FX_BOOL LTP, SLTP, bVal; | |
| 379 FX_DWORD CONTEXT; | |
| 380 CJBig2_Image* GBREG; | |
| 381 FX_DWORD line1, line2; | |
| 382 uint8_t *pLine, cVal; | |
| 383 intptr_t nStride, nStride2; | |
| 384 int32_t nBits, k; | |
| 385 LTP = 0; | |
| 386 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 387 if (GBREG->m_pData == NULL) { | |
| 388 delete GBREG; | |
| 389 m_pModule->JBig2_Error( | |
| 390 "Generic region decoding procedure: Create Image Failed with width = " | |
| 391 "%d, height = %d\n", | |
| 392 GBW, GBH); | |
| 393 return NULL; | |
| 394 } | |
| 395 pLine = GBREG->m_pData; | |
| 396 nStride = GBREG->m_nStride; | |
| 397 nStride2 = nStride << 1; | |
| 398 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 399 if (TPGDON) { | |
| 400 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | |
| 401 LTP = LTP ^ SLTP; | |
| 402 } | |
| 403 if (LTP == 1) { | |
| 404 GBREG->copyLine(h, h - 1); | |
| 405 } else { | |
| 406 line1 = (h > 1) ? pLine[-nStride2] << 4 : 0; | |
| 407 line2 = (h > 0) ? pLine[-nStride] : 0; | |
| 408 CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); | |
| 409 for (FX_DWORD w = 0; w < GBW; w += 8) { | |
| 410 if (w + 8 < GBW) { | |
| 411 nBits = 8; | |
| 412 if (h > 1) { | |
| 413 line1 = (line1 << 8) | (pLine[-nStride2 + (w >> 3) + 1] << 4); | |
| 414 } | |
| 415 if (h > 0) { | |
| 416 line2 = (line2 << 8) | (pLine[-nStride + (w >> 3) + 1]); | |
| 417 } | |
| 418 } else { | |
| 419 nBits = GBW - w; | |
| 420 if (h > 1) { | |
| 421 line1 <<= 8; | |
| 422 } | |
| 423 if (h > 0) { | |
| 424 line2 <<= 8; | |
| 425 } | |
| 426 } | |
| 427 cVal = 0; | |
| 428 for (k = 0; k < nBits; k++) { | |
| 429 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 430 bVal = 0; | |
| 431 } else { | |
| 432 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 433 } | |
| 434 cVal |= bVal << (7 - k); | |
| 435 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | | |
| 436 ((line1 >> (7 - k)) & 0x0200) | | |
| 437 ((line2 >> (8 - k)) & 0x0008); | |
| 438 } | |
| 439 pLine[w >> 3] = cVal; | |
| 440 } | |
| 441 } | |
| 442 pLine += nStride; | |
| 443 } | |
| 444 return GBREG; | |
| 445 } | |
| 446 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( | 212 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( |
| 447 CJBig2_ArithDecoder* pArithDecoder, | 213 CJBig2_ArithDecoder* pArithDecoder, |
| 448 JBig2ArithCtx* gbContext) { | 214 JBig2ArithCtx* gbContext) { |
| 449 FX_BOOL LTP, SLTP, bVal; | 215 FX_BOOL LTP, SLTP, bVal; |
| 450 FX_DWORD CONTEXT; | 216 FX_DWORD CONTEXT; |
| 451 CJBig2_Image* GBREG; | 217 CJBig2_Image* GBREG; |
| 452 FX_DWORD line1, line2; | 218 FX_DWORD line1, line2; |
| 453 uint8_t *pLine, *pLine1, *pLine2, cVal; | 219 uint8_t *pLine, *pLine1, *pLine2, cVal; |
| 454 int32_t nStride, nStride2, k; | 220 int32_t nStride, nStride2, k; |
| 455 int32_t nLineBytes, nBitsLeft, cc; | 221 int32_t nLineBytes, nBitsLeft, cc; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 GBREG->setPixel(w, h, bVal); | 342 GBREG->setPixel(w, h, bVal); |
| 577 } | 343 } |
| 578 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x0f; | 344 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x0f; |
| 579 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; | 345 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; |
| 580 line3 = ((line3 << 1) | bVal) & 0x07; | 346 line3 = ((line3 << 1) | bVal) & 0x07; |
| 581 } | 347 } |
| 582 } | 348 } |
| 583 } | 349 } |
| 584 return GBREG; | 350 return GBREG; |
| 585 } | 351 } |
| 586 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt( | |
| 587 CJBig2_ArithDecoder* pArithDecoder, | |
| 588 JBig2ArithCtx* gbContext) { | |
| 589 FX_BOOL LTP, SLTP, bVal; | |
| 590 FX_DWORD CONTEXT; | |
| 591 CJBig2_Image* GBREG; | |
| 592 FX_DWORD line1, line2, line3; | |
| 593 LTP = 0; | |
| 594 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 595 GBREG->fill(0); | |
| 596 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 597 if (TPGDON) { | |
| 598 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | |
| 599 LTP = LTP ^ SLTP; | |
| 600 } | |
| 601 if (LTP == 1) { | |
| 602 GBREG->copyLine(h, h - 1); | |
| 603 } else { | |
| 604 line1 = GBREG->getPixel(1, h - 2); | |
| 605 line1 |= GBREG->getPixel(0, h - 2) << 1; | |
| 606 line2 = GBREG->getPixel(2, h - 1); | |
| 607 line2 |= GBREG->getPixel(1, h - 1) << 1; | |
| 608 line2 |= GBREG->getPixel(0, h - 1) << 2; | |
| 609 line3 = 0; | |
| 610 for (FX_DWORD w = 0; w < GBW; w++) { | |
| 611 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 612 bVal = 0; | |
| 613 } else { | |
| 614 CONTEXT = line3; | |
| 615 CONTEXT |= line2 << 2; | |
| 616 CONTEXT |= line1 << 7; | |
| 617 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 618 } | |
| 619 if (bVal) { | |
| 620 GBREG->setPixel(w, h, bVal); | |
| 621 } | |
| 622 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; | |
| 623 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; | |
| 624 line3 = ((line3 << 1) | bVal) & 0x03; | |
| 625 } | |
| 626 } | |
| 627 } | |
| 628 return GBREG; | |
| 629 } | |
| 630 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt2( | |
| 631 CJBig2_ArithDecoder* pArithDecoder, | |
| 632 JBig2ArithCtx* gbContext) { | |
| 633 FX_BOOL LTP, SLTP, bVal; | |
| 634 FX_DWORD CONTEXT; | |
| 635 CJBig2_Image* GBREG; | |
| 636 FX_DWORD line1, line2; | |
| 637 uint8_t *pLine, cVal; | |
| 638 intptr_t nStride, nStride2; | |
| 639 int32_t nBits, k; | |
| 640 LTP = 0; | |
| 641 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 642 if (GBREG->m_pData == NULL) { | |
| 643 delete GBREG; | |
| 644 m_pModule->JBig2_Error( | |
| 645 "Generic region decoding procedure: Create Image Failed with width = " | |
| 646 "%d, height = %d\n", | |
| 647 GBW, GBH); | |
| 648 return NULL; | |
| 649 } | |
| 650 pLine = GBREG->m_pData; | |
| 651 nStride = GBREG->m_nStride; | |
| 652 nStride2 = nStride << 1; | |
| 653 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 654 if (TPGDON) { | |
| 655 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | |
| 656 LTP = LTP ^ SLTP; | |
| 657 } | |
| 658 if (LTP == 1) { | |
| 659 GBREG->copyLine(h, h - 1); | |
| 660 } else { | |
| 661 line1 = (h > 1) ? pLine[-nStride2] << 1 : 0; | |
| 662 line2 = (h > 0) ? pLine[-nStride] : 0; | |
| 663 CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); | |
| 664 for (FX_DWORD w = 0; w < GBW; w += 8) { | |
| 665 if (w + 8 < GBW) { | |
| 666 nBits = 8; | |
| 667 if (h > 1) { | |
| 668 line1 = (line1 << 8) | (pLine[-nStride2 + (w >> 3) + 1] << 1); | |
| 669 } | |
| 670 if (h > 0) { | |
| 671 line2 = (line2 << 8) | (pLine[-nStride + (w >> 3) + 1]); | |
| 672 } | |
| 673 } else { | |
| 674 nBits = GBW - w; | |
| 675 if (h > 1) { | |
| 676 line1 <<= 8; | |
| 677 } | |
| 678 if (h > 0) { | |
| 679 line2 <<= 8; | |
| 680 } | |
| 681 } | |
| 682 cVal = 0; | |
| 683 for (k = 0; k < nBits; k++) { | |
| 684 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 685 bVal = 0; | |
| 686 } else { | |
| 687 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 688 } | |
| 689 cVal |= bVal << (7 - k); | |
| 690 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | |
| 691 ((line1 >> (7 - k)) & 0x0080) | | |
| 692 ((line2 >> (10 - k)) & 0x0004); | |
| 693 } | |
| 694 pLine[w >> 3] = cVal; | |
| 695 } | |
| 696 } | |
| 697 pLine += nStride; | |
| 698 } | |
| 699 return GBREG; | |
| 700 } | |
| 701 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( | 352 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( |
| 702 CJBig2_ArithDecoder* pArithDecoder, | 353 CJBig2_ArithDecoder* pArithDecoder, |
| 703 JBig2ArithCtx* gbContext) { | 354 JBig2ArithCtx* gbContext) { |
| 704 FX_BOOL LTP, SLTP, bVal; | 355 FX_BOOL LTP, SLTP, bVal; |
| 705 FX_DWORD CONTEXT; | 356 FX_DWORD CONTEXT; |
| 706 CJBig2_Image* GBREG; | 357 CJBig2_Image* GBREG; |
| 707 FX_DWORD line1, line2; | 358 FX_DWORD line1, line2; |
| 708 uint8_t *pLine, *pLine1, *pLine2, cVal; | 359 uint8_t *pLine, *pLine1, *pLine2, cVal; |
| 709 int32_t nStride, nStride2, k; | 360 int32_t nStride, nStride2, k; |
| 710 int32_t nLineBytes, nBitsLeft, cc; | 361 int32_t nLineBytes, nBitsLeft, cc; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 GBREG->setPixel(w, h, bVal); | 480 GBREG->setPixel(w, h, bVal); |
| 830 } | 481 } |
| 831 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; | 482 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; |
| 832 line2 = ((line2 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x0f; | 483 line2 = ((line2 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x0f; |
| 833 line3 = ((line3 << 1) | bVal) & 0x03; | 484 line3 = ((line3 << 1) | bVal) & 0x03; |
| 834 } | 485 } |
| 835 } | 486 } |
| 836 } | 487 } |
| 837 return GBREG; | 488 return GBREG; |
| 838 } | 489 } |
| 839 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt( | |
| 840 CJBig2_ArithDecoder* pArithDecoder, | |
| 841 JBig2ArithCtx* gbContext) { | |
| 842 FX_BOOL LTP, SLTP, bVal; | |
| 843 FX_DWORD CONTEXT; | |
| 844 CJBig2_Image* GBREG; | |
| 845 FX_DWORD line1, line2; | |
| 846 LTP = 0; | |
| 847 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 848 GBREG->fill(0); | |
| 849 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 850 if (TPGDON) { | |
| 851 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | |
| 852 LTP = LTP ^ SLTP; | |
| 853 } | |
| 854 if (LTP == 1) { | |
| 855 GBREG->copyLine(h, h - 1); | |
| 856 } else { | |
| 857 line1 = GBREG->getPixel(2, h - 1); | |
| 858 line1 |= GBREG->getPixel(1, h - 1) << 1; | |
| 859 line1 |= GBREG->getPixel(0, h - 1) << 2; | |
| 860 line2 = 0; | |
| 861 for (FX_DWORD w = 0; w < GBW; w++) { | |
| 862 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 863 bVal = 0; | |
| 864 } else { | |
| 865 CONTEXT = line2; | |
| 866 CONTEXT |= line1 << 4; | |
| 867 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 868 } | |
| 869 if (bVal) { | |
| 870 GBREG->setPixel(w, h, bVal); | |
| 871 } | |
| 872 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x3f; | |
| 873 line2 = ((line2 << 1) | bVal) & 0x0f; | |
| 874 } | |
| 875 } | |
| 876 } | |
| 877 return GBREG; | |
| 878 } | |
| 879 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt2( | |
| 880 CJBig2_ArithDecoder* pArithDecoder, | |
| 881 JBig2ArithCtx* gbContext) { | |
| 882 FX_BOOL LTP, SLTP, bVal; | |
| 883 FX_DWORD CONTEXT; | |
| 884 CJBig2_Image* GBREG; | |
| 885 FX_DWORD line1; | |
| 886 uint8_t *pLine, cVal; | |
| 887 intptr_t nStride; | |
| 888 int32_t nBits, k; | |
| 889 LTP = 0; | |
| 890 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | |
| 891 if (GBREG->m_pData == NULL) { | |
| 892 delete GBREG; | |
| 893 m_pModule->JBig2_Error( | |
| 894 "Generic region decoding procedure: Create Image Failed with width = " | |
| 895 "%d, height = %d\n", | |
| 896 GBW, GBH); | |
| 897 return NULL; | |
| 898 } | |
| 899 pLine = GBREG->m_pData; | |
| 900 nStride = GBREG->m_nStride; | |
| 901 for (FX_DWORD h = 0; h < GBH; h++) { | |
| 902 if (TPGDON) { | |
| 903 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | |
| 904 LTP = LTP ^ SLTP; | |
| 905 } | |
| 906 if (LTP == 1) { | |
| 907 GBREG->copyLine(h, h - 1); | |
| 908 } else { | |
| 909 line1 = (h > 0) ? pLine[-nStride] : 0; | |
| 910 CONTEXT = (line1 >> 1) & 0x03f0; | |
| 911 for (FX_DWORD w = 0; w < GBW; w += 8) { | |
| 912 if (w + 8 < GBW) { | |
| 913 nBits = 8; | |
| 914 if (h > 0) { | |
| 915 line1 = (line1 << 8) | (pLine[-nStride + (w >> 3) + 1]); | |
| 916 } | |
| 917 } else { | |
| 918 nBits = GBW - w; | |
| 919 if (h > 0) { | |
| 920 line1 <<= 8; | |
| 921 } | |
| 922 } | |
| 923 cVal = 0; | |
| 924 for (k = 0; k < nBits; k++) { | |
| 925 if (USESKIP && SKIP->getPixel(w, h)) { | |
| 926 bVal = 0; | |
| 927 } else { | |
| 928 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | |
| 929 } | |
| 930 cVal |= bVal << (7 - k); | |
| 931 CONTEXT = | |
| 932 ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010); | |
| 933 } | |
| 934 pLine[w >> 3] = cVal; | |
| 935 } | |
| 936 } | |
| 937 pLine += nStride; | |
| 938 } | |
| 939 return GBREG; | |
| 940 } | |
| 941 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( | 490 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( |
| 942 CJBig2_ArithDecoder* pArithDecoder, | 491 CJBig2_ArithDecoder* pArithDecoder, |
| 943 JBig2ArithCtx* gbContext) { | 492 JBig2ArithCtx* gbContext) { |
| 944 FX_BOOL LTP, SLTP, bVal; | 493 FX_BOOL LTP, SLTP, bVal; |
| 945 FX_DWORD CONTEXT; | 494 FX_DWORD CONTEXT; |
| 946 CJBig2_Image* GBREG; | 495 CJBig2_Image* GBREG; |
| 947 FX_DWORD line1; | 496 FX_DWORD line1; |
| 948 uint8_t *pLine, *pLine1, cVal; | 497 uint8_t *pLine, *pLine1, cVal; |
| 949 int32_t nStride, k; | 498 int32_t nStride, k; |
| 950 int32_t nLineBytes, nBitsLeft, cc; | 499 int32_t nLineBytes, nBitsLeft, cc; |
| (...skipping 2927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3878 } | 3427 } |
| 3879 if (pPause && pPause->NeedToPauseNow()) { | 3428 if (pPause && pPause->NeedToPauseNow()) { |
| 3880 m_loopIndex++; | 3429 m_loopIndex++; |
| 3881 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 3430 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 3882 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 3431 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 3883 } | 3432 } |
| 3884 } | 3433 } |
| 3885 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 3434 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 3886 return FXCODEC_STATUS_DECODE_FINISH; | 3435 return FXCODEC_STATUS_DECODE_FINISH; |
| 3887 } | 3436 } |
| OLD | NEW |