OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 |
| 7 #include "JBig2_PddProc.h" |
| 8 |
| 9 #include "../../../../third_party/base/nonstd_unique_ptr.h" |
| 10 #include "JBig2_GrdProc.h" |
| 11 #include "JBig2_Image.h" |
| 12 #include "JBig2_PatternDict.h" |
| 13 |
| 14 CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( |
| 15 CJBig2_ArithDecoder* pArithDecoder, |
| 16 JBig2ArithCtx* gbContext, |
| 17 IFX_Pause* pPause) { |
| 18 FX_DWORD GRAY; |
| 19 CJBig2_Image* BHDC = nullptr; |
| 20 nonstd::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict()); |
| 21 pDict->NUMPATS = GRAYMAX + 1; |
| 22 pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); |
| 23 JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); |
| 24 |
| 25 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
| 26 pGRD->MMR = HDMMR; |
| 27 pGRD->GBW = (GRAYMAX + 1) * HDPW; |
| 28 pGRD->GBH = HDPH; |
| 29 pGRD->GBTEMPLATE = HDTEMPLATE; |
| 30 pGRD->TPGDON = 0; |
| 31 pGRD->USESKIP = 0; |
| 32 pGRD->GBAT[0] = -(int32_t)HDPW; |
| 33 pGRD->GBAT[1] = 0; |
| 34 if (pGRD->GBTEMPLATE == 0) { |
| 35 pGRD->GBAT[2] = -3; |
| 36 pGRD->GBAT[3] = -1; |
| 37 pGRD->GBAT[4] = 2; |
| 38 pGRD->GBAT[5] = -2; |
| 39 pGRD->GBAT[6] = -2; |
| 40 pGRD->GBAT[7] = -2; |
| 41 } |
| 42 FXCODEC_STATUS status = |
| 43 pGRD->Start_decode_Arith(&BHDC, pArithDecoder, gbContext, nullptr); |
| 44 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 45 pGRD->Continue_decode(pPause); |
| 46 } |
| 47 if (!BHDC) |
| 48 return nullptr; |
| 49 |
| 50 GRAY = 0; |
| 51 while (GRAY <= GRAYMAX) { |
| 52 pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); |
| 53 GRAY = GRAY + 1; |
| 54 } |
| 55 delete BHDC; |
| 56 return pDict.release(); |
| 57 } |
| 58 |
| 59 CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream, |
| 60 IFX_Pause* pPause) { |
| 61 FX_DWORD GRAY; |
| 62 CJBig2_Image* BHDC = nullptr; |
| 63 nonstd::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict()); |
| 64 pDict->NUMPATS = GRAYMAX + 1; |
| 65 pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); |
| 66 JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); |
| 67 |
| 68 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
| 69 pGRD->MMR = HDMMR; |
| 70 pGRD->GBW = (GRAYMAX + 1) * HDPW; |
| 71 pGRD->GBH = HDPH; |
| 72 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&BHDC, pStream, nullptr); |
| 73 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 74 pGRD->Continue_decode(pPause); |
| 75 } |
| 76 if (!BHDC) |
| 77 return nullptr; |
| 78 |
| 79 GRAY = 0; |
| 80 while (GRAY <= GRAYMAX) { |
| 81 pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); |
| 82 GRAY = GRAY + 1; |
| 83 } |
| 84 delete BHDC; |
| 85 return pDict.release(); |
| 86 } |
OLD | NEW |