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