• 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_TRDPROC_H_
8 #define CORE_FXCODEC_JBIG2_JBIG2_TRDPROC_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcodec/jbig2/JBig2_Image.h"
14 #include "core/fxcrt/fx_system.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 
17 class CJBig2_ArithDecoder;
18 class CJBig2_ArithIaidDecoder;
19 class CJBig2_ArithIntDecoder;
20 class CJBig2_BitStream;
21 class CJBig2_HuffmanTable;
22 class JBig2ArithCtx;
23 struct JBig2HuffmanCode;
24 
25 struct JBig2IntDecoderState {
26   JBig2IntDecoderState();
27   ~JBig2IntDecoderState();
28 
29   UnownedPtr<CJBig2_ArithIntDecoder> IADT;
30   UnownedPtr<CJBig2_ArithIntDecoder> IAFS;
31   UnownedPtr<CJBig2_ArithIntDecoder> IADS;
32   UnownedPtr<CJBig2_ArithIntDecoder> IAIT;
33   UnownedPtr<CJBig2_ArithIntDecoder> IARI;
34   UnownedPtr<CJBig2_ArithIntDecoder> IARDW;
35   UnownedPtr<CJBig2_ArithIntDecoder> IARDH;
36   UnownedPtr<CJBig2_ArithIntDecoder> IARDX;
37   UnownedPtr<CJBig2_ArithIntDecoder> IARDY;
38   UnownedPtr<CJBig2_ArithIaidDecoder> IAID;
39 };
40 
41 enum JBig2Corner {
42   JBIG2_CORNER_BOTTOMLEFT = 0,
43   JBIG2_CORNER_TOPLEFT = 1,
44   JBIG2_CORNER_BOTTOMRIGHT = 2,
45   JBIG2_CORNER_TOPRIGHT = 3
46 };
47 
48 class CJBig2_TRDProc {
49  public:
50   CJBig2_TRDProc();
51   ~CJBig2_TRDProc();
52 
53   std::unique_ptr<CJBig2_Image> DecodeHuffman(CJBig2_BitStream* pStream,
54                                               JBig2ArithCtx* grContext);
55 
56   std::unique_ptr<CJBig2_Image> DecodeArith(CJBig2_ArithDecoder* pArithDecoder,
57                                             JBig2ArithCtx* grContext,
58                                             JBig2IntDecoderState* pIDS);
59 
60   bool SBHUFF;
61   bool SBREFINE;
62   bool SBRTEMPLATE;
63   bool TRANSPOSED;
64   bool SBDEFPIXEL;
65   int8_t SBDSOFFSET;
66   uint8_t SBSYMCODELEN;
67   uint32_t SBW;
68   uint32_t SBH;
69   uint32_t SBNUMINSTANCES;
70   uint32_t SBSTRIPS;
71   uint32_t SBNUMSYMS;
72   std::vector<JBig2HuffmanCode> SBSYMCODES;
73   CJBig2_Image** SBSYMS;
74   JBig2ComposeOp SBCOMBOP;
75   JBig2Corner REFCORNER;
76   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFFS;
77   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFDS;
78   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFDT;
79   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDW;
80   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDH;
81   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDX;
82   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDY;
83   UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRSIZE;
84   int8_t SBRAT[4];
85 
86  private:
87   struct ComposeData {
88     int32_t x;
89     int32_t y;
90     uint32_t increment = 0;
91   };
92   ComposeData GetComposeData(int32_t SI,
93                              int32_t TI,
94                              uint32_t WI,
95                              uint32_t HI) const;
96 };
97 
98 #endif  // CORE_FXCODEC_JBIG2_JBIG2_TRDPROC_H_
99