1 // Copyright 2015 The PDFium Authors 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 #ifndef CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_ 8 #define CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_ 9 10 #include <stdint.h> 11 12 #include <memory> 13 14 #include "core/fxcodec/fx_codec_def.h" 15 #include "core/fxcrt/fx_coordinates.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 #include "core/fxcrt/unowned_ptr_exclusion.h" 18 19 class CJBig2_ArithDecoder; 20 class CJBig2_BitStream; 21 class CJBig2_Image; 22 class JBig2ArithCtx; 23 class PauseIndicatorIface; 24 25 class CJBig2_GRDProc { 26 public: 27 class ProgressiveArithDecodeState { 28 public: 29 ProgressiveArithDecodeState(); 30 ~ProgressiveArithDecodeState(); 31 32 UnownedPtr<std::unique_ptr<CJBig2_Image>> pImage; 33 UnownedPtr<CJBig2_ArithDecoder> pArithDecoder; 34 UnownedPtr<JBig2ArithCtx> gbContext; 35 UnownedPtr<PauseIndicatorIface> pPause; 36 }; 37 38 CJBig2_GRDProc(); 39 ~CJBig2_GRDProc(); 40 41 std::unique_ptr<CJBig2_Image> DecodeArith(CJBig2_ArithDecoder* pArithDecoder, 42 JBig2ArithCtx* gbContext); 43 44 FXCODEC_STATUS StartDecodeArith(ProgressiveArithDecodeState* pState); 45 FXCODEC_STATUS StartDecodeMMR(std::unique_ptr<CJBig2_Image>* pImage, 46 CJBig2_BitStream* pStream); 47 FXCODEC_STATUS ContinueDecode(ProgressiveArithDecodeState* pState); GetReplaceRect()48 const FX_RECT& GetReplaceRect() const { return m_ReplaceRect; } 49 50 bool MMR; 51 bool TPGDON; 52 bool USESKIP; 53 uint8_t GBTEMPLATE; 54 uint32_t GBW; 55 uint32_t GBH; 56 UnownedPtr<CJBig2_Image> SKIP; 57 int8_t GBAT[8]; 58 59 private: 60 bool UseTemplate0Opt3() const; 61 bool UseTemplate1Opt3() const; 62 bool UseTemplate23Opt3() const; 63 64 FXCODEC_STATUS ProgressiveDecodeArith(ProgressiveArithDecodeState* pState); 65 FXCODEC_STATUS ProgressiveDecodeArithTemplate0Opt3( 66 ProgressiveArithDecodeState* pState); 67 FXCODEC_STATUS ProgressiveDecodeArithTemplate0Unopt( 68 ProgressiveArithDecodeState* pState); 69 FXCODEC_STATUS ProgressiveDecodeArithTemplate1Opt3( 70 ProgressiveArithDecodeState* pState); 71 FXCODEC_STATUS ProgressiveDecodeArithTemplate1Unopt( 72 ProgressiveArithDecodeState* pState); 73 FXCODEC_STATUS ProgressiveDecodeArithTemplate2Opt3( 74 ProgressiveArithDecodeState* pState); 75 FXCODEC_STATUS ProgressiveDecodeArithTemplate2Unopt( 76 ProgressiveArithDecodeState* pState); 77 FXCODEC_STATUS ProgressiveDecodeArithTemplate3Opt3( 78 ProgressiveArithDecodeState* pState); 79 FXCODEC_STATUS ProgressiveDecodeArithTemplate3Unopt( 80 ProgressiveArithDecodeState* pState); 81 82 std::unique_ptr<CJBig2_Image> DecodeArithOpt3( 83 CJBig2_ArithDecoder* pArithDecoder, 84 JBig2ArithCtx* gbContext, 85 int OPT); 86 std::unique_ptr<CJBig2_Image> DecodeArithTemplateUnopt( 87 CJBig2_ArithDecoder* pArithDecoder, 88 JBig2ArithCtx* gbContext, 89 int UNOPT); 90 std::unique_ptr<CJBig2_Image> DecodeArithTemplate3Opt3( 91 CJBig2_ArithDecoder* pArithDecoder, 92 JBig2ArithCtx* gbContext); 93 std::unique_ptr<CJBig2_Image> DecodeArithTemplate3Unopt( 94 CJBig2_ArithDecoder* pArithDecoder, 95 JBig2ArithCtx* gbContext); 96 97 uint32_t m_loopIndex = 0; 98 UNOWNED_PTR_EXCLUSION uint8_t* m_pLine = nullptr; 99 FXCODEC_STATUS m_ProgressiveStatus; 100 uint16_t m_DecodeType = 0; 101 int m_LTP = 0; 102 FX_RECT m_ReplaceRect; 103 }; 104 105 #endif // CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_ 106