// Copyright 2014 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #ifndef CORE_FXCODEC_JBIG2_JBIG2_CONTEXT_H_ #define CORE_FXCODEC_JBIG2_JBIG2_CONTEXT_H_ #include #include #include #include #include "core/fxcodec/fx_codec_def.h" #include "core/fxcodec/jbig2/JBig2_Page.h" #include "core/fxcodec/jbig2/JBig2_Segment.h" #include "core/fxcrt/fx_safe_types.h" #include "third_party/base/span.h" class CJBig2_ArithDecoder; class CJBig2_GRDProc; class CPDF_StreamAcc; class PauseIndicatorIface; // Cache is keyed by the ObjNum of a stream and an index within the stream. using CJBig2_CacheKey = std::pair; using CJBig2_CachePair = std::pair>; #define JBIG2_MIN_SEGMENT_SIZE 11 enum class JBig2_Result { kSuccess, kFailure, kEndReached }; class CJBig2_Context { public: static std::unique_ptr Create( pdfium::span pGlobalSpan, uint32_t dwGlobalObjNum, pdfium::span pSrcSpan, uint32_t dwSrcObjNum, std::list* pSymbolDictCache); ~CJBig2_Context(); static bool HuffmanAssignCode(JBig2HuffmanCode* SBSYMCODES, uint32_t NTEMP); bool GetFirstPage(uint8_t* pBuf, int32_t width, int32_t height, int32_t stride, PauseIndicatorIface* pPause); bool Continue(PauseIndicatorIface* pPause); FXCODEC_STATUS GetProcessingStatus() const { return m_ProcessingStatus; } private: CJBig2_Context(pdfium::span pSrcSpan, uint32_t dwObjNum, std::list* pSymbolDictCache, bool bIsGlobal); JBig2_Result DecodeSequential(PauseIndicatorIface* pPause); CJBig2_Segment* FindSegmentByNumber(uint32_t dwNumber); CJBig2_Segment* FindReferredTableSegmentByIndex(CJBig2_Segment* pSegment, int32_t nIndex); JBig2_Result ParseSegmentHeader(CJBig2_Segment* pSegment); JBig2_Result ParseSegmentData(CJBig2_Segment* pSegment, PauseIndicatorIface* pPause); JBig2_Result ProcessingParseSegmentData(CJBig2_Segment* pSegment, PauseIndicatorIface* pPause); JBig2_Result ParseSymbolDict(CJBig2_Segment* pSegment); JBig2_Result ParseTextRegion(CJBig2_Segment* pSegment); JBig2_Result ParsePatternDict(CJBig2_Segment* pSegment, PauseIndicatorIface* pPause); JBig2_Result ParseHalftoneRegion(CJBig2_Segment* pSegment, PauseIndicatorIface* pPause); JBig2_Result ParseGenericRegion(CJBig2_Segment* pSegment, PauseIndicatorIface* pPause); JBig2_Result ParseGenericRefinementRegion(CJBig2_Segment* pSegment); JBig2_Result ParseTable(CJBig2_Segment* pSegment); JBig2_Result ParseRegionInfo(JBig2RegionInfo* pRI); std::vector DecodeSymbolIDHuffmanTable(uint32_t SBNUMSYMS); const CJBig2_HuffmanTable* GetHuffmanTable(size_t idx); std::unique_ptr m_pGlobalContext; std::unique_ptr m_pStream; std::vector> m_SegmentList; std::vector> m_PageInfoList; std::unique_ptr m_pPage; std::vector> m_HuffmanTables; const bool m_bIsGlobal; bool m_bInPage = false; bool m_bBufSpecified = false; int32_t m_PauseStep = 10; FXCODEC_STATUS m_ProcessingStatus = FXCODEC_STATUS_FRAME_READY; std::vector m_gbContext; std::unique_ptr m_pArithDecoder; std::unique_ptr m_pGRD; std::unique_ptr m_pSegment; FX_SAFE_UINT32 m_dwOffset = 0; JBig2RegionInfo m_ri; std::list* const m_pSymbolDictCache; }; #endif // CORE_FXCODEC_JBIG2_JBIG2_CONTEXT_H_