summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-07-19 16:06:10 -0700
committerCommit bot <commit-bot@chromium.org>2016-07-19 16:06:10 -0700
commit8ca60b2cda3efc112c987c1d57d1eb8568667da9 (patch)
treeb9170a729249b4f4aa8751e2f713afed77fca15b /core/fxcodec/jbig2
parent5b36f0a0eff7f3666a0e642640db3c89e4bb6748 (diff)
downloadpdfium-8ca60b2cda3efc112c987c1d57d1eb8568667da9.tar.xz
Use smart pointers for various Jbig2 decoding contexts
Use unique_ptr for class owned member variables, and remove unnecessary or unused functions and member variable. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2149903002
Diffstat (limited to 'core/fxcodec/jbig2')
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp49
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.h43
2 files changed, 27 insertions, 65 deletions
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;