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