summaryrefslogtreecommitdiff
path: root/core/src/fxcodec
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fxcodec')
-rw-r--r--core/src/fxcodec/codec/codec_int.h4
-rw-r--r--core/src/fxcodec/codec/fx_codec_jbig.cpp8
-rw-r--r--core/src/fxcodec/jbig2/JBig2_Context.cpp27
-rw-r--r--core/src/fxcodec/jbig2/JBig2_Context.h7
4 files changed, 25 insertions, 21 deletions
diff --git a/core/src/fxcodec/codec/codec_int.h b/core/src/fxcodec/codec/codec_int.h
index 78672e62ee..b95871b4e1 100644
--- a/core/src/fxcodec/codec/codec_int.h
+++ b/core/src/fxcodec/codec/codec_int.h
@@ -5,6 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <limits.h>
+#include <list>
+#include "../jbig2/JBig2_Context.h"
class CCodec_BasicModule : public ICodec_BasicModule
{
public:
@@ -196,7 +198,6 @@ public:
FX_BOOL Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_BOOL bTranslateColor, FX_LPBYTE offsets);
void DestroyDecoder(void* ctx);
};
-#include "../jbig2/JBig2_Context.h"
class CPDF_Jbig2Interface : public CFX_Object, public CJBig2_Module
{
public:
@@ -268,5 +269,6 @@ public:
FXCODEC_STATUS ContinueDecode(void* pJbig2Context, IFX_Pause* pPause);
void DestroyJbig2Context(void* pJbig2Context);
CPDF_Jbig2Interface m_Module;
+ std::list<CJBig2_CachePair> m_SymbolDictCache;
private:
};
diff --git a/core/src/fxcodec/codec/fx_codec_jbig.cpp b/core/src/fxcodec/codec/fx_codec_jbig.cpp
index 996ad60f8a..173f7a7d36 100644
--- a/core/src/fxcodec/codec/fx_codec_jbig.cpp
+++ b/core/src/fxcodec/codec/fx_codec_jbig.cpp
@@ -30,7 +30,7 @@ FX_BOOL CCodec_Jbig2Module::Decode(FX_DWORD width, FX_DWORD height, FX_LPCBYTE s
{
FXSYS_memset32(dest_buf, 0, height * dest_pitch);
CJBig2_Context* pContext = CJBig2_Context::CreateContext(&m_Module,
- (FX_LPBYTE)global_data, global_size, (FX_LPBYTE)src_buf, src_size, JBIG2_EMBED_STREAM);
+ (FX_LPBYTE)global_data, global_size, (FX_LPBYTE)src_buf, src_size, JBIG2_EMBED_STREAM, &m_SymbolDictCache);
if (pContext == NULL) {
return FALSE;
}
@@ -60,7 +60,7 @@ FX_BOOL CCodec_Jbig2Module::Decode(IFX_FileRead* file_ptr,
if(!file_ptr->ReadBlock(src_buf, 0, src_size)) {
goto failed;
}
- pContext = CJBig2_Context::CreateContext(&m_Module, NULL, 0, src_buf, src_size, JBIG2_FILE_STREAM);
+ pContext = CJBig2_Context::CreateContext(&m_Module, NULL, 0, src_buf, src_size, JBIG2_FILE_STREAM, &m_SymbolDictCache);
if(pContext == NULL) {
goto failed;
}
@@ -102,7 +102,7 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(void* pJbig2Context, FX_DWORD wid
m_pJbig2Context->m_bFileReader = FALSE;
FXSYS_memset32(dest_buf, 0, height * dest_pitch);
m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(&m_Module,
- (FX_LPBYTE)global_data, global_size, (FX_LPBYTE)src_buf, src_size, JBIG2_EMBED_STREAM, pPause);
+ (FX_LPBYTE)global_data, global_size, (FX_LPBYTE)src_buf, src_size, JBIG2_EMBED_STREAM, &m_SymbolDictCache, pPause);
if(!m_pJbig2Context->m_pContext) {
return FXCODEC_STATUS_ERROR;
}
@@ -140,7 +140,7 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(void* pJbig2Context, IFX_FileRead
if(!file_ptr->ReadBlock((void*)m_pJbig2Context->m_src_buf, 0, m_pJbig2Context->m_src_size)) {
goto failed;
}
- m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(&m_Module, NULL, 0, m_pJbig2Context->m_src_buf, m_pJbig2Context->m_src_size, JBIG2_FILE_STREAM, pPause);
+ m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(&m_Module, NULL, 0, m_pJbig2Context->m_src_buf, m_pJbig2Context->m_src_size, JBIG2_FILE_STREAM, &m_SymbolDictCache, pPause);
if(m_pJbig2Context->m_pContext == NULL) {
goto failed;
}
diff --git a/core/src/fxcodec/jbig2/JBig2_Context.cpp b/core/src/fxcodec/jbig2/JBig2_Context.cpp
index fec6b5fb68..bcd16e7e14 100644
--- a/core/src/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/src/fxcodec/jbig2/JBig2_Context.cpp
@@ -16,8 +16,6 @@
// at the front. Even a tiny cache size like 2 makes a dramatic
// difference for typical JBIG2 documents.
const int kSymbolDictCacheMaxSize = 2;
-typedef std::pair<FX_BYTE*, CJBig2_SymbolDict*> CJBig2_CachePair;
-static std::list<CJBig2_CachePair> SymbolDictCache;
void OutputBitmap(CJBig2_Image* pImage)
{
@@ -26,9 +24,9 @@ void OutputBitmap(CJBig2_Image* pImage)
}
}
CJBig2_Context *CJBig2_Context::CreateContext(CJBig2_Module *pModule, FX_BYTE *pGlobalData, FX_DWORD dwGlobalLength,
- FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, IFX_Pause* pPause)
+ FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause)
{
- return new(pModule) CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, nStreamType, pPause);
+ return new(pModule)CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, nStreamType, pSymbolDictCache, pPause);
}
void CJBig2_Context::DestroyContext(CJBig2_Context *pContext)
{
@@ -37,11 +35,11 @@ void CJBig2_Context::DestroyContext(CJBig2_Context *pContext)
}
}
CJBig2_Context::CJBig2_Context(FX_BYTE *pGlobalData, FX_DWORD dwGlobalLength,
- FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, IFX_Pause* pPause)
+ FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause)
{
if(pGlobalData && (dwGlobalLength > 0)) {
JBIG2_ALLOC(m_pGlobalContext, CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength,
- JBIG2_EMBED_STREAM, pPause));
+ JBIG2_EMBED_STREAM, pSymbolDictCache, pPause));
} else {
m_pGlobalContext = NULL;
}
@@ -61,6 +59,7 @@ CJBig2_Context::CJBig2_Context(FX_BYTE *pGlobalData, FX_DWORD dwGlobalLength,
m_pSegment = NULL;
m_dwOffset = 0;
m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY;
+ m_pSymbolDictCache = pSymbolDictCache;
}
CJBig2_Context::~CJBig2_Context()
{
@@ -808,11 +807,11 @@ FX_INT32 CJBig2_Context::parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pP
}
pSegment->m_nResultType = JBIG2_SYMBOL_DICT_POINTER;
for(std::list<CJBig2_CachePair>::iterator it =
- SymbolDictCache.begin(); it != SymbolDictCache.end(); ++it) {
+ m_pSymbolDictCache->begin(); it != m_pSymbolDictCache->end(); ++it) {
if (it->first == key) {
pSegment->m_Result.sd = it->second->DeepCopy();
- SymbolDictCache.push_front(*it);
- SymbolDictCache.erase(it);
+ m_pSymbolDictCache->push_front(*it);
+ m_pSymbolDictCache->erase(it);
cache_hit = true;
break;
}
@@ -837,12 +836,12 @@ FX_INT32 CJBig2_Context::parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pP
m_pStream->alignByte();
}
CJBig2_SymbolDict *value = pSegment->m_Result.sd->DeepCopy();
- if (value) {
- while (SymbolDictCache.size() >= kSymbolDictCacheMaxSize) {
- delete SymbolDictCache.back().second;
- SymbolDictCache.pop_back();
+ if (value && kSymbolDictCacheMaxSize > 0) {
+ while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) {
+ delete m_pSymbolDictCache->back().second;
+ m_pSymbolDictCache->pop_back();
}
- SymbolDictCache.push_front(CJBig2_CachePair(key, value));
+ m_pSymbolDictCache->push_front(CJBig2_CachePair(key, value));
}
}
if(wFlags & 0x0200) {
diff --git a/core/src/fxcodec/jbig2/JBig2_Context.h b/core/src/fxcodec/jbig2/JBig2_Context.h
index 90bd7ddbbe..f46530e005 100644
--- a/core/src/fxcodec/jbig2/JBig2_Context.h
+++ b/core/src/fxcodec/jbig2/JBig2_Context.h
@@ -13,6 +13,8 @@
#include "JBig2_GeneralDecoder.h"
#include "../../../include/fxcodec/fx_codec_def.h"
#include "../../../include/fxcrt/fx_basic.h"
+#include <utility>
+typedef std::pair<FX_BYTE*, CJBig2_SymbolDict*> CJBig2_CachePair;
typedef enum {
JBIG2_OUT_OF_PAGE = 0,
JBIG2_IN_PAGE,
@@ -36,7 +38,7 @@ class CJBig2_Context : public CJBig2_Object
public:
static CJBig2_Context *CreateContext(CJBig2_Module *pModule, FX_BYTE *pGlobalData, FX_DWORD dwGlobalLength,
- FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, IFX_Pause* pPause = NULL);
+ FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause = NULL);
static void DestroyContext(CJBig2_Context *pContext);
@@ -55,7 +57,7 @@ public:
private:
CJBig2_Context(FX_BYTE *pGlobalData, FX_DWORD dwGlobalLength,
- FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, IFX_Pause* pPause);
+ FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause);
~CJBig2_Context();
@@ -131,5 +133,6 @@ private:
CJBig2_Segment *m_pSegment;
FX_DWORD m_dwOffset;
JBig2RegionInfo m_ri;
+ std::list<CJBig2_CachePair>* m_pSymbolDictCache;
};
#endif