1 // Copyright 2014 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_SRC_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_ 8 #define CORE_SRC_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_ 9 10 #include "core/include/fxcrt/fx_basic.h" 11 12 class CPDF_StreamAcc; 13 14 class CJBig2_BitStream { 15 public: 16 explicit CJBig2_BitStream(CPDF_StreamAcc* pSrcStream); 17 ~CJBig2_BitStream(); 18 19 // TODO(thestig): readFoo() should return bool. 20 int32_t readNBits(FX_DWORD nBits, FX_DWORD* dwResult); 21 int32_t readNBits(FX_DWORD nBits, int32_t* nResult); 22 int32_t read1Bit(FX_DWORD* dwResult); 23 int32_t read1Bit(FX_BOOL* bResult); 24 int32_t read1Byte(uint8_t* cResult); 25 int32_t readInteger(FX_DWORD* dwResult); 26 int32_t readShortInteger(FX_WORD* wResult); 27 void alignByte(); 28 uint8_t getCurByte() const; 29 void incByteIdx(); 30 uint8_t getCurByte_arith() const; 31 uint8_t getNextByte_arith() const; 32 FX_DWORD getOffset() const; 33 void setOffset(FX_DWORD dwOffset); 34 FX_DWORD getBitPos() const; 35 void setBitPos(FX_DWORD dwBitPos); 36 const uint8_t* getBuf() const; getLength()37 FX_DWORD getLength() const { return m_dwLength; } 38 const uint8_t* getPointer() const; 39 void offset(FX_DWORD dwOffset); 40 FX_DWORD getByteLeft() const; 41 FX_DWORD getObjNum() const; 42 43 private: 44 void AdvanceBit(); 45 bool IsInBound() const; 46 FX_DWORD LengthInBits() const; 47 48 const uint8_t* m_pBuf; 49 FX_DWORD m_dwLength; 50 FX_DWORD m_dwByteIdx; 51 FX_DWORD m_dwBitIdx; 52 const FX_DWORD m_dwObjNum; 53 54 CJBig2_BitStream(const CJBig2_BitStream&) = delete; 55 void operator=(const CJBig2_BitStream&) = delete; 56 }; 57 58 #endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_ 59