• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_ARITHDECODER_H_
8 #define CORE_FXCODEC_JBIG2_JBIG2_ARITHDECODER_H_
9 
10 #include <stdint.h>
11 
12 #include "core/fxcrt/fx_memory_wrappers.h"
13 #include "core/fxcrt/unowned_ptr.h"
14 
15 class CJBig2_BitStream;
16 struct JBig2ArithQe;
17 
18 class JBig2ArithCtx {
19  public:
20   struct JBig2ArithQe {
21     uint16_t Qe;
22     uint8_t NMPS;
23     uint8_t NLPS;
24     bool bSwitch;
25   };
26 
27   JBig2ArithCtx();
28 
29   int DecodeNLPS(const JBig2ArithQe& qe);
30   int DecodeNMPS(const JBig2ArithQe& qe);
31 
MPS()32   unsigned int MPS() const { return m_MPS ? 1 : 0; }
I()33   unsigned int I() const { return m_I; }
34 
35  private:
36   bool m_MPS = false;
37   unsigned int m_I = 0;
38 };
39 FX_DATA_PARTITION_EXCEPTION(JBig2ArithCtx);
40 
41 class CJBig2_ArithDecoder {
42  public:
43   explicit CJBig2_ArithDecoder(CJBig2_BitStream* pStream);
44   ~CJBig2_ArithDecoder();
45 
46   int Decode(JBig2ArithCtx* pCX);
47 
IsComplete()48   bool IsComplete() const { return m_Complete; }
49 
50  private:
51   enum class StreamState : uint8_t {
52     kDataAvailable,
53     kDecodingFinished,
54     kLooping,
55   };
56 
57   void BYTEIN();
58   void ReadValueA();
59 
60   bool m_Complete = false;
61   StreamState m_State = StreamState::kDataAvailable;
62   uint8_t m_B;
63   unsigned int m_C;
64   unsigned int m_A;
65   unsigned int m_CT;
66   UnownedPtr<CJBig2_BitStream> const m_pStream;
67 };
68 
69 #endif  // CORE_FXCODEC_JBIG2_JBIG2_ARITHDECODER_H_
70