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