Fix include paths for fx_system.h
[pdfium.git] / core / src / fxcodec / jbig2 / JBig2_Context.h
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_CONTEXT_H_
8 #define CORE_SRC_FXCODEC_JBIG2_JBIG2_CONTEXT_H_
9
10 #include <list>
11 #include <utility>
12
13 #include "../../../../third_party/base/nonstd_unique_ptr.h"
14 #include "../../../include/fxcodec/fx_codec_def.h"
15 #include "JBig2_List.h"
16 #include "JBig2_Page.h"
17 #include "JBig2_Segment.h"
18
19 class CJBig2_GRDProc;
20 class IFX_Pause;
21
22 using CJBig2_CachePair = std::pair<const uint8_t*, CJBig2_SymbolDict*>;
23
24 #define JBIG2_SUCCESS 0
25 #define JBIG2_FAILED -1
26 #define JBIG2_ERROR_TOO_SHORT -2
27 #define JBIG2_ERROR_FATAL -3
28 #define JBIG2_END_OF_PAGE 2
29 #define JBIG2_END_OF_FILE 3
30 #define JBIG2_ERROR_FILE_FORMAT -4
31 #define JBIG2_ERROR_STREAM_TYPE -5
32 #define JBIG2_ERROR_LIMIT -6
33 #define JBIG2_MIN_SEGMENT_SIZE 11
34
35 class CJBig2_Context {
36  public:
37   static CJBig2_Context* CreateContext(
38       const uint8_t* pGlobalData,
39       FX_DWORD dwGlobalLength,
40       const uint8_t* pData,
41       FX_DWORD dwLength,
42       std::list<CJBig2_CachePair>* pSymbolDictCache,
43       IFX_Pause* pPause = NULL);
44
45   static void DestroyContext(CJBig2_Context* pContext);
46
47   int32_t getFirstPage(uint8_t* pBuf,
48                        int32_t width,
49                        int32_t height,
50                        int32_t stride,
51                        IFX_Pause* pPause);
52
53   int32_t Continue(IFX_Pause* pPause);
54   FXCODEC_STATUS GetProcessingStatus() { return m_ProcessingStatus; }
55
56  private:
57   CJBig2_Context(const uint8_t* pGlobalData,
58                  FX_DWORD dwGlobalLength,
59                  const uint8_t* pData,
60                  FX_DWORD dwLength,
61                  std::list<CJBig2_CachePair>* pSymbolDictCache,
62                  IFX_Pause* pPause);
63
64   ~CJBig2_Context();
65
66   int32_t decode_SquentialOrgnazation(IFX_Pause* pPause);
67
68   int32_t decode_EmbedOrgnazation(IFX_Pause* pPause);
69
70   int32_t decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause);
71
72   int32_t decode_RandomOrgnazation(IFX_Pause* pPause);
73
74   CJBig2_Segment* findSegmentByNumber(FX_DWORD dwNumber);
75
76   CJBig2_Segment* findReferredSegmentByTypeAndIndex(CJBig2_Segment* pSegment,
77                                                     uint8_t cType,
78                                                     int32_t nIndex);
79
80   int32_t parseSegmentHeader(CJBig2_Segment* pSegment);
81
82   int32_t parseSegmentData(CJBig2_Segment* pSegment, IFX_Pause* pPause);
83   int32_t ProcessingParseSegmentData(CJBig2_Segment* pSegment,
84                                      IFX_Pause* pPause);
85
86   int32_t parseSymbolDict(CJBig2_Segment* pSegment, IFX_Pause* pPause);
87
88   int32_t parseTextRegion(CJBig2_Segment* pSegment);
89
90   int32_t parsePatternDict(CJBig2_Segment* pSegment, IFX_Pause* pPause);
91
92   int32_t parseHalftoneRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause);
93
94   int32_t parseGenericRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause);
95
96   int32_t parseGenericRefinementRegion(CJBig2_Segment* pSegment);
97
98   int32_t parseTable(CJBig2_Segment* pSegment);
99
100   int32_t parseRegionInfo(JBig2RegionInfo* pRI);
101
102   JBig2HuffmanCode* decodeSymbolIDHuffmanTable(CJBig2_BitStream* pStream,
103                                                FX_DWORD SBNUMSYMS);
104
105   void huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP);
106
107   void huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, int NTEMP);
108
109  private:
110   CJBig2_Context* m_pGlobalContext;
111   nonstd::unique_ptr<CJBig2_BitStream> m_pStream;
112   CJBig2_List<CJBig2_Segment> m_SegmentList;
113   CJBig2_List<JBig2PageInfo> m_PageInfoList;
114   nonstd::unique_ptr<CJBig2_Image> m_pPage;
115   size_t m_nSegmentDecoded;
116   bool m_bInPage;
117   bool m_bBufSpecified;
118   int32_t m_PauseStep;
119   IFX_Pause* m_pPause;
120   FXCODEC_STATUS m_ProcessingStatus;
121   CJBig2_ArithDecoder* m_pArithDecoder;
122   nonstd::unique_ptr<CJBig2_GRDProc> m_pGRD;
123   JBig2ArithCtx* m_gbContext;
124   nonstd::unique_ptr<CJBig2_Segment> m_pSegment;
125   FX_DWORD m_dwOffset;
126   JBig2RegionInfo m_ri;
127   std::list<CJBig2_CachePair>* const m_pSymbolDictCache;
128 };
129
130 #endif  // CORE_SRC_FXCODEC_JBIG2_JBIG2_CONTEXT_H_