summaryrefslogtreecommitdiff
path: root/core/fxcodec
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec')
-rw-r--r--core/fxcodec/codec/ccodec_jbig2module.h7
-rw-r--r--core/fxcodec/codec/fx_codec_jbig.cpp36
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp49
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.h43
4 files changed, 43 insertions, 92 deletions
diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/ccodec_jbig2module.h
index 63e63afcfa..5d77d53619 100644
--- a/core/fxcodec/codec/ccodec_jbig2module.h
+++ b/core/fxcodec/codec/ccodec_jbig2module.h
@@ -20,7 +20,7 @@ class IFX_Pause;
class CCodec_Jbig2Context {
public:
CCodec_Jbig2Context();
- ~CCodec_Jbig2Context() {}
+ ~CCodec_Jbig2Context();
uint32_t m_width;
uint32_t m_height;
@@ -29,8 +29,7 @@ class CCodec_Jbig2Context {
uint8_t* m_dest_buf;
uint32_t m_dest_pitch;
IFX_Pause* m_pPause;
- CJBig2_Context* m_pContext;
- CJBig2_Image* m_dest_image;
+ std::unique_ptr<CJBig2_Context> m_pContext;
};
class CCodec_Jbig2Module {
@@ -38,7 +37,6 @@ class CCodec_Jbig2Module {
CCodec_Jbig2Module() {}
~CCodec_Jbig2Module();
- CCodec_Jbig2Context* CreateJbig2Context();
FXCODEC_STATUS StartDecode(CCodec_Jbig2Context* pJbig2Context,
std::unique_ptr<CFX_Deletable>* pContextHolder,
uint32_t width,
@@ -50,7 +48,6 @@ class CCodec_Jbig2Module {
IFX_Pause* pPause);
FXCODEC_STATUS ContinueDecode(CCodec_Jbig2Context* pJbig2Context,
IFX_Pause* pPause);
- void DestroyJbig2Context(CCodec_Jbig2Context* pJbig2Context);
};
#endif // CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_
diff --git a/core/fxcodec/codec/fx_codec_jbig.cpp b/core/fxcodec/codec/fx_codec_jbig.cpp
index 4876cef53d..8f2d07f490 100644
--- a/core/fxcodec/codec/fx_codec_jbig.cpp
+++ b/core/fxcodec/codec/fx_codec_jbig.cpp
@@ -37,24 +37,18 @@ JBig2DocumentContext* GetJBig2DocumentContext(
return static_cast<JBig2DocumentContext*>(pContextHolder->get());
}
-CCodec_Jbig2Context::CCodec_Jbig2Context() {
- FXSYS_memset(this, 0, sizeof(CCodec_Jbig2Context));
-}
-
-CCodec_Jbig2Module::~CCodec_Jbig2Module() {}
+CCodec_Jbig2Context::CCodec_Jbig2Context()
+ : m_width(0),
+ m_height(0),
+ m_pGlobalStream(nullptr),
+ m_pSrcStream(nullptr),
+ m_dest_buf(0),
+ m_dest_pitch(0),
+ m_pPause(nullptr) {}
-CCodec_Jbig2Context* CCodec_Jbig2Module::CreateJbig2Context() {
- return new CCodec_Jbig2Context();
-}
+CCodec_Jbig2Context::~CCodec_Jbig2Context() {}
-void CCodec_Jbig2Module::DestroyJbig2Context(
- CCodec_Jbig2Context* pJbig2Context) {
- if (pJbig2Context) {
- CJBig2_Context::DestroyContext(pJbig2Context->m_pContext);
- delete pJbig2Context;
- }
- pJbig2Context = nullptr;
-}
+CCodec_Jbig2Module::~CCodec_Jbig2Module() {}
FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(
CCodec_Jbig2Context* pJbig2Context,
@@ -79,9 +73,9 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(
pJbig2Context->m_dest_pitch = dest_pitch;
pJbig2Context->m_pPause = pPause;
FXSYS_memset(dest_buf, 0, height * dest_pitch);
- pJbig2Context->m_pContext = CJBig2_Context::CreateContext(
+ pJbig2Context->m_pContext.reset(new CJBig2_Context(
global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(),
- pPause);
+ pPause, false));
if (!pJbig2Context->m_pContext)
return FXCODEC_STATUS_ERROR;
@@ -89,8 +83,7 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(
dest_pitch, pPause);
if (pJbig2Context->m_pContext->GetProcessingStatus() ==
FXCODEC_STATUS_DECODE_FINISH) {
- CJBig2_Context::DestroyContext(pJbig2Context->m_pContext);
- pJbig2Context->m_pContext = nullptr;
+ pJbig2Context->m_pContext.reset();
if (ret != JBIG2_SUCCESS)
return FXCODEC_STATUS_ERROR;
@@ -111,8 +104,7 @@ FXCODEC_STATUS CCodec_Jbig2Module::ContinueDecode(
FXCODEC_STATUS_DECODE_FINISH) {
return pJbig2Context->m_pContext->GetProcessingStatus();
}
- CJBig2_Context::DestroyContext(pJbig2Context->m_pContext);
- pJbig2Context->m_pContext = nullptr;
+ pJbig2Context->m_pContext.reset();
if (ret != JBIG2_SUCCESS)
return FXCODEC_STATUS_ERROR;
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 8dde290be6..1e4c35a625 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -45,19 +45,6 @@ size_t GetRefAggContextSize(FX_BOOL val) {
// difference for typical JBIG2 documents.
static const int kSymbolDictCacheMaxSize = 2;
-CJBig2_Context* CJBig2_Context::CreateContext(
- CPDF_StreamAcc* pGlobalStream,
- CPDF_StreamAcc* pSrcStream,
- std::list<CJBig2_CachePair>* pSymbolDictCache,
- IFX_Pause* pPause) {
- return new CJBig2_Context(pGlobalStream, pSrcStream, pSymbolDictCache, pPause,
- false);
-}
-
-void CJBig2_Context::DestroyContext(CJBig2_Context* pContext) {
- delete pContext;
-}
-
CJBig2_Context::CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
CPDF_StreamAcc* pSrcStream,
std::list<CJBig2_CachePair>* pSymbolDictCache,
@@ -69,26 +56,17 @@ CJBig2_Context::CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
m_PauseStep(10),
m_pPause(pPause),
m_ProcessingStatus(FXCODEC_STATUS_FRAME_READY),
- m_gbContext(nullptr),
m_dwOffset(0),
m_pSymbolDictCache(pSymbolDictCache),
m_bIsGlobal(bIsGlobal) {
if (pGlobalStream && (pGlobalStream->GetSize() > 0)) {
- m_pGlobalContext = new CJBig2_Context(nullptr, pGlobalStream,
- pSymbolDictCache, pPause, true);
- } else {
- m_pGlobalContext = nullptr;
+ m_pGlobalContext.reset(new CJBig2_Context(nullptr, pGlobalStream,
+ pSymbolDictCache, pPause, true));
}
-
m_pStream.reset(new CJBig2_BitStream(pSrcStream));
}
-CJBig2_Context::~CJBig2_Context() {
- FX_Free(m_gbContext);
- m_gbContext = nullptr;
- delete m_pGlobalContext;
- m_pGlobalContext = nullptr;
-}
+CJBig2_Context::~CJBig2_Context() {}
int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) {
int32_t nRet;
@@ -135,9 +113,11 @@ int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) {
}
return JBIG2_SUCCESS;
}
+
int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) {
return decode_SquentialOrgnazation(pPause);
}
+
int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) {
int32_t nRet;
while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) {
@@ -158,6 +138,7 @@ int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) {
m_nSegmentDecoded = 0;
return decode_RandomOrgnazation(pPause);
}
+
int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) {
for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) {
int32_t nRet =
@@ -176,6 +157,7 @@ int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) {
}
return JBIG2_SUCCESS;
}
+
int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf,
int32_t width,
int32_t height,
@@ -199,6 +181,7 @@ int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf,
}
return Continue(pPause);
}
+
int32_t CJBig2_Context::Continue(IFX_Pause* pPause) {
m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY;
int32_t nRet = 0;
@@ -245,6 +228,7 @@ CJBig2_Segment* CJBig2_Context::findSegmentByNumber(uint32_t dwNumber) {
}
return nullptr;
}
+
CJBig2_Segment* CJBig2_Context::findReferredSegmentByTypeAndIndex(
CJBig2_Segment* pSegment,
uint8_t cType,
@@ -261,6 +245,7 @@ CJBig2_Segment* CJBig2_Context::findReferredSegmentByTypeAndIndex(
}
return nullptr;
}
+
int32_t CJBig2_Context::parseSegmentHeader(CJBig2_Segment* pSegment) {
if (m_pStream->readInteger(&pSegment->m_dwNumber) != 0 ||
m_pStream->read1Byte(&pSegment->m_cFlags.c) != 0) {
@@ -1106,15 +1091,15 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
}
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
if (m_pGRD->MMR == 0) {
- if (!m_gbContext) {
+ if (m_gbContext.empty()) {
const size_t size = GetHuffContextSize(m_pGRD->GBTEMPLATE);
- m_gbContext = FX_Alloc(JBig2ArithCtx, size);
- JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * size);
+ m_gbContext.resize(size);
}
if (!m_pArithDecoder) {
m_pArithDecoder.reset(new CJBig2_ArithDecoder(m_pStream.get()));
- m_ProcessingStatus = m_pGRD->Start_decode_Arith(
- &pSegment->m_Result.im, m_pArithDecoder.get(), m_gbContext, pPause);
+ m_ProcessingStatus = m_pGRD->Start_decode_Arith(&pSegment->m_Result.im,
+ m_pArithDecoder.get(),
+ &m_gbContext[0], pPause);
} else {
m_ProcessingStatus = m_pGRD->Continue_decode(pPause);
}
@@ -1136,8 +1121,7 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
return JBIG2_SUCCESS;
} else {
m_pArithDecoder.reset();
- FX_Free(m_gbContext);
- m_gbContext = nullptr;
+ m_gbContext.clear();
if (!pSegment->m_Result.im) {
m_ProcessingStatus = FXCODEC_STATUS_ERROR;
m_pGRD.reset();
@@ -1373,6 +1357,7 @@ void CJBig2_Context::huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP) {
FX_Free(LENCOUNT);
FX_Free(FIRSTCODE);
}
+
void CJBig2_Context::huffman_assign_code(JBig2HuffmanCode* SBSYMCODES,
int NTEMP) {
int CURLEN, LENMAX, CURCODE, CURTEMP, i;
diff --git a/core/fxcodec/jbig2/JBig2_Context.h b/core/fxcodec/jbig2/JBig2_Context.h
index 950ad130d7..1577b22d37 100644
--- a/core/fxcodec/jbig2/JBig2_Context.h
+++ b/core/fxcodec/jbig2/JBig2_Context.h
@@ -10,6 +10,7 @@
#include <list>
#include <memory>
#include <utility>
+#include <vector>
#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
#include "core/fxcodec/include/fx_codec_def.h"
@@ -40,13 +41,12 @@ using CJBig2_CachePair = std::pair<CJBig2_CacheKey, CJBig2_SymbolDict*>;
class CJBig2_Context {
public:
- static CJBig2_Context* CreateContext(
- CPDF_StreamAcc* pGlobalStream,
- CPDF_StreamAcc* pSrcStream,
- std::list<CJBig2_CachePair>* pSymbolDictCache,
- IFX_Pause* pPause = nullptr);
-
- static void DestroyContext(CJBig2_Context* pContext);
+ CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
+ CPDF_StreamAcc* pSrcStream,
+ std::list<CJBig2_CachePair>* pSymbolDictCache,
+ IFX_Pause* pPause,
+ bool bIsGlobal);
+ ~CJBig2_Context();
int32_t getFirstPage(uint8_t* pBuf,
int32_t width,
@@ -58,59 +58,36 @@ class CJBig2_Context {
FXCODEC_STATUS GetProcessingStatus() { return m_ProcessingStatus; }
private:
- CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
- CPDF_StreamAcc* pSrcStream,
- std::list<CJBig2_CachePair>* pSymbolDictCache,
- IFX_Pause* pPause,
- bool bIsGlobal);
-
- ~CJBig2_Context();
-
int32_t decode_SquentialOrgnazation(IFX_Pause* pPause);
-
int32_t decode_EmbedOrgnazation(IFX_Pause* pPause);
-
int32_t decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause);
-
int32_t decode_RandomOrgnazation(IFX_Pause* pPause);
CJBig2_Segment* findSegmentByNumber(uint32_t dwNumber);
-
CJBig2_Segment* findReferredSegmentByTypeAndIndex(CJBig2_Segment* pSegment,
uint8_t cType,
int32_t nIndex);
int32_t parseSegmentHeader(CJBig2_Segment* pSegment);
-
int32_t parseSegmentData(CJBig2_Segment* pSegment, IFX_Pause* pPause);
int32_t ProcessingParseSegmentData(CJBig2_Segment* pSegment,
IFX_Pause* pPause);
-
int32_t parseSymbolDict(CJBig2_Segment* pSegment, IFX_Pause* pPause);
-
int32_t parseTextRegion(CJBig2_Segment* pSegment);
-
int32_t parsePatternDict(CJBig2_Segment* pSegment, IFX_Pause* pPause);
-
int32_t parseHalftoneRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause);
-
int32_t parseGenericRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause);
-
int32_t parseGenericRefinementRegion(CJBig2_Segment* pSegment);
-
int32_t parseTable(CJBig2_Segment* pSegment);
-
int32_t parseRegionInfo(JBig2RegionInfo* pRI);
JBig2HuffmanCode* decodeSymbolIDHuffmanTable(CJBig2_BitStream* pStream,
uint32_t SBNUMSYMS);
void huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP);
-
void huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, int NTEMP);
- private:
- CJBig2_Context* m_pGlobalContext;
+ std::unique_ptr<CJBig2_Context> m_pGlobalContext;
std::unique_ptr<CJBig2_BitStream> m_pStream;
CJBig2_List<CJBig2_Segment> m_SegmentList;
CJBig2_List<JBig2PageInfo> m_PageInfoList;
@@ -119,11 +96,11 @@ class CJBig2_Context {
bool m_bInPage;
bool m_bBufSpecified;
int32_t m_PauseStep;
- IFX_Pause* m_pPause;
+ IFX_Pause* const m_pPause;
FXCODEC_STATUS m_ProcessingStatus;
+ std::vector<JBig2ArithCtx> m_gbContext;
std::unique_ptr<CJBig2_ArithDecoder> m_pArithDecoder;
std::unique_ptr<CJBig2_GRDProc> m_pGRD;
- JBig2ArithCtx* m_gbContext;
std::unique_ptr<CJBig2_Segment> m_pSegment;
uint32_t m_dwOffset;
JBig2RegionInfo m_ri;