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