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_GRRDPROC_H_
8 #define CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/fx_system.h"
13 #include "core/fxcrt/unowned_ptr.h"
14 
15 class CJBig2_ArithDecoder;
16 class CJBig2_Image;
17 class JBig2ArithCtx;
18 
19 class CJBig2_GRRDProc {
20  public:
21   CJBig2_GRRDProc();
22   ~CJBig2_GRRDProc();
23 
24   std::unique_ptr<CJBig2_Image> Decode(CJBig2_ArithDecoder* pArithDecoder,
25                                        JBig2ArithCtx* grContext);
26 
27   bool GRTEMPLATE;
28   bool TPGRON;
29   uint32_t GRW;
30   uint32_t GRH;
31   int32_t GRREFERENCEDX;
32   int32_t GRREFERENCEDY;
33   UnownedPtr<CJBig2_Image> GRREFERENCE;
34   int8_t GRAT[4];
35 
36  private:
37   std::unique_ptr<CJBig2_Image> DecodeTemplate0Unopt(
38       CJBig2_ArithDecoder* pArithDecoder,
39       JBig2ArithCtx* grContext);
40   uint32_t DecodeTemplate0UnoptCalculateContext(const CJBig2_Image& GRREG,
41                                                 const uint32_t* lines,
42                                                 uint32_t w,
43                                                 uint32_t h) const;
44   void DecodeTemplate0UnoptSetPixel(CJBig2_Image* GRREG,
45                                     uint32_t* lines,
46                                     uint32_t w,
47                                     uint32_t h,
48                                     int bVal);
49 
50   std::unique_ptr<CJBig2_Image> DecodeTemplate0Opt(
51       CJBig2_ArithDecoder* pArithDecoder,
52       JBig2ArithCtx* grContext);
53 
54   std::unique_ptr<CJBig2_Image> DecodeTemplate1Unopt(
55       CJBig2_ArithDecoder* pArithDecoder,
56       JBig2ArithCtx* grContext);
57 
58   std::unique_ptr<CJBig2_Image> DecodeTemplate1Opt(
59       CJBig2_ArithDecoder* pArithDecoder,
60       JBig2ArithCtx* grContext);
61 };
62 
63 #endif  // CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_
64