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