summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-09-10 16:34:17 -0700
committerLei Zhang <thestig@chromium.org>2015-09-10 16:34:17 -0700
commita7f5386053136db6d41b1fc4943544ec623704c3 (patch)
tree3c8e8345078b166fcbd55bd2f258de98146e00b3 /core
parent808a99e8c6f72713ca9492508faa4b8445ae0d33 (diff)
downloadpdfium-a7f5386053136db6d41b1fc4943544ec623704c3.tar.xz
Merge to XFA: Make a bunch of JBig2 classes independent of CJBig2_Object.
TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1319713003 . (cherry picked from commit 800bf5ac07305ccf9c9522c8c76f728a4fd99da5) Review URL: https://codereview.chromium.org/1332153002 .
Diffstat (limited to 'core')
-rw-r--r--core/src/fxcodec/jbig2/JBig2_ArithDecoder.h13
-rw-r--r--core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp13
-rw-r--r--core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.h4
-rw-r--r--core/src/fxcodec/jbig2/JBig2_BitStream.h4
-rw-r--r--core/src/fxcodec/jbig2/JBig2_Context.cpp318
-rw-r--r--core/src/fxcodec/jbig2/JBig2_Context.h38
-rw-r--r--core/src/fxcodec/jbig2/JBig2_GeneralDecoder.cpp199
-rw-r--r--core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h2
-rw-r--r--core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp65
-rw-r--r--core/src/fxcodec/jbig2/JBig2_HuffmanTable.h2
-rw-r--r--core/src/fxcodec/jbig2/JBig2_List.h43
-rw-r--r--core/src/fxcodec/jbig2/JBig2_Page.h13
-rw-r--r--core/src/fxcodec/jbig2/JBig2_PatternDict.cpp5
-rw-r--r--core/src/fxcodec/jbig2/JBig2_PatternDict.h3
-rw-r--r--core/src/fxcodec/jbig2/JBig2_Segment.cpp43
-rw-r--r--core/src/fxcodec/jbig2/JBig2_Segment.h5
16 files changed, 346 insertions, 424 deletions
diff --git a/core/src/fxcodec/jbig2/JBig2_ArithDecoder.h b/core/src/fxcodec/jbig2/JBig2_ArithDecoder.h
index 0258014927..7acfe9cd36 100644
--- a/core/src/fxcodec/jbig2/JBig2_ArithDecoder.h
+++ b/core/src/fxcodec/jbig2/JBig2_ArithDecoder.h
@@ -9,13 +9,15 @@
#include "JBig2_Define.h"
#include "JBig2_BitStream.h"
#include "JBig2_ArithQe.h"
-typedef struct {
+
+struct JBig2ArithCtx {
unsigned int MPS;
unsigned int I;
-} JBig2ArithCtx;
-class CJBig2_ArithDecoder : public CJBig2_Object {
+};
+
+class CJBig2_ArithDecoder {
public:
- CJBig2_ArithDecoder(CJBig2_BitStream* pStream);
+ explicit CJBig2_ArithDecoder(CJBig2_BitStream* pStream);
~CJBig2_ArithDecoder();
@@ -23,14 +25,15 @@ class CJBig2_ArithDecoder : public CJBig2_Object {
private:
void INITDEC();
-
void BYTEIN();
+
unsigned char B;
unsigned int C;
unsigned int A;
unsigned int CT;
CJBig2_BitStream* m_pStream;
};
+
inline CJBig2_ArithDecoder::CJBig2_ArithDecoder(CJBig2_BitStream* pStream) {
m_pStream = pStream;
INITDEC();
diff --git a/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp b/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
index 3aab2fb3e6..d12ab5a2e8 100644
--- a/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
+++ b/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
@@ -5,12 +5,15 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "JBig2_ArithIntDecoder.h"
+
+#include "../../../include/fxcrt/fx_memory.h"
+
CJBig2_ArithIntDecoder::CJBig2_ArithIntDecoder() {
- IAx = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), 512);
+ IAx = (JBig2ArithCtx*)FX_AllocOrDie(sizeof(JBig2ArithCtx), 512);
JBIG2_memset(IAx, 0, sizeof(JBig2ArithCtx) * 512);
}
CJBig2_ArithIntDecoder::~CJBig2_ArithIntDecoder() {
- m_pModule->JBig2_Free(IAx);
+ FX_Free(IAx);
}
int CJBig2_ArithIntDecoder::decode(CJBig2_ArithDecoder* pArithDecoder,
int* nResult) {
@@ -79,12 +82,12 @@ int CJBig2_ArithIntDecoder::decode(CJBig2_ArithDecoder* pArithDecoder,
}
CJBig2_ArithIaidDecoder::CJBig2_ArithIaidDecoder(unsigned char SBSYMCODELENA) {
SBSYMCODELEN = SBSYMCODELENA;
- IAID = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx),
- (1 << SBSYMCODELEN));
+ IAID =
+ (JBig2ArithCtx*)FX_AllocOrDie(sizeof(JBig2ArithCtx), (1 << SBSYMCODELEN));
JBIG2_memset(IAID, 0, sizeof(JBig2ArithCtx) * (int)(1 << SBSYMCODELEN));
}
CJBig2_ArithIaidDecoder::~CJBig2_ArithIaidDecoder() {
- m_pModule->JBig2_Free(IAID);
+ FX_Free(IAID);
}
int CJBig2_ArithIaidDecoder::decode(CJBig2_ArithDecoder* pArithDecoder,
int* nResult) {
diff --git a/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.h b/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.h
index d024e7150f..4bcaa1b8a5 100644
--- a/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.h
+++ b/core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.h
@@ -8,7 +8,7 @@
#define _JBIG2_ARITH_INT_DECODER_H_
#include "JBig2_Module.h"
#include "JBig2_ArithDecoder.h"
-class CJBig2_ArithIntDecoder : public CJBig2_Object {
+class CJBig2_ArithIntDecoder {
public:
CJBig2_ArithIntDecoder();
@@ -19,7 +19,7 @@ class CJBig2_ArithIntDecoder : public CJBig2_Object {
private:
JBig2ArithCtx* IAx;
};
-class CJBig2_ArithIaidDecoder : public CJBig2_Object {
+class CJBig2_ArithIaidDecoder {
public:
CJBig2_ArithIaidDecoder(unsigned char SBSYMCODELENA);
diff --git a/core/src/fxcodec/jbig2/JBig2_BitStream.h b/core/src/fxcodec/jbig2/JBig2_BitStream.h
index c74964473c..78a9dfe677 100644
--- a/core/src/fxcodec/jbig2/JBig2_BitStream.h
+++ b/core/src/fxcodec/jbig2/JBig2_BitStream.h
@@ -6,8 +6,10 @@
#ifndef _JBIG2_BIT_STREAM_H_
#define _JBIG2_BIT_STREAM_H_
+
#include "JBig2_Define.h"
-class CJBig2_BitStream : public CJBig2_Object {
+
+class CJBig2_BitStream {
public:
CJBig2_BitStream(uint8_t* pBuffer, FX_DWORD dwLength);
diff --git a/core/src/fxcodec/jbig2/JBig2_Context.cpp b/core/src/fxcodec/jbig2/JBig2_Context.cpp
index c66c2ebaea..46ed6f081e 100644
--- a/core/src/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/src/fxcodec/jbig2/JBig2_Context.cpp
@@ -4,7 +4,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include <map>
#include <list>
#include "JBig2_Context.h"
@@ -47,11 +46,9 @@ CJBig2_Context::CJBig2_Context(uint8_t* pGlobalData,
} else {
m_pGlobalContext = NULL;
}
- JBIG2_ALLOC(m_pStream, CJBig2_BitStream(pData, dwLength));
+ m_pStream = new CJBig2_BitStream(pData, dwLength);
m_nStreamType = nStreamType;
m_nState = JBIG2_OUT_OF_PAGE;
- JBIG2_ALLOC(m_pSegmentList, CJBig2_List<CJBig2_Segment>);
- JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(1));
m_pPage = NULL;
m_bBufSpecified = FALSE;
m_pPause = pPause;
@@ -60,7 +57,6 @@ CJBig2_Context::CJBig2_Context(uint8_t* pGlobalData,
m_pArithDecoder = NULL;
m_pGRD = NULL;
m_gbContext = NULL;
- m_pSegment = NULL;
m_dwOffset = 0;
m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY;
m_pSymbolDictCache = pSymbolDictCache;
@@ -76,16 +72,12 @@ CJBig2_Context::~CJBig2_Context() {
m_gbContext = NULL;
delete m_pGlobalContext;
m_pGlobalContext = NULL;
- delete m_pPageInfoList;
- m_pPageInfoList = NULL;
if (m_bBufSpecified) {
delete m_pPage;
}
m_pPage = NULL;
delete m_pStream;
m_pStream = NULL;
- delete m_pSegmentList;
- m_pSegmentList = NULL;
}
int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) {
uint8_t cFlags;
@@ -115,8 +107,8 @@ int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) {
goto failed;
}
if (dwTemp > 0) {
- delete m_pPageInfoList;
- JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(dwTemp));
+ m_PageInfoList.clear();
+ m_PageInfoList.resize(dwTemp);
}
}
if (cFlags & 0x01) {
@@ -131,50 +123,46 @@ failed:
}
int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) {
int32_t nRet;
- if (m_pStream->getByteLeft() > 0) {
- while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) {
- if (m_pSegment == NULL) {
- JBIG2_ALLOC(m_pSegment, CJBig2_Segment());
- nRet = parseSegmentHeader(m_pSegment);
- if (nRet != JBIG2_SUCCESS) {
- delete m_pSegment;
- m_pSegment = NULL;
- return nRet;
- }
- m_dwOffset = m_pStream->getOffset();
- }
- nRet = parseSegmentData(m_pSegment, pPause);
- if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
- m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
- m_PauseStep = 2;
- return JBIG2_SUCCESS;
- }
- if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) {
- delete m_pSegment;
- m_pSegment = NULL;
- break;
- } else if (nRet != JBIG2_SUCCESS) {
- delete m_pSegment;
- m_pSegment = NULL;
+ if (m_pStream->getByteLeft() <= 0)
+ return JBIG2_END_OF_FILE;
+
+ while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) {
+ if (!m_pSegment) {
+ m_pSegment.reset(new CJBig2_Segment);
+ nRet = parseSegmentHeader(m_pSegment.get());
+ if (nRet != JBIG2_SUCCESS) {
+ m_pSegment.reset();
return nRet;
}
- m_pSegmentList->addItem(m_pSegment);
- if (m_pSegment->m_dwData_length != 0xffffffff) {
- m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length;
- m_pStream->setOffset(m_dwOffset);
- } else {
- m_pStream->offset(4);
- }
- m_pSegment = NULL;
- if (m_pStream->getByteLeft() > 0 && m_pPage && pPause &&
- pPause->NeedToPauseNow()) {
- m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
- m_PauseStep = 2;
- return JBIG2_SUCCESS;
- }
+ m_dwOffset = m_pStream->getOffset();
+ }
+ nRet = parseSegmentData(m_pSegment.get(), pPause);
+ if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
+ m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ m_PauseStep = 2;
+ return JBIG2_SUCCESS;
+ }
+ if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) {
+ m_pSegment.reset();
+ return JBIG2_SUCCESS;
+ }
+ if (nRet != JBIG2_SUCCESS) {
+ m_pSegment.reset();
+ return nRet;
+ }
+ if (m_pSegment->m_dwData_length != 0xffffffff) {
+ m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length;
+ m_pStream->setOffset(m_dwOffset);
+ } else {
+ m_pStream->offset(4);
+ }
+ m_SegmentList.push_back(m_pSegment.release());
+ if (m_pStream->getByteLeft() > 0 && m_pPage && pPause &&
+ pPause->NeedToPauseNow()) {
+ m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ m_PauseStep = 2;
+ return JBIG2_SUCCESS;
}
- } else {
- return JBIG2_END_OF_FILE;
}
return JBIG2_SUCCESS;
}
@@ -182,19 +170,16 @@ int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) {
return decode_SquentialOrgnazation(pPause);
}
int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) {
- CJBig2_Segment* pSegment;
int32_t nRet;
while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) {
- JBIG2_ALLOC(pSegment, CJBig2_Segment());
- nRet = parseSegmentHeader(pSegment);
+ nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment);
+ nRet = parseSegmentHeader(pSegment.get());
if (nRet != JBIG2_SUCCESS) {
- delete pSegment;
return nRet;
} else if (pSegment->m_cFlags.s.type == 51) {
- delete pSegment;
break;
}
- m_pSegmentList->addItem(pSegment);
+ m_SegmentList.push_back(pSegment.release());
if (pPause && m_pPause && pPause->NeedToPauseNow()) {
m_PauseStep = 3;
m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -205,14 +190,15 @@ int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) {
return decode_RandomOrgnazation(pPause);
}
int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) {
- int32_t nRet;
- for (; m_nSegmentDecoded < m_pSegmentList->getLength(); m_nSegmentDecoded++) {
- nRet = parseSegmentData(m_pSegmentList->getAt(m_nSegmentDecoded), pPause);
- if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) {
- break;
- } else if (nRet != JBIG2_SUCCESS) {
+ for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) {
+ int32_t nRet =
+ parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause);
+ if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE))
+ return JBIG2_SUCCESS;
+
+ if (nRet != JBIG2_SUCCESS)
return nRet;
- }
+
if (m_pPage && pPause && pPause->NeedToPauseNow()) {
m_PauseStep = 4;
m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -312,20 +298,19 @@ int32_t CJBig2_Context::getFirstPage(CJBig2_Image** image, IFX_Pause* pPause) {
}
CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) {
CJBig2_Segment* pSeg;
- int32_t i;
if (m_pGlobalContext) {
pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber);
if (pSeg) {
return pSeg;
}
}
- for (i = 0; i < m_pSegmentList->getLength(); i++) {
- pSeg = m_pSegmentList->getAt(i);
+ for (size_t i = 0; i < m_SegmentList.size(); ++i) {
+ pSeg = m_SegmentList.get(i);
if (pSeg->m_dwNumber == dwNumber) {
return pSeg;
}
}
- return NULL;
+ return nullptr;
}
CJBig2_Segment* CJBig2_Context::findReferredSegmentByTypeAndIndex(
CJBig2_Segment* pSegment,
@@ -480,23 +465,21 @@ int32_t CJBig2_Context::ProcessiveParseSegmentData(CJBig2_Segment* pSegment,
}
case 48: {
FX_WORD wTemp;
- JBig2PageInfo* pPageInfo;
- JBIG2_ALLOC(pPageInfo, JBig2PageInfo);
+ nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo);
if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) ||
(m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) ||
(m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) ||
(m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) ||
(m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) ||
(m_pStream->readShortInteger(&wTemp) != 0)) {
- delete pPageInfo;
goto failed1;
}
pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0;
pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff;
if ((pPageInfo->m_dwHeight == 0xffffffff) &&
- (pPageInfo->m_bIsStriped != 1)) {
+ (pPageInfo->m_bIsStriped != TRUE)) {
m_pModule->JBig2_Warn("page height = 0xffffffff buf stripe field is 0");
- pPageInfo->m_bIsStriped = 1;
+ pPageInfo->m_bIsStriped = TRUE;
}
if (!m_bBufSpecified) {
delete m_pPage;
@@ -509,7 +492,7 @@ int32_t CJBig2_Context::ProcessiveParseSegmentData(CJBig2_Segment* pSegment,
}
}
m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0);
- m_pPageInfoList->addItem(pPageInfo);
+ m_PageInfoList.push_back(pPageInfo.release());
m_nState = JBIG2_IN_PAGE;
} break;
case 49:
@@ -653,16 +636,14 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
}
nIndex = 0;
if (cSDHUFFDH == 0) {
- JBIG2_ALLOC(Table_B4, CJBig2_HuffmanTable(HuffmanTable_B4,
- sizeof(HuffmanTable_B4) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B4));
+ Table_B4 = new CJBig2_HuffmanTable(HuffmanTable_B4,
+ FX_ArraySize(HuffmanTable_B4),
+ HuffmanTable_HTOOB_B4);
pSymbolDictDecoder->SDHUFFDH = Table_B4;
} else if (cSDHUFFDH == 1) {
- JBIG2_ALLOC(Table_B5, CJBig2_HuffmanTable(HuffmanTable_B5,
- sizeof(HuffmanTable_B5) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B5));
+ Table_B5 = new CJBig2_HuffmanTable(HuffmanTable_B5,
+ FX_ArraySize(HuffmanTable_B5),
+ HuffmanTable_HTOOB_B5);
pSymbolDictDecoder->SDHUFFDH = Table_B5;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -676,16 +657,14 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
pSymbolDictDecoder->SDHUFFDH = pSeg->m_Result.ht;
}
if (cSDHUFFDW == 0) {
- JBIG2_ALLOC(Table_B2, CJBig2_HuffmanTable(HuffmanTable_B2,
- sizeof(HuffmanTable_B2) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B2));
+ Table_B2 = new CJBig2_HuffmanTable(HuffmanTable_B2,
+ FX_ArraySize(HuffmanTable_B2),
+ HuffmanTable_HTOOB_B2);
pSymbolDictDecoder->SDHUFFDW = Table_B2;
} else if (cSDHUFFDW == 1) {
- JBIG2_ALLOC(Table_B3, CJBig2_HuffmanTable(HuffmanTable_B3,
- sizeof(HuffmanTable_B3) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B3));
+ Table_B3 = new CJBig2_HuffmanTable(HuffmanTable_B3,
+ FX_ArraySize(HuffmanTable_B3),
+ HuffmanTable_HTOOB_B3);
pSymbolDictDecoder->SDHUFFDW = Table_B3;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -699,10 +678,9 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
pSymbolDictDecoder->SDHUFFDW = pSeg->m_Result.ht;
}
if (cSDHUFFBMSIZE == 0) {
- JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1,
- sizeof(HuffmanTable_B1) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B1));
+ Table_B1 = new CJBig2_HuffmanTable(HuffmanTable_B1,
+ FX_ArraySize(HuffmanTable_B1),
+ HuffmanTable_HTOOB_B1);
pSymbolDictDecoder->SDHUFFBMSIZE = Table_B1;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -718,10 +696,9 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
if (pSymbolDictDecoder->SDREFAGG == 1) {
if (cSDHUFFAGGINST == 0) {
if (!Table_B1) {
- JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1,
- sizeof(HuffmanTable_B1) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B1));
+ Table_B1 = new CJBig2_HuffmanTable(HuffmanTable_B1,
+ FX_ArraySize(HuffmanTable_B1),
+ HuffmanTable_HTOOB_B1);
}
pSymbolDictDecoder->SDHUFFAGGINST = Table_B1;
} else {
@@ -783,7 +760,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
}
if (!cache_hit) {
if (pSymbolDictDecoder->SDHUFF == 0) {
- JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream));
+ pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
pSegment->m_Result.sd =
pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext);
delete pArithDecoder;
@@ -987,16 +964,14 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
}
nIndex = 0;
if (cSBHUFFFS == 0) {
- JBIG2_ALLOC(Table_B6, CJBig2_HuffmanTable(HuffmanTable_B6,
- sizeof(HuffmanTable_B6) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B6));
+ Table_B6 = new CJBig2_HuffmanTable(HuffmanTable_B6,
+ FX_ArraySize(HuffmanTable_B6),
+ HuffmanTable_HTOOB_B6);
pTRD->SBHUFFFS = Table_B6;
} else if (cSBHUFFFS == 1) {
- JBIG2_ALLOC(Table_B7, CJBig2_HuffmanTable(HuffmanTable_B7,
- sizeof(HuffmanTable_B7) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B7));
+ Table_B7 = new CJBig2_HuffmanTable(HuffmanTable_B7,
+ FX_ArraySize(HuffmanTable_B7),
+ HuffmanTable_HTOOB_B7);
pTRD->SBHUFFFS = Table_B7;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -1009,22 +984,19 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFFS = pSeg->m_Result.ht;
}
if (cSBHUFFDS == 0) {
- JBIG2_ALLOC(Table_B8, CJBig2_HuffmanTable(HuffmanTable_B8,
- sizeof(HuffmanTable_B8) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B8));
+ Table_B8 = new CJBig2_HuffmanTable(HuffmanTable_B8,
+ FX_ArraySize(HuffmanTable_B8),
+ HuffmanTable_HTOOB_B8);
pTRD->SBHUFFDS = Table_B8;
} else if (cSBHUFFDS == 1) {
- JBIG2_ALLOC(Table_B9, CJBig2_HuffmanTable(HuffmanTable_B9,
- sizeof(HuffmanTable_B9) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B9));
+ Table_B9 = new CJBig2_HuffmanTable(HuffmanTable_B9,
+ FX_ArraySize(HuffmanTable_B9),
+ HuffmanTable_HTOOB_B9);
pTRD->SBHUFFDS = Table_B9;
} else if (cSBHUFFDS == 2) {
- JBIG2_ALLOC(Table_B10, CJBig2_HuffmanTable(HuffmanTable_B10,
- sizeof(HuffmanTable_B10) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B10));
+ Table_B10 = new CJBig2_HuffmanTable(HuffmanTable_B10,
+ FX_ArraySize(HuffmanTable_B10),
+ HuffmanTable_HTOOB_B10);
pTRD->SBHUFFDS = Table_B10;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -1037,22 +1009,19 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFDS = pSeg->m_Result.ht;
}
if (cSBHUFFDT == 0) {
- JBIG2_ALLOC(Table_B11, CJBig2_HuffmanTable(HuffmanTable_B11,
- sizeof(HuffmanTable_B11) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B11));
+ Table_B11 = new CJBig2_HuffmanTable(HuffmanTable_B11,
+ FX_ArraySize(HuffmanTable_B11),
+ HuffmanTable_HTOOB_B11);
pTRD->SBHUFFDT = Table_B11;
} else if (cSBHUFFDT == 1) {
- JBIG2_ALLOC(Table_B12, CJBig2_HuffmanTable(HuffmanTable_B12,
- sizeof(HuffmanTable_B12) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B12));
+ Table_B12 = new CJBig2_HuffmanTable(HuffmanTable_B12,
+ FX_ArraySize(HuffmanTable_B12),
+ HuffmanTable_HTOOB_B12);
pTRD->SBHUFFDT = Table_B12;
} else if (cSBHUFFDT == 2) {
- JBIG2_ALLOC(Table_B13, CJBig2_HuffmanTable(HuffmanTable_B13,
- sizeof(HuffmanTable_B13) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B13));
+ Table_B13 = new CJBig2_HuffmanTable(HuffmanTable_B13,
+ FX_ArraySize(HuffmanTable_B13),
+ HuffmanTable_HTOOB_B13);
pTRD->SBHUFFDT = Table_B13;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -1065,16 +1034,14 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFDT = pSeg->m_Result.ht;
}
if (cSBHUFFRDW == 0) {
- JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14,
- sizeof(HuffmanTable_B14) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B14));
+ Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14,
+ FX_ArraySize(HuffmanTable_B14),
+ HuffmanTable_HTOOB_B14);
pTRD->SBHUFFRDW = Table_B14;
} else if (cSBHUFFRDW == 1) {
- JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
+ Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
pTRD->SBHUFFRDW = Table_B15;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -1088,18 +1055,16 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
}
if (cSBHUFFRDH == 0) {
if (!Table_B14) {
- JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14,
- sizeof(HuffmanTable_B14) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B14));
+ Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14,
+ FX_ArraySize(HuffmanTable_B14),
+ HuffmanTable_HTOOB_B14);
}
pTRD->SBHUFFRDH = Table_B14;
} else if (cSBHUFFRDH == 1) {
if (!Table_B15) {
- JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
+ Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
}
pTRD->SBHUFFRDH = Table_B15;
} else {
@@ -1114,18 +1079,16 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
}
if (cSBHUFFRDX == 0) {
if (!Table_B14) {
- JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14,
- sizeof(HuffmanTable_B14) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B14));
+ Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14,
+ FX_ArraySize(HuffmanTable_B14),
+ HuffmanTable_HTOOB_B14);
}
pTRD->SBHUFFRDX = Table_B14;
} else if (cSBHUFFRDX == 1) {
if (!Table_B15) {
- JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
+ Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
}
pTRD->SBHUFFRDX = Table_B15;
} else {
@@ -1140,18 +1103,16 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
}
if (cSBHUFFRDY == 0) {
if (!Table_B14) {
- JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14,
- sizeof(HuffmanTable_B14) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B14));
+ Table_B14 = new CJBig2_HuffmanTable(HuffmanTable_B14,
+ FX_ArraySize(HuffmanTable_B14),
+ HuffmanTable_HTOOB_B14);
}
pTRD->SBHUFFRDY = Table_B14;
} else if (cSBHUFFRDY == 1) {
if (!Table_B15) {
- JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
+ Table_B15 = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
}
pTRD->SBHUFFRDY = Table_B15;
} else {
@@ -1165,10 +1126,9 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFRDY = pSeg->m_Result.ht;
}
if (cSBHUFFRSIZE == 0) {
- JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1,
- sizeof(HuffmanTable_B1) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B1));
+ Table_B1 = new CJBig2_HuffmanTable(HuffmanTable_B1,
+ FX_ArraySize(HuffmanTable_B1),
+ HuffmanTable_HTOOB_B1);
pTRD->SBHUFFRSIZE = Table_B1;
} else {
pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
@@ -1188,7 +1148,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
}
if (pTRD->SBHUFF == 0) {
- JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream));
+ pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext);
delete pArithDecoder;
@@ -1209,7 +1169,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
}
if (pSegment->m_cFlags.s.type != 4) {
if (!m_bBufSpecified) {
- JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast();
+ JBig2PageInfo* pPageInfo = m_PageInfoList.back();
if ((pPageInfo->m_bIsStriped == 1) &&
(ri.y + ri.height > m_pPage->m_nHeight)) {
m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
@@ -1299,7 +1259,7 @@ int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment,
gbContext =
(JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp);
JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
- JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream));
+ pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
pSegment->m_Result.pd =
pPDD->decode_Arith(pArithDecoder, gbContext, pPause);
delete pArithDecoder;
@@ -1385,7 +1345,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
gbContext =
(JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp);
JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
- JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream));
+ pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
pSegment->m_Result.im =
pHRD->decode_Arith(pArithDecoder, gbContext, pPause);
delete pArithDecoder;
@@ -1407,7 +1367,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
}
if (pSegment->m_cFlags.s.type != 20) {
if (!m_bBufSpecified) {
- JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast();
+ JBig2PageInfo* pPageInfo = m_PageInfoList.back();
if ((pPageInfo->m_bIsStriped == 1) &&
(ri.y + ri.height > m_pPage->m_nHeight)) {
m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
@@ -1481,7 +1441,7 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
}
if (m_pArithDecoder == NULL) {
- JBIG2_ALLOC(m_pArithDecoder, CJBig2_ArithDecoder(m_pStream));
+ m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
m_ProcessiveStatus = m_pGRD->Start_decode_Arith(
&pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause);
} else {
@@ -1490,7 +1450,7 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
if (pSegment->m_cFlags.s.type != 36) {
if (!m_bBufSpecified) {
- JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast();
+ JBig2PageInfo* pPageInfo = m_PageInfoList.back();
if ((pPageInfo->m_bIsStriped == 1) &&
(m_ri.y + m_ri.height > m_pPage->m_nHeight)) {
m_pPage->expand(m_ri.y + m_ri.height,
@@ -1532,7 +1492,7 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
}
if (pSegment->m_cFlags.s.type != 36) {
if (!m_bBufSpecified) {
- JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast();
+ JBig2PageInfo* pPageInfo = m_PageInfoList.back();
if ((pPageInfo->m_bIsStriped == 1) &&
(m_ri.y + m_ri.height > m_pPage->m_nHeight)) {
m_pPage->expand(m_ri.y + m_ri.height,
@@ -1619,7 +1579,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
grContext =
(JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp);
JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
- JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream));
+ pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext);
delete pArithDecoder;
@@ -1633,7 +1593,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
m_pStream->offset(2);
if (pSegment->m_cFlags.s.type != 40) {
if (!m_bBufSpecified) {
- JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast();
+ JBig2PageInfo* pPageInfo = m_PageInfoList.back();
if ((pPageInfo->m_bIsStriped == 1) &&
(ri.y + ri.height > m_pPage->m_nHeight)) {
m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
@@ -1652,7 +1612,7 @@ failed:
}
int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) {
pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER;
- JBIG2_ALLOC(pSegment->m_Result.ht, CJBig2_HuffmanTable(m_pStream));
+ pSegment->m_Result.ht = new CJBig2_HuffmanTable(m_pStream);
if (!pSegment->m_Result.ht->isOK()) {
delete pSegment->m_Result.ht;
pSegment->m_Result.ht = NULL;
diff --git a/core/src/fxcodec/jbig2/JBig2_Context.h b/core/src/fxcodec/jbig2/JBig2_Context.h
index eb0ceb0eb9..0590fd157b 100644
--- a/core/src/fxcodec/jbig2/JBig2_Context.h
+++ b/core/src/fxcodec/jbig2/JBig2_Context.h
@@ -10,18 +10,16 @@
#include <list>
#include <utility>
-#include "JBig2_Module.h"
+#include "../../../../third_party/base/nonstd_unique_ptr.h"
+#include "../../../include/fxcodec/fx_codec_def.h"
+#include "JBig2_GeneralDecoder.h"
#include "JBig2_List.h"
-#include "JBig2_Segment.h"
+#include "JBig2_Module.h"
#include "JBig2_Page.h"
-#include "JBig2_GeneralDecoder.h"
-#include "../../../include/fxcodec/fx_codec_def.h"
+#include "JBig2_Segment.h"
+
+using CJBig2_CachePair = std::pair<uint8_t*, CJBig2_SymbolDict*>;
-typedef std::pair<uint8_t*, CJBig2_SymbolDict*> CJBig2_CachePair;
-typedef enum {
- JBIG2_OUT_OF_PAGE = 0,
- JBIG2_IN_PAGE,
-} JBig2State;
#define JBIG2_SUCCESS 0
#define JBIG2_FAILED -1
#define JBIG2_ERROR_TOO_SHORT -2
@@ -36,6 +34,7 @@ typedef enum {
#define JBIG2_RANDOM_STREAM 2
#define JBIG2_EMBED_STREAM 3
#define JBIG2_MIN_SEGMENT_SIZE 11
+
class CJBig2_Context : public CJBig2_Object {
public:
static CJBig2_Context* CreateContext(
@@ -62,6 +61,11 @@ class CJBig2_Context : public CJBig2_Object {
FXCODEC_STATUS GetProcessiveStatus() { return m_ProcessiveStatus; }
private:
+ enum JBig2State {
+ JBIG2_OUT_OF_PAGE = 0,
+ JBIG2_IN_PAGE,
+ };
+
CJBig2_Context(uint8_t* pGlobalData,
FX_DWORD dwGlobalLength,
uint8_t* pData,
@@ -119,22 +123,14 @@ class CJBig2_Context : public CJBig2_Object {
private:
CJBig2_Context* m_pGlobalContext;
-
int32_t m_nStreamType;
-
CJBig2_BitStream* m_pStream;
-
int32_t m_nState;
-
- CJBig2_List<CJBig2_Segment>* m_pSegmentList;
-
- CJBig2_List<JBig2PageInfo>* m_pPageInfoList;
-
+ CJBig2_List<CJBig2_Segment> m_SegmentList;
+ CJBig2_List<JBig2PageInfo> m_PageInfoList;
CJBig2_Image* m_pPage;
-
FX_BOOL m_bBufSpecified;
-
- int32_t m_nSegmentDecoded;
+ size_t m_nSegmentDecoded;
IFX_Pause* m_pPause;
int32_t m_PauseStep;
FXCODEC_STATUS m_ProcessiveStatus;
@@ -142,7 +138,7 @@ class CJBig2_Context : public CJBig2_Object {
CJBig2_ArithDecoder* m_pArithDecoder;
CJBig2_GRDProc* m_pGRD;
JBig2ArithCtx* m_gbContext;
- CJBig2_Segment* m_pSegment;
+ nonstd::unique_ptr<CJBig2_Segment> m_pSegment;
FX_DWORD m_dwOffset;
JBig2RegionInfo m_ri;
std::list<CJBig2_CachePair>* m_pSymbolDictCache;
diff --git a/core/src/fxcodec/jbig2/JBig2_GeneralDecoder.cpp b/core/src/fxcodec/jbig2/JBig2_GeneralDecoder.cpp
index a2dc397af2..cd03424295 100644
--- a/core/src/fxcodec/jbig2/JBig2_GeneralDecoder.cpp
+++ b/core/src/fxcodec/jbig2/JBig2_GeneralDecoder.cpp
@@ -29,7 +29,7 @@ extern const JBig2ArithQe QeTable[] = {
{0x0015, 43, 40, 0}, {0x0009, 44, 41, 0}, {0x0005, 45, 42, 0},
{0x0001, 45, 43, 0}, {0x5601, 46, 46, 0}};
-extern const unsigned int JBIG2_QE_NUM = sizeof(QeTable) / sizeof(JBig2ArithQe);
+extern const unsigned int JBIG2_QE_NUM = FX_ArraySize(QeTable);
CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
@@ -1138,10 +1138,9 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
FX_BOOL bFirst;
FX_DWORD nTmp;
int32_t nVal, nBits;
- CJBig2_HuffmanDecoder* pHuffmanDecoder;
CJBig2_GRRDProc* pGRRD;
CJBig2_ArithDecoder* pArithDecoder;
- JBIG2_ALLOC(pHuffmanDecoder, CJBig2_HuffmanDecoder(pStream));
+ CJBig2_HuffmanDecoder* pHuffmanDecoder = new CJBig2_HuffmanDecoder(pStream);
JBIG2_ALLOC(SBREG, CJBig2_Image(SBW, SBH));
SBREG->fill(SBDEFPIXEL);
if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) {
@@ -1266,7 +1265,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
pGRRD->GRAT[1] = SBRAT[1];
pGRRD->GRAT[2] = SBRAT[2];
pGRRD->GRAT[3] = SBRAT[3];
- JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(pStream));
+ pArithDecoder = new CJBig2_ArithDecoder(pStream);
IBI = pGRRD->decode(pArithDecoder, grContext);
if (IBI == NULL) {
delete pGRRD;
@@ -1388,16 +1387,16 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
IAID = pIDS->IAID;
bRetained = TRUE;
} else {
- JBIG2_ALLOC(IADT, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IAFS, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IADS, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IAIT, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARI, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDW, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDH, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDX, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDY, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IAID, CJBig2_ArithIaidDecoder(SBSYMCODELEN));
+ IADT = new CJBig2_ArithIntDecoder();
+ IAFS = new CJBig2_ArithIntDecoder();
+ IADS = new CJBig2_ArithIntDecoder();
+ IAIT = new CJBig2_ArithIntDecoder();
+ IARI = new CJBig2_ArithIntDecoder();
+ IARDW = new CJBig2_ArithIntDecoder();
+ IARDH = new CJBig2_ArithIntDecoder();
+ IARDX = new CJBig2_ArithIntDecoder();
+ IARDY = new CJBig2_ArithIntDecoder();
+ IAID = new CJBig2_ArithIaidDecoder(SBSYMCODELEN);
bRetained = FALSE;
}
JBIG2_ALLOC(SBREG, CJBig2_Image(SBW, SBH));
@@ -1633,24 +1632,24 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
*IAFS, *IADS, *IAIT, *IARI, *IARDW, *IARDH;
CJBig2_ArithIaidDecoder* IAID;
CJBig2_SymbolDict* pDict;
- JBIG2_ALLOC(IADH, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IADW, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IAAI, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDX, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDY, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IAEX, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IADT, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IAFS, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IADS, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IAIT, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARI, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDW, CJBig2_ArithIntDecoder());
- JBIG2_ALLOC(IARDH, CJBig2_ArithIntDecoder());
+ IADH = new CJBig2_ArithIntDecoder();
+ IADW = new CJBig2_ArithIntDecoder();
+ IAAI = new CJBig2_ArithIntDecoder();
+ IARDX = new CJBig2_ArithIntDecoder();
+ IARDY = new CJBig2_ArithIntDecoder();
+ IAEX = new CJBig2_ArithIntDecoder();
+ IADT = new CJBig2_ArithIntDecoder();
+ IAFS = new CJBig2_ArithIntDecoder();
+ IADS = new CJBig2_ArithIntDecoder();
+ IAIT = new CJBig2_ArithIntDecoder();
+ IARI = new CJBig2_ArithIntDecoder();
+ IARDW = new CJBig2_ArithIntDecoder();
+ IARDH = new CJBig2_ArithIntDecoder();
nTmp = 0;
while ((FX_DWORD)(1 << nTmp) < (SDNUMINSYMS + SDNUMNEWSYMS)) {
nTmp++;
}
- JBIG2_ALLOC(IAID, CJBig2_ArithIaidDecoder((uint8_t)nTmp));
+ IAID = new CJBig2_ArithIaidDecoder((uint8_t)nTmp);
SDNEWSYMS = (CJBig2_Image**)m_pModule->JBig2_Malloc2(SDNUMNEWSYMS,
sizeof(CJBig2_Image*));
FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*));
@@ -1757,39 +1756,30 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
pDecoder->TRANSPOSED = 0;
pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT;
pDecoder->SBDSOFFSET = 0;
- JBIG2_ALLOC(SBHUFFFS, CJBig2_HuffmanTable(HuffmanTable_B6,
- sizeof(HuffmanTable_B6) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B6));
- JBIG2_ALLOC(SBHUFFDS, CJBig2_HuffmanTable(HuffmanTable_B8,
- sizeof(HuffmanTable_B8) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B8));
- JBIG2_ALLOC(SBHUFFDT, CJBig2_HuffmanTable(HuffmanTable_B11,
- sizeof(HuffmanTable_B11) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B11));
- JBIG2_ALLOC(SBHUFFRDW, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRDH, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRDX, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRDY, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRSIZE,
- CJBig2_HuffmanTable(
- HuffmanTable_B1,
- sizeof(HuffmanTable_B1) / sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B1));
+ SBHUFFFS = new CJBig2_HuffmanTable(HuffmanTable_B6,
+ FX_ArraySize(HuffmanTable_B6),
+ HuffmanTable_HTOOB_B6);
+ SBHUFFDS = new CJBig2_HuffmanTable(HuffmanTable_B8,
+ FX_ArraySize(HuffmanTable_B8),
+ HuffmanTable_HTOOB_B8);
+ SBHUFFDT = new CJBig2_HuffmanTable(HuffmanTable_B11,
+ FX_ArraySize(HuffmanTable_B11),
+ HuffmanTable_HTOOB_B11);
+ SBHUFFRDW = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRDH = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRDX = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRDY = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRSIZE = new CJBig2_HuffmanTable(HuffmanTable_B1,
+ FX_ArraySize(HuffmanTable_B1),
+ HuffmanTable_HTOOB_B1);
pDecoder->SBHUFFFS = SBHUFFFS;
pDecoder->SBHUFFDS = SBHUFFDS;
pDecoder->SBHUFFDT = SBHUFFDT;
@@ -2014,7 +2004,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream,
CJBig2_ArithDecoder* pArithDecoder;
CJBig2_GRDProc* pGRD;
CJBig2_SymbolDict* pDict;
- JBIG2_ALLOC(pHuffmanDecoder, CJBig2_HuffmanDecoder(pStream));
+ pHuffmanDecoder = new CJBig2_HuffmanDecoder(pStream);
SDNEWSYMS = (CJBig2_Image**)m_pModule->JBig2_Malloc2(SDNUMNEWSYMS,
sizeof(CJBig2_Image*));
FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*));
@@ -2114,39 +2104,30 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream,
pDecoder->TRANSPOSED = 0;
pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT;
pDecoder->SBDSOFFSET = 0;
- JBIG2_ALLOC(SBHUFFFS, CJBig2_HuffmanTable(HuffmanTable_B6,
- sizeof(HuffmanTable_B6) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B6));
- JBIG2_ALLOC(SBHUFFDS, CJBig2_HuffmanTable(HuffmanTable_B8,
- sizeof(HuffmanTable_B8) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B8));
- JBIG2_ALLOC(SBHUFFDT, CJBig2_HuffmanTable(HuffmanTable_B11,
- sizeof(HuffmanTable_B11) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B11));
- JBIG2_ALLOC(SBHUFFRDW, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRDH, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRDX, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRDY, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRSIZE,
- CJBig2_HuffmanTable(
- HuffmanTable_B1,
- sizeof(HuffmanTable_B1) / sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B1));
+ SBHUFFFS = new CJBig2_HuffmanTable(HuffmanTable_B6,
+ FX_ArraySize(HuffmanTable_B6),
+ HuffmanTable_HTOOB_B6);
+ SBHUFFDS = new CJBig2_HuffmanTable(HuffmanTable_B8,
+ FX_ArraySize(HuffmanTable_B8),
+ HuffmanTable_HTOOB_B8);
+ SBHUFFDT = new CJBig2_HuffmanTable(HuffmanTable_B11,
+ FX_ArraySize(HuffmanTable_B11),
+ HuffmanTable_HTOOB_B11);
+ SBHUFFRDW = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRDH = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRDX = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRDY = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRSIZE = new CJBig2_HuffmanTable(HuffmanTable_B1,
+ FX_ArraySize(HuffmanTable_B1),
+ HuffmanTable_HTOOB_B1);
pDecoder->SBHUFFFS = SBHUFFFS;
pDecoder->SBHUFFDS = SBHUFFDS;
pDecoder->SBHUFFDT = SBHUFFDT;
@@ -2220,15 +2201,12 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream,
}
}
m_pModule->JBig2_Free(SBSYMCODES);
- JBIG2_ALLOC(SBHUFFRDX, CJBig2_HuffmanTable(HuffmanTable_B15,
- sizeof(HuffmanTable_B15) /
- sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B15));
- JBIG2_ALLOC(SBHUFFRSIZE,
- CJBig2_HuffmanTable(
- HuffmanTable_B1,
- sizeof(HuffmanTable_B1) / sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B1));
+ SBHUFFRDX = new CJBig2_HuffmanTable(HuffmanTable_B15,
+ FX_ArraySize(HuffmanTable_B15),
+ HuffmanTable_HTOOB_B15);
+ SBHUFFRSIZE = new CJBig2_HuffmanTable(HuffmanTable_B1,
+ FX_ArraySize(HuffmanTable_B1),
+ HuffmanTable_HTOOB_B1);
if ((pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDXI) != 0) ||
(pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDYI) != 0) ||
(pHuffmanDecoder->decodeAValue(SBHUFFRSIZE, &nVal) != 0)) {
@@ -2259,7 +2237,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream,
pGRRD->GRAT[1] = SDRAT[1];
pGRRD->GRAT[2] = SDRAT[2];
pGRRD->GRAT[3] = SDRAT[3];
- JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(pStream));
+ pArithDecoder = new CJBig2_ArithDecoder(pStream);
BS = pGRRD->decode(pArithDecoder, grContext);
if (BS == NULL) {
m_pModule->JBig2_Free(SBSYMS);
@@ -2338,10 +2316,8 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream,
}
EXINDEX = 0;
CUREXFLAG = 0;
- JBIG2_ALLOC(pTable, CJBig2_HuffmanTable(
- HuffmanTable_B1,
- sizeof(HuffmanTable_B1) / sizeof(JBig2TableLine),
- HuffmanTable_HTOOB_B1));
+ pTable = new CJBig2_HuffmanTable(
+ HuffmanTable_B1, FX_ArraySize(HuffmanTable_B1), HuffmanTable_HTOOB_B1);
EXFLAGS = (FX_BOOL*)m_pModule->JBig2_Malloc2(sizeof(FX_BOOL),
(SDNUMINSYMS + SDNUMNEWSYMS));
while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) {
@@ -2523,7 +2499,7 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith(
CJBig2_Image* BHDC = NULL;
CJBig2_PatternDict* pDict;
CJBig2_GRDProc* pGRD;
- JBIG2_ALLOC(pDict, CJBig2_PatternDict());
+ pDict = new CJBig2_PatternDict();
pDict->NUMPATS = GRAYMAX + 1;
pDict->HDPATS = (CJBig2_Image**)m_pModule->JBig2_Malloc2(
sizeof(CJBig2_Image*), pDict->NUMPATS);
@@ -2571,9 +2547,8 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream,
IFX_Pause* pPause) {
FX_DWORD GRAY;
CJBig2_Image* BHDC = NULL;
- CJBig2_PatternDict* pDict;
CJBig2_GRDProc* pGRD;
- JBIG2_ALLOC(pDict, CJBig2_PatternDict());
+ CJBig2_PatternDict* pDict = new CJBig2_PatternDict();
pDict->NUMPATS = GRAYMAX + 1;
pDict->HDPATS = (CJBig2_Image**)m_pModule->JBig2_Malloc2(
sizeof(CJBig2_Image*), pDict->NUMPATS);
diff --git a/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h b/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h
index 6bf1cb45e0..c972aae074 100644
--- a/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h
+++ b/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h
@@ -8,7 +8,7 @@
#define _JBIG2_HUFFMAN_DECODER_H_
#include "JBig2_BitStream.h"
#include "JBig2_HuffmanTable.h"
-class CJBig2_HuffmanDecoder : public CJBig2_Object {
+class CJBig2_HuffmanDecoder {
public:
CJBig2_HuffmanDecoder(CJBig2_BitStream* pStream);
diff --git a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp
index 87722d2628..ea1fdee3be 100644
--- a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp
+++ b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp
@@ -5,9 +5,12 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "JBig2_HuffmanTable.h"
-#include "JBig2_BitStream.h"
+
#include <string.h>
+#include "../../../include/fxcrt/fx_memory.h"
+#include "JBig2_BitStream.h"
+
CJBig2_HuffmanTable::CJBig2_HuffmanTable(const JBig2TableLine* pTable,
int nLines,
FX_BOOL bHTOOB) {
@@ -21,18 +24,10 @@ CJBig2_HuffmanTable::CJBig2_HuffmanTable(CJBig2_BitStream* pStream) {
}
CJBig2_HuffmanTable::~CJBig2_HuffmanTable() {
- if (CODES) {
- m_pModule->JBig2_Free(CODES);
- }
- if (PREFLEN) {
- m_pModule->JBig2_Free(PREFLEN);
- }
- if (RANGELEN) {
- m_pModule->JBig2_Free(RANGELEN);
- }
- if (RANGELOW) {
- m_pModule->JBig2_Free(RANGELOW);
- }
+ FX_Free(CODES);
+ FX_Free(PREFLEN);
+ FX_Free(RANGELEN);
+ FX_Free(RANGELOW);
}
void CJBig2_HuffmanTable::init() {
HTOOB = FALSE;
@@ -50,10 +45,10 @@ int CJBig2_HuffmanTable::parseFromStandardTable(const JBig2TableLine* pTable,
int* FIRSTCODE;
HTOOB = bHTOOB;
NTEMP = nLines;
- CODES = (int*)m_pModule->JBig2_Malloc2(sizeof(int), NTEMP);
- PREFLEN = (int*)m_pModule->JBig2_Malloc2(sizeof(int), NTEMP);
- RANGELEN = (int*)m_pModule->JBig2_Malloc2(sizeof(int), NTEMP);
- RANGELOW = (int*)m_pModule->JBig2_Malloc2(sizeof(int), NTEMP);
+ CODES = (int*)FX_AllocOrDie(sizeof(int), NTEMP);
+ PREFLEN = (int*)FX_AllocOrDie(sizeof(int), NTEMP);
+ RANGELEN = (int*)FX_AllocOrDie(sizeof(int), NTEMP);
+ RANGELOW = (int*)FX_AllocOrDie(sizeof(int), NTEMP);
LENMAX = 0;
for (i = 0; i < NTEMP; i++) {
PREFLEN[i] = pTable[i].PREFLEN;
@@ -63,9 +58,9 @@ int CJBig2_HuffmanTable::parseFromStandardTable(const JBig2TableLine* pTable,
LENMAX = PREFLEN[i];
}
}
- LENCOUNT = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1));
+ LENCOUNT = (int*)FX_AllocOrDie(sizeof(int), (LENMAX + 1));
JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1));
- FIRSTCODE = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1));
+ FIRSTCODE = (int*)FX_AllocOrDie(sizeof(int), (LENMAX + 1));
for (i = 0; i < NTEMP; i++) {
LENCOUNT[PREFLEN[i]]++;
}
@@ -85,17 +80,17 @@ int CJBig2_HuffmanTable::parseFromStandardTable(const JBig2TableLine* pTable,
}
CURLEN = CURLEN + 1;
}
- m_pModule->JBig2_Free(LENCOUNT);
- m_pModule->JBig2_Free(FIRSTCODE);
+ FX_Free(LENCOUNT);
+ FX_Free(FIRSTCODE);
return 1;
}
-#define HT_CHECK_MEMORY_ADJUST \
- if (NTEMP >= nSize) { \
- nSize += 16; \
- PREFLEN = (int*)m_pModule->JBig2_Realloc(PREFLEN, sizeof(int) * nSize); \
- RANGELEN = (int*)m_pModule->JBig2_Realloc(RANGELEN, sizeof(int) * nSize); \
- RANGELOW = (int*)m_pModule->JBig2_Realloc(RANGELOW, sizeof(int) * nSize); \
+#define HT_CHECK_MEMORY_ADJUST \
+ if (NTEMP >= nSize) { \
+ nSize += 16; \
+ PREFLEN = (int*)FX_Realloc(uint8_t, PREFLEN, sizeof(int) * nSize); \
+ RANGELEN = (int*)FX_Realloc(uint8_t, RANGELEN, sizeof(int) * nSize); \
+ RANGELOW = (int*)FX_Realloc(uint8_t, RANGELOW, sizeof(int) * nSize); \
}
int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) {
unsigned char HTPS, HTRS;
@@ -116,9 +111,9 @@ int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) {
pStream->readInteger(&HTHIGH) == -1 || HTLOW > HTHIGH) {
goto failed;
}
- PREFLEN = (int*)m_pModule->JBig2_Malloc2(sizeof(int), nSize);
- RANGELEN = (int*)m_pModule->JBig2_Malloc2(sizeof(int), nSize);
- RANGELOW = (int*)m_pModule->JBig2_Malloc2(sizeof(int), nSize);
+ PREFLEN = (int*)FX_AllocOrDie(sizeof(int), nSize);
+ RANGELEN = (int*)FX_AllocOrDie(sizeof(int), nSize);
+ RANGELOW = (int*)FX_AllocOrDie(sizeof(int), nSize);
CURRANGELOW = HTLOW;
NTEMP = 0;
do {
@@ -152,16 +147,16 @@ int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) {
}
NTEMP = NTEMP + 1;
}
- CODES = (int*)m_pModule->JBig2_Malloc2(sizeof(int), NTEMP);
+ CODES = (int*)FX_AllocOrDie(sizeof(int), NTEMP);
LENMAX = 0;
for (int i = 0; i < NTEMP; i++) {
if (PREFLEN[i] > LENMAX) {
LENMAX = PREFLEN[i];
}
}
- LENCOUNT = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1));
+ LENCOUNT = (int*)FX_AllocOrDie(sizeof(int), (LENMAX + 1));
JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1));
- FIRSTCODE = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1));
+ FIRSTCODE = (int*)FX_AllocOrDie(sizeof(int), (LENMAX + 1));
for (int i = 0; i < NTEMP; i++) {
LENCOUNT[PREFLEN[i]]++;
}
@@ -181,8 +176,8 @@ int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) {
}
CURLEN = CURLEN + 1;
}
- m_pModule->JBig2_Free(LENCOUNT);
- m_pModule->JBig2_Free(FIRSTCODE);
+ FX_Free(LENCOUNT);
+ FX_Free(FIRSTCODE);
return TRUE;
failed:
return FALSE;
diff --git a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h
index 64c52176be..b954b4d30d 100644
--- a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h
+++ b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h
@@ -9,7 +9,7 @@
#include "JBig2_Module.h"
#include "JBig2_HuffmanTable_Standard.h"
#include "JBig2_BitStream.h"
-class CJBig2_HuffmanTable : public CJBig2_Object {
+class CJBig2_HuffmanTable {
public:
CJBig2_HuffmanTable(const JBig2TableLine* pTable, int nLines, FX_BOOL bHTOOB);
diff --git a/core/src/fxcodec/jbig2/JBig2_List.h b/core/src/fxcodec/jbig2/JBig2_List.h
index be2d7cb7e4..e033eb23ea 100644
--- a/core/src/fxcodec/jbig2/JBig2_List.h
+++ b/core/src/fxcodec/jbig2/JBig2_List.h
@@ -6,48 +6,35 @@
#ifndef _JBIG2_LIST_H_
#define _JBIG2_LIST_H_
-#include "JBig2_Define.h"
-#include "JBig2_Object.h"
+
+#include <vector>
+
template <class TYPE>
-class CJBig2_List : public CJBig2_Object {
+class CJBig2_List {
public:
- CJBig2_List(int32_t nSize = 8) {
- m_nSize = nSize;
- m_pArray = (TYPE**)m_pModule->JBig2_Malloc2(sizeof(TYPE*), nSize);
- m_nLength = 0;
- }
+ CJBig2_List() {}
~CJBig2_List() {
clear();
- m_pModule->JBig2_Free(m_pArray);
}
void clear() {
- int32_t i;
- for (i = 0; i < m_nLength; i++) {
- delete m_pArray[i];
- }
- m_nLength = 0;
+ for (size_t i = 0; i < m_vector.size(); ++i)
+ delete m_vector[i];
+ m_vector.clear();
}
- void addItem(TYPE* pItem) {
- if (m_nLength >= m_nSize) {
- m_nSize += 8;
- m_pArray =
- (TYPE**)m_pModule->JBig2_Realloc(m_pArray, sizeof(TYPE*) * m_nSize);
- }
- m_pArray[m_nLength++] = pItem;
- }
+ void push_back(TYPE* pItem) { m_vector.push_back(pItem); }
- int32_t getLength() { return m_nLength; }
+ size_t size() const { return m_vector.size(); }
+ void resize(size_t count) { m_vector.resize(count); }
- TYPE* getAt(int32_t nIndex) { return m_pArray[nIndex]; }
+ TYPE* get(size_t index) { return m_vector[index]; }
- TYPE* getLast() { return m_pArray[m_nLength - 1]; }
+ TYPE* back() { return m_vector.back(); }
private:
- int32_t m_nSize;
- TYPE** m_pArray;
- int32_t m_nLength;
+ std::vector<TYPE*> m_vector;
};
+
#endif
diff --git a/core/src/fxcodec/jbig2/JBig2_Page.h b/core/src/fxcodec/jbig2/JBig2_Page.h
index 5b2fa69678..ba4b288453 100644
--- a/core/src/fxcodec/jbig2/JBig2_Page.h
+++ b/core/src/fxcodec/jbig2/JBig2_Page.h
@@ -6,12 +6,17 @@
#ifndef _JBIG2_PAGE_H_
#define _JBIG2_PAGE_H_
-#include "JBig2_Image.h"
-struct JBig2PageInfo : public CJBig2_Object {
- FX_DWORD m_dwWidth, m_dwHeight;
- FX_DWORD m_dwResolutionX, m_dwResolutionY;
+
+#include "../../../include/fxcrt/fx_system.h"
+
+struct JBig2PageInfo {
+ FX_DWORD m_dwWidth;
+ FX_DWORD m_dwHeight;
+ FX_DWORD m_dwResolutionX;
+ FX_DWORD m_dwResolutionY;
uint8_t m_cFlags;
FX_BOOL m_bIsStriped;
FX_WORD m_wMaxStripeSize;
};
+
#endif
diff --git a/core/src/fxcodec/jbig2/JBig2_PatternDict.cpp b/core/src/fxcodec/jbig2/JBig2_PatternDict.cpp
index 3469c36847..21f6d64182 100644
--- a/core/src/fxcodec/jbig2/JBig2_PatternDict.cpp
+++ b/core/src/fxcodec/jbig2/JBig2_PatternDict.cpp
@@ -5,6 +5,9 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "JBig2_PatternDict.h"
+
+#include "../../../include/fxcrt/fx_memory.h"
+
CJBig2_PatternDict::CJBig2_PatternDict() {
NUMPATS = 0;
HDPATS = NULL;
@@ -15,6 +18,6 @@ CJBig2_PatternDict::~CJBig2_PatternDict() {
for (FX_DWORD i = 0; i < NUMPATS; i++) {
delete HDPATS[i];
}
- m_pModule->JBig2_Free(HDPATS);
+ FX_Free(HDPATS);
}
}
diff --git a/core/src/fxcodec/jbig2/JBig2_PatternDict.h b/core/src/fxcodec/jbig2/JBig2_PatternDict.h
index fd39bfd20b..43250f9163 100644
--- a/core/src/fxcodec/jbig2/JBig2_PatternDict.h
+++ b/core/src/fxcodec/jbig2/JBig2_PatternDict.h
@@ -8,13 +8,12 @@
#define _JBIG2_PATTERN_DICT_H_
#include "JBig2_Define.h"
#include "JBig2_Image.h"
-class CJBig2_PatternDict : public CJBig2_Object {
+class CJBig2_PatternDict {
public:
CJBig2_PatternDict();
~CJBig2_PatternDict();
- public:
FX_DWORD NUMPATS;
CJBig2_Image** HDPATS;
};
diff --git a/core/src/fxcodec/jbig2/JBig2_Segment.cpp b/core/src/fxcodec/jbig2/JBig2_Segment.cpp
index 39e4fafaa1..7ad55f3515 100644
--- a/core/src/fxcodec/jbig2/JBig2_Segment.cpp
+++ b/core/src/fxcodec/jbig2/JBig2_Segment.cpp
@@ -5,6 +5,9 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "JBig2_Segment.h"
+
+#include "../../../include/fxcrt/fx_memory.h"
+
CJBig2_Segment::CJBig2_Segment() {
m_dwNumber = 0;
m_cFlags.c = 0;
@@ -19,28 +22,22 @@ CJBig2_Segment::CJBig2_Segment() {
m_Result.vd = NULL;
}
CJBig2_Segment::~CJBig2_Segment() {
- clean();
-}
-void CJBig2_Segment::clean() {
- if (m_pReferred_to_segment_numbers) {
- m_pModule->JBig2_Free(m_pReferred_to_segment_numbers);
- }
- if (m_Result.vd) {
- switch (m_nResultType) {
- case JBIG2_IMAGE_POINTER:
- delete m_Result.im;
- break;
- case JBIG2_SYMBOL_DICT_POINTER:
- delete m_Result.sd;
- break;
- case JBIG2_PATTERN_DICT_POINTER:
- delete m_Result.pd;
- break;
- case JBIG2_HUFFMAN_TABLE_POINTER:
- delete m_Result.ht;
- break;
- default:
- m_pModule->JBig2_Free(m_Result.vd);
- }
+ FX_Free(m_pReferred_to_segment_numbers);
+
+ switch (m_nResultType) {
+ case JBIG2_IMAGE_POINTER:
+ delete m_Result.im;
+ break;
+ case JBIG2_SYMBOL_DICT_POINTER:
+ delete m_Result.sd;
+ break;
+ case JBIG2_PATTERN_DICT_POINTER:
+ delete m_Result.pd;
+ break;
+ case JBIG2_HUFFMAN_TABLE_POINTER:
+ delete m_Result.ht;
+ break;
+ default:
+ FX_Free(m_Result.vd);
}
}
diff --git a/core/src/fxcodec/jbig2/JBig2_Segment.h b/core/src/fxcodec/jbig2/JBig2_Segment.h
index 82cd8384a0..5c1c585939 100644
--- a/core/src/fxcodec/jbig2/JBig2_Segment.h
+++ b/core/src/fxcodec/jbig2/JBig2_Segment.h
@@ -28,15 +28,12 @@ typedef enum {
JBIG2_PATTERN_DICT_POINTER,
JBIG2_HUFFMAN_TABLE_POINTER
} JBig2_ResultType;
-class CJBig2_Segment : public CJBig2_Object {
+class CJBig2_Segment {
public:
CJBig2_Segment();
~CJBig2_Segment();
- void clean();
-
- public:
FX_DWORD m_dwNumber;
union {
struct {