summaryrefslogtreecommitdiff
path: root/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp')
-rw-r--r--core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp65
1 files changed, 30 insertions, 35 deletions
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;