• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
8 #define CORE_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
9 
10 #include "core/fxcrt/retain_ptr.h"
11 
12 class CPDF_StreamAcc;
13 
14 class CJBig2_BitStream {
15  public:
16   explicit CJBig2_BitStream(const RetainPtr<CPDF_StreamAcc>& pSrcStream);
17   ~CJBig2_BitStream();
18 
19   // TODO(thestig): readFoo() should return bool.
20   int32_t readNBits(uint32_t nBits, uint32_t* dwResult);
21   int32_t readNBits(uint32_t nBits, int32_t* nResult);
22   int32_t read1Bit(uint32_t* dwResult);
23   int32_t read1Bit(bool* bResult);
24   int32_t read1Byte(uint8_t* cResult);
25   int32_t readInteger(uint32_t* dwResult);
26   int32_t readShortInteger(uint16_t* 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   uint32_t getOffset() const;
33   void setOffset(uint32_t dwOffset);
34   uint32_t getBitPos() const;
35   void setBitPos(uint32_t dwBitPos);
36   const uint8_t* getBuf() const;
getLength()37   uint32_t getLength() const { return m_dwLength; }
38   const uint8_t* getPointer() const;
39   void offset(uint32_t dwOffset);
40   uint32_t getByteLeft() const;
41   uint32_t getObjNum() const;
42 
43   bool IsInBounds() const;
44 
45  private:
46   void AdvanceBit();
47   uint32_t LengthInBits() const;
48 
49   const uint8_t* m_pBuf;
50   uint32_t m_dwLength;
51   uint32_t m_dwByteIdx;
52   uint32_t m_dwBitIdx;
53   const uint32_t m_dwObjNum;
54 
55   CJBig2_BitStream(const CJBig2_BitStream&) = delete;
56   void operator=(const CJBig2_BitStream&) = delete;
57 };
58 
59 #endif  // CORE_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
60