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