summaryrefslogtreecommitdiff
path: root/core/src/fxcodec/codec
diff options
context:
space:
mode:
authorDavid Lattimore <dml@google.com>2015-10-09 08:18:20 +1100
committerDavid Lattimore <dml@google.com>2015-10-09 08:18:20 +1100
commitf1b88e76134808f36f16b9e53a2e9dd89b12c8fd (patch)
tree215fae3dd4fe42787ea4cc2fa2a4d1e4cd587d76 /core/src/fxcodec/codec
parent8793b4a071fad51a770b93838e0752505b020e43 (diff)
downloadpdfium-f1b88e76134808f36f16b9e53a2e9dd89b12c8fd.tar.xz
Various changes to JBig2 cache:
- Makes the cache be per-document - Keys the cache on ObjNum and stream offset instead of keying on a pointer to the data (which can result in false cache hits). - Makes it so the cache is only used for the globals stream. - Reenable the cache. R=thestig@chromium.org BUG=pdfium:207 Review URL: https://codereview.chromium.org/1380243004 .
Diffstat (limited to 'core/src/fxcodec/codec')
-rw-r--r--core/src/fxcodec/codec/codec_int.h16
-rw-r--r--core/src/fxcodec/codec/fx_codec_jbig.cpp51
2 files changed, 44 insertions, 23 deletions
diff --git a/core/src/fxcodec/codec/codec_int.h b/core/src/fxcodec/codec/codec_int.h
index 10d0c3fd79..b08dee7422 100644
--- a/core/src/fxcodec/codec/codec_int.h
+++ b/core/src/fxcodec/codec/codec_int.h
@@ -274,10 +274,8 @@ class CCodec_Jbig2Context {
FX_DWORD m_width;
FX_DWORD m_height;
- uint8_t* m_src_buf;
- FX_DWORD m_src_size;
- const uint8_t* m_global_data;
- FX_DWORD m_global_size;
+ CPDF_StreamAcc* m_pGlobalStream;
+ CPDF_StreamAcc* m_pSrcStream;
uint8_t* m_dest_buf;
FX_DWORD m_dest_pitch;
IFX_Pause* m_pPause;
@@ -292,21 +290,17 @@ class CCodec_Jbig2Module : public ICodec_Jbig2Module {
// ICodec_Jbig2Module
void* CreateJbig2Context() override;
FXCODEC_STATUS StartDecode(void* pJbig2Context,
+ CFX_PrivateData* pPrivateData,
FX_DWORD width,
FX_DWORD height,
- const uint8_t* src_buf,
- FX_DWORD src_size,
- const uint8_t* global_data,
- FX_DWORD global_size,
+ CPDF_StreamAcc* src_stream,
+ CPDF_StreamAcc* global_stream,
uint8_t* dest_buf,
FX_DWORD dest_pitch,
IFX_Pause* pPause) override;
FXCODEC_STATUS ContinueDecode(void* pJbig2Context,
IFX_Pause* pPause) override;
void DestroyJbig2Context(void* pJbig2Context) override;
-
- private:
- std::list<CJBig2_CachePair> m_SymbolDictCache;
};
struct DecodeData {
diff --git a/core/src/fxcodec/codec/fx_codec_jbig.cpp b/core/src/fxcodec/codec/fx_codec_jbig.cpp
index 18a665784a..1524b68df0 100644
--- a/core/src/fxcodec/codec/fx_codec_jbig.cpp
+++ b/core/src/fxcodec/codec/fx_codec_jbig.cpp
@@ -7,14 +7,41 @@
#include "../../../include/fxcodec/fx_codec.h"
#include "codec_int.h"
+// Holds per-document JBig2 related data.
+class JBig2DocumentContext : public CFX_DestructObject {
+ public:
+ std::list<CJBig2_CachePair>* GetSymbolDictCache() {
+ return &m_SymbolDictCache;
+ }
+
+ ~JBig2DocumentContext() {
+ for (auto it : m_SymbolDictCache) {
+ delete it.second;
+ }
+ }
+
+ private:
+ std::list<CJBig2_CachePair> m_SymbolDictCache;
+};
+
+JBig2DocumentContext* GetJBig2DocumentContext(CCodec_Jbig2Module* pModule,
+ CFX_PrivateData* pPrivateData) {
+ void* pModulePrivateData = pPrivateData->GetPrivateData(pModule);
+ if (pModulePrivateData) {
+ CFX_DestructObject* pDestructObject =
+ reinterpret_cast<CFX_DestructObject*>(pModulePrivateData);
+ return static_cast<JBig2DocumentContext*>(pDestructObject);
+ }
+ JBig2DocumentContext* pJBig2DocumentContext = new JBig2DocumentContext();
+ pPrivateData->SetPrivateObj(pModule, pJBig2DocumentContext);
+ return pJBig2DocumentContext;
+}
+
CCodec_Jbig2Context::CCodec_Jbig2Context() {
FXSYS_memset(this, 0, sizeof(CCodec_Jbig2Context));
}
CCodec_Jbig2Module::~CCodec_Jbig2Module() {
- for (auto it : m_SymbolDictCache) {
- delete it.second;
- }
}
void* CCodec_Jbig2Module::CreateJbig2Context() {
@@ -29,31 +56,31 @@ void CCodec_Jbig2Module::DestroyJbig2Context(void* pJbig2Content) {
pJbig2Content = NULL;
}
FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(void* pJbig2Context,
+ CFX_PrivateData* pPrivateData,
FX_DWORD width,
FX_DWORD height,
- const uint8_t* src_buf,
- FX_DWORD src_size,
- const uint8_t* global_data,
- FX_DWORD global_size,
+ CPDF_StreamAcc* src_stream,
+ CPDF_StreamAcc* global_stream,
uint8_t* dest_buf,
FX_DWORD dest_pitch,
IFX_Pause* pPause) {
if (!pJbig2Context) {
return FXCODEC_STATUS_ERR_PARAMS;
}
+ JBig2DocumentContext* pJBig2DocumentContext =
+ GetJBig2DocumentContext(this, pPrivateData);
CCodec_Jbig2Context* m_pJbig2Context = (CCodec_Jbig2Context*)pJbig2Context;
m_pJbig2Context->m_width = width;
m_pJbig2Context->m_height = height;
- m_pJbig2Context->m_src_buf = (unsigned char*)src_buf;
- m_pJbig2Context->m_src_size = src_size;
- m_pJbig2Context->m_global_data = global_data;
- m_pJbig2Context->m_global_size = global_size;
+ m_pJbig2Context->m_pSrcStream = src_stream;
+ m_pJbig2Context->m_pGlobalStream = global_stream;
m_pJbig2Context->m_dest_buf = dest_buf;
m_pJbig2Context->m_dest_pitch = dest_pitch;
m_pJbig2Context->m_pPause = pPause;
FXSYS_memset(dest_buf, 0, height * dest_pitch);
m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(
- global_data, global_size, src_buf, src_size, &m_SymbolDictCache, pPause);
+ global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(),
+ pPause);
if (!m_pJbig2Context->m_pContext) {
return FXCODEC_STATUS_ERROR;
}