| 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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 } | 881 } |
| 882 return GBREG; | 882 return GBREG; |
| 883 } | 883 } |
| 884 CJBig2_Image *CJBig2_GRDProc::decode_Arith_Template3_opt2(CJBig2_ArithDecoder *p
ArithDecoder, JBig2ArithCtx *gbContext) | 884 CJBig2_Image *CJBig2_GRDProc::decode_Arith_Template3_opt2(CJBig2_ArithDecoder *p
ArithDecoder, JBig2ArithCtx *gbContext) |
| 885 { | 885 { |
| 886 FX_BOOL LTP, SLTP, bVal; | 886 FX_BOOL LTP, SLTP, bVal; |
| 887 FX_DWORD CONTEXT; | 887 FX_DWORD CONTEXT; |
| 888 CJBig2_Image *GBREG; | 888 CJBig2_Image *GBREG; |
| 889 FX_DWORD line1; | 889 FX_DWORD line1; |
| 890 FX_BYTE *pLine, cVal; | 890 FX_BYTE *pLine, cVal; |
| 891 FX_INTPTR nStride, nStride2; | 891 FX_INTPTR nStride; |
| 892 FX_INT32 nBits, k; | 892 FX_INT32 nBits, k; |
| 893 LTP = 0; | 893 LTP = 0; |
| 894 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); | 894 JBIG2_ALLOC(GBREG, CJBig2_Image(GBW, GBH)); |
| 895 if (GBREG->m_pData == NULL) { | 895 if (GBREG->m_pData == NULL) { |
| 896 delete GBREG; | 896 delete GBREG; |
| 897 m_pModule->JBig2_Error("Generic region decoding procedure: Create Image
Failed with width = %d, height = %d\n", GBW, GBH); | 897 m_pModule->JBig2_Error("Generic region decoding procedure: Create Image
Failed with width = %d, height = %d\n", GBW, GBH); |
| 898 return NULL; | 898 return NULL; |
| 899 } | 899 } |
| 900 pLine = GBREG->m_pData; | 900 pLine = GBREG->m_pData; |
| 901 nStride = GBREG->m_nStride; | 901 nStride = GBREG->m_nStride; |
| 902 nStride2 = nStride << 1; | |
| 903 for(FX_DWORD h = 0; h < GBH; h++) { | 902 for(FX_DWORD h = 0; h < GBH; h++) { |
| 904 if(TPGDON) { | 903 if(TPGDON) { |
| 905 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | 904 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); |
| 906 LTP = LTP ^ SLTP; | 905 LTP = LTP ^ SLTP; |
| 907 } | 906 } |
| 908 if(LTP == 1) { | 907 if(LTP == 1) { |
| 909 GBREG->copyLine(h, h - 1); | 908 GBREG->copyLine(h, h - 1); |
| 910 } else { | 909 } else { |
| 911 line1 = (h > 0) ? pLine[-nStride] : 0; | 910 line1 = (h > 0) ? pLine[-nStride] : 0; |
| 912 CONTEXT = (line1 >> 1) & 0x03f0; | 911 CONTEXT = (line1 >> 1) & 0x03f0; |
| (...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2328 } | 2327 } |
| 2329 delete SBREG; | 2328 delete SBREG; |
| 2330 return NULL; | 2329 return NULL; |
| 2331 } | 2330 } |
| 2332 CJBig2_SymbolDict *CJBig2_SDDProc::decode_Arith(CJBig2_ArithDecoder *pArithDecod
er, | 2331 CJBig2_SymbolDict *CJBig2_SDDProc::decode_Arith(CJBig2_ArithDecoder *pArithDecod
er, |
| 2333 JBig2ArithCtx *gbContext, JBig2ArithCtx *grContext) | 2332 JBig2ArithCtx *gbContext, JBig2ArithCtx *grContext) |
| 2334 { | 2333 { |
| 2335 CJBig2_Image **SDNEWSYMS; | 2334 CJBig2_Image **SDNEWSYMS; |
| 2336 FX_DWORD HCHEIGHT, NSYMSDECODED; | 2335 FX_DWORD HCHEIGHT, NSYMSDECODED; |
| 2337 FX_INT32 HCDH; | 2336 FX_INT32 HCDH; |
| 2338 FX_DWORD SYMWIDTH, TOTWIDTH, HCFIRSTSYM; | 2337 FX_DWORD SYMWIDTH, TOTWIDTH; |
| 2339 FX_INT32 DW; | 2338 FX_INT32 DW; |
| 2340 CJBig2_Image *BS; | 2339 CJBig2_Image *BS; |
| 2341 FX_DWORD I, J, REFAGGNINST; | 2340 FX_DWORD I, J, REFAGGNINST; |
| 2342 FX_BOOL *EXFLAGS; | 2341 FX_BOOL *EXFLAGS; |
| 2343 FX_DWORD EXINDEX; | 2342 FX_DWORD EXINDEX; |
| 2344 FX_BOOL CUREXFLAG; | 2343 FX_BOOL CUREXFLAG; |
| 2345 FX_DWORD EXRUNLENGTH; | 2344 FX_DWORD EXRUNLENGTH; |
| 2346 FX_INT32 nVal; | 2345 FX_INT32 nVal; |
| 2347 FX_DWORD nTmp; | 2346 FX_DWORD nTmp; |
| 2348 FX_BOOL SBHUFF; | |
| 2349 FX_DWORD SBNUMSYMS; | 2347 FX_DWORD SBNUMSYMS; |
| 2350 FX_BYTE SBSYMCODELEN; | 2348 FX_BYTE SBSYMCODELEN; |
| 2351 FX_DWORD IDI; | 2349 FX_DWORD IDI; |
| 2352 FX_INT32 RDXI, RDYI; | 2350 FX_INT32 RDXI, RDYI; |
| 2353 CJBig2_Image **SBSYMS; | 2351 CJBig2_Image **SBSYMS; |
| 2354 CJBig2_HuffmanTable *SBHUFFFS, *SBHUFFDS, *SBHUFFDT, *SBHUFFRDW, *SBHUFFRDH,
*SBHUFFRDX, *SBHUFFRDY, | 2352 CJBig2_HuffmanTable *SBHUFFFS, *SBHUFFDS, *SBHUFFDT, *SBHUFFRDW, *SBHUFFRDH,
*SBHUFFRDX, *SBHUFFRDY, |
| 2355 *SBHUFFRSIZE; | 2353 *SBHUFFRSIZE; |
| 2356 CJBig2_GRRDProc *pGRRD; | 2354 CJBig2_GRRDProc *pGRRD; |
| 2357 CJBig2_GRDProc *pGRD; | 2355 CJBig2_GRDProc *pGRD; |
| 2358 CJBig2_ArithIntDecoder *IADH, *IADW, *IAAI, *IARDX, *IARDY, *IAEX, | 2356 CJBig2_ArithIntDecoder *IADH, *IADW, *IAAI, *IARDX, *IARDY, *IAEX, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2387 m_pModule->JBig2_Error("symbol dictionary decoding procedure (arith)
: too short."); | 2385 m_pModule->JBig2_Error("symbol dictionary decoding procedure (arith)
: too short."); |
| 2388 goto failed; | 2386 goto failed; |
| 2389 } | 2387 } |
| 2390 HCHEIGHT = HCHEIGHT + HCDH; | 2388 HCHEIGHT = HCHEIGHT + HCDH; |
| 2391 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { | 2389 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { |
| 2392 m_pModule->JBig2_Error("symbol dictionary decoding procedure (arith)
: invalid HCHEIGHT value."); | 2390 m_pModule->JBig2_Error("symbol dictionary decoding procedure (arith)
: invalid HCHEIGHT value."); |
| 2393 goto failed; | 2391 goto failed; |
| 2394 } | 2392 } |
| 2395 SYMWIDTH = 0; | 2393 SYMWIDTH = 0; |
| 2396 TOTWIDTH = 0; | 2394 TOTWIDTH = 0; |
| 2397 HCFIRSTSYM = NSYMSDECODED; | |
| 2398 for(;;) { | 2395 for(;;) { |
| 2399 nVal = IADW->decode(pArithDecoder, &DW); | 2396 nVal = IADW->decode(pArithDecoder, &DW); |
| 2400 if(nVal == JBIG2_OOB) { | 2397 if(nVal == JBIG2_OOB) { |
| 2401 break; | 2398 break; |
| 2402 } else if(nVal != 0) { | 2399 } else if(nVal != 0) { |
| 2403 m_pModule->JBig2_Error("symbol dictionary decoding procedure (ar
ith): too short."); | 2400 m_pModule->JBig2_Error("symbol dictionary decoding procedure (ar
ith): too short."); |
| 2404 goto failed; | 2401 goto failed; |
| 2405 } else { | 2402 } else { |
| 2406 if (NSYMSDECODED >= SDNUMNEWSYMS) { | 2403 if (NSYMSDECODED >= SDNUMNEWSYMS) { |
| 2407 m_pModule->JBig2_Error("symbol dictionary decoding procedure
(arith): NSYMSDECODED >= SDNUMNEWSYMS."); | 2404 m_pModule->JBig2_Error("symbol dictionary decoding procedure
(arith): NSYMSDECODED >= SDNUMNEWSYMS."); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 delete SBHUFFFS; | 2527 delete SBHUFFFS; |
| 2531 delete SBHUFFDS; | 2528 delete SBHUFFDS; |
| 2532 delete SBHUFFDT; | 2529 delete SBHUFFDT; |
| 2533 delete SBHUFFRDW; | 2530 delete SBHUFFRDW; |
| 2534 delete SBHUFFRDH; | 2531 delete SBHUFFRDH; |
| 2535 delete SBHUFFRDX; | 2532 delete SBHUFFRDX; |
| 2536 delete SBHUFFRDY; | 2533 delete SBHUFFRDY; |
| 2537 delete SBHUFFRSIZE; | 2534 delete SBHUFFRSIZE; |
| 2538 delete pDecoder; | 2535 delete pDecoder; |
| 2539 } else if(REFAGGNINST == 1) { | 2536 } else if(REFAGGNINST == 1) { |
| 2540 SBHUFF = SDHUFF; | |
| 2541 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; | 2537 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; |
| 2542 if(IAID->decode(pArithDecoder, (int*)&IDI) == -1) { | 2538 if(IAID->decode(pArithDecoder, (int*)&IDI) == -1) { |
| 2543 m_pModule->JBig2_Error("symbol dictionary decoding proce
dure (arith): too short."); | 2539 m_pModule->JBig2_Error("symbol dictionary decoding proce
dure (arith): too short."); |
| 2544 goto failed; | 2540 goto failed; |
| 2545 } | 2541 } |
| 2546 if((IARDX->decode(pArithDecoder, &RDXI) == -1) | 2542 if((IARDX->decode(pArithDecoder, &RDXI) == -1) |
| 2547 || (IARDY->decode(pArithDecoder, &RDYI) == -1)) { | 2543 || (IARDY->decode(pArithDecoder, &RDYI) == -1)) { |
| 2548 m_pModule->JBig2_Error("symbol dictionary decoding proce
dure (arith): too short."); | 2544 m_pModule->JBig2_Error("symbol dictionary decoding proce
dure (arith): too short."); |
| 2549 goto failed; | 2545 goto failed; |
| 2550 } | 2546 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2679 FX_DWORD SYMWIDTH, TOTWIDTH, HCFIRSTSYM; | 2675 FX_DWORD SYMWIDTH, TOTWIDTH, HCFIRSTSYM; |
| 2680 FX_INT32 DW; | 2676 FX_INT32 DW; |
| 2681 CJBig2_Image *BS, *BHC; | 2677 CJBig2_Image *BS, *BHC; |
| 2682 FX_DWORD I, J, REFAGGNINST; | 2678 FX_DWORD I, J, REFAGGNINST; |
| 2683 FX_BOOL *EXFLAGS; | 2679 FX_BOOL *EXFLAGS; |
| 2684 FX_DWORD EXINDEX; | 2680 FX_DWORD EXINDEX; |
| 2685 FX_BOOL CUREXFLAG; | 2681 FX_BOOL CUREXFLAG; |
| 2686 FX_DWORD EXRUNLENGTH; | 2682 FX_DWORD EXRUNLENGTH; |
| 2687 FX_INT32 nVal, nBits; | 2683 FX_INT32 nVal, nBits; |
| 2688 FX_DWORD nTmp; | 2684 FX_DWORD nTmp; |
| 2689 FX_BOOL SBHUFF; | |
| 2690 FX_DWORD SBNUMSYMS; | 2685 FX_DWORD SBNUMSYMS; |
| 2691 FX_BYTE SBSYMCODELEN; | 2686 FX_BYTE SBSYMCODELEN; |
| 2692 JBig2HuffmanCode *SBSYMCODES; | 2687 JBig2HuffmanCode *SBSYMCODES; |
| 2693 FX_DWORD IDI; | 2688 FX_DWORD IDI; |
| 2694 FX_INT32 RDXI, RDYI; | 2689 FX_INT32 RDXI, RDYI; |
| 2695 FX_DWORD BMSIZE; | 2690 FX_DWORD BMSIZE; |
| 2696 FX_DWORD stride; | 2691 FX_DWORD stride; |
| 2697 CJBig2_Image **SBSYMS; | 2692 CJBig2_Image **SBSYMS; |
| 2698 CJBig2_HuffmanTable *SBHUFFFS, *SBHUFFDS, *SBHUFFDT, *SBHUFFRDW, *SBHUFFRDH,
*SBHUFFRDX, *SBHUFFRDY, | 2693 CJBig2_HuffmanTable *SBHUFFFS, *SBHUFFDS, *SBHUFFDT, *SBHUFFRDW, *SBHUFFRDH,
*SBHUFFRDX, *SBHUFFRDY, |
| 2699 *SBHUFFRSIZE, *pTable; | 2694 *SBHUFFRSIZE, *pTable; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2836 delete SBHUFFFS; | 2831 delete SBHUFFFS; |
| 2837 delete SBHUFFDS; | 2832 delete SBHUFFDS; |
| 2838 delete SBHUFFDT; | 2833 delete SBHUFFDT; |
| 2839 delete SBHUFFRDW; | 2834 delete SBHUFFRDW; |
| 2840 delete SBHUFFRDH; | 2835 delete SBHUFFRDH; |
| 2841 delete SBHUFFRDX; | 2836 delete SBHUFFRDX; |
| 2842 delete SBHUFFRDY; | 2837 delete SBHUFFRDY; |
| 2843 delete SBHUFFRSIZE; | 2838 delete SBHUFFRSIZE; |
| 2844 delete pDecoder; | 2839 delete pDecoder; |
| 2845 } else if(REFAGGNINST == 1) { | 2840 } else if(REFAGGNINST == 1) { |
| 2846 SBHUFF = SDHUFF; | |
| 2847 SBNUMSYMS = SDNUMINSYMS + SDNUMNEWSYMS; | 2841 SBNUMSYMS = SDNUMINSYMS + SDNUMNEWSYMS; |
| 2848 nTmp = 1; | 2842 nTmp = 1; |
| 2849 while((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { | 2843 while((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { |
| 2850 nTmp ++; | 2844 nTmp ++; |
| 2851 } | 2845 } |
| 2852 SBSYMCODELEN = (FX_BYTE)nTmp; | 2846 SBSYMCODELEN = (FX_BYTE)nTmp; |
| 2853 SBSYMCODES = (JBig2HuffmanCode*)m_pModule->JBig2_Malloc2(SBN
UMSYMS, sizeof(JBig2HuffmanCode)); | 2847 SBSYMCODES = (JBig2HuffmanCode*)m_pModule->JBig2_Malloc2(SBN
UMSYMS, sizeof(JBig2HuffmanCode)); |
| 2854 for(I = 0; I < SBNUMSYMS; I++) { | 2848 for(I = 0; I < SBNUMSYMS; I++) { |
| 2855 SBSYMCODES[I].codelen = SBSYMCODELEN; | 2849 SBSYMCODES[I].codelen = SBSYMCODELEN; |
| 2856 SBSYMCODES[I].code = I; | 2850 SBSYMCODES[I].code = I; |
| (...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4334 } | 4328 } |
| 4335 if(pPause && pPause->NeedToPauseNow()) { | 4329 if(pPause && pPause->NeedToPauseNow()) { |
| 4336 m_loopIndex++; | 4330 m_loopIndex++; |
| 4337 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 4331 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 4338 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 4332 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 4339 } | 4333 } |
| 4340 } | 4334 } |
| 4341 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 4335 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 4342 return FXCODEC_STATUS_DECODE_FINISH; | 4336 return FXCODEC_STATUS_DECODE_FINISH; |
| 4343 } | 4337 } |
| OLD | NEW |