diff options
Diffstat (limited to 'core/fxcodec')
-rw-r--r-- | core/fxcodec/codec/ccodec_jbig2module.h | 28 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jbig.cpp | 119 |
2 files changed, 75 insertions, 72 deletions
diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/ccodec_jbig2module.h index a967e0b997..63e63afcfa 100644 --- a/core/fxcodec/codec/ccodec_jbig2module.h +++ b/core/fxcodec/codec/ccodec_jbig2module.h @@ -9,18 +9,37 @@ #include <memory> +#include "core/fxcodec/include/fx_codec_def.h" #include "core/fxcrt/include/fx_basic.h" +class CJBig2_Context; +class CJBig2_Image; class CPDF_StreamAcc; class IFX_Pause; +class CCodec_Jbig2Context { + public: + CCodec_Jbig2Context(); + ~CCodec_Jbig2Context() {} + + uint32_t m_width; + uint32_t m_height; + CPDF_StreamAcc* m_pGlobalStream; + CPDF_StreamAcc* m_pSrcStream; + uint8_t* m_dest_buf; + uint32_t m_dest_pitch; + IFX_Pause* m_pPause; + CJBig2_Context* m_pContext; + CJBig2_Image* m_dest_image; +}; + class CCodec_Jbig2Module { public: CCodec_Jbig2Module() {} ~CCodec_Jbig2Module(); - void* CreateJbig2Context(); - FXCODEC_STATUS StartDecode(void* pJbig2Context, + CCodec_Jbig2Context* CreateJbig2Context(); + FXCODEC_STATUS StartDecode(CCodec_Jbig2Context* pJbig2Context, std::unique_ptr<CFX_Deletable>* pContextHolder, uint32_t width, uint32_t height, @@ -29,8 +48,9 @@ class CCodec_Jbig2Module { uint8_t* dest_buf, uint32_t dest_pitch, IFX_Pause* pPause); - FXCODEC_STATUS ContinueDecode(void* pJbig2Context, IFX_Pause* pPause); - void DestroyJbig2Context(void* pJbig2Context); + FXCODEC_STATUS ContinueDecode(CCodec_Jbig2Context* pJbig2Context, + IFX_Pause* pPause); + void DestroyJbig2Context(CCodec_Jbig2Context* pJbig2Context); }; #endif // CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_ diff --git a/core/fxcodec/codec/fx_codec_jbig.cpp b/core/fxcodec/codec/fx_codec_jbig.cpp index 30798fe361..4876cef53d 100644 --- a/core/fxcodec/codec/fx_codec_jbig.cpp +++ b/core/fxcodec/codec/fx_codec_jbig.cpp @@ -4,30 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include <list> - -#include "core/fxcodec/codec/codec_int.h" -#include "core/fxcodec/include/fx_codec.h" - -namespace { +#include "core/fxcodec/codec/ccodec_jbig2module.h" -class CCodec_Jbig2Context { - public: - CCodec_Jbig2Context(); - ~CCodec_Jbig2Context() {} - - uint32_t m_width; - uint32_t m_height; - CPDF_StreamAcc* m_pGlobalStream; - CPDF_StreamAcc* m_pSrcStream; - uint8_t* m_dest_buf; - uint32_t m_dest_pitch; - IFX_Pause* m_pPause; - CJBig2_Context* m_pContext; - CJBig2_Image* m_dest_image; -}; +#include <list> -} // namespace +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" +#include "core/fxcodec/jbig2/JBig2_Context.h" +#include "core/fxcodec/jbig2/JBig2_Image.h" +#include "core/fxcrt/include/fx_memory.h" // Holds per-document JBig2 related data. class JBig2DocumentContext : public CFX_Deletable { @@ -59,19 +43,21 @@ CCodec_Jbig2Context::CCodec_Jbig2Context() { CCodec_Jbig2Module::~CCodec_Jbig2Module() {} -void* CCodec_Jbig2Module::CreateJbig2Context() { +CCodec_Jbig2Context* CCodec_Jbig2Module::CreateJbig2Context() { return new CCodec_Jbig2Context(); } -void CCodec_Jbig2Module::DestroyJbig2Context(void* pJbig2Content) { - if (pJbig2Content) { - CJBig2_Context::DestroyContext( - ((CCodec_Jbig2Context*)pJbig2Content)->m_pContext); - delete (CCodec_Jbig2Context*)pJbig2Content; + +void CCodec_Jbig2Module::DestroyJbig2Context( + CCodec_Jbig2Context* pJbig2Context) { + if (pJbig2Context) { + CJBig2_Context::DestroyContext(pJbig2Context->m_pContext); + delete pJbig2Context; } - pJbig2Content = nullptr; + pJbig2Context = nullptr; } + FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( - void* pJbig2Context, + CCodec_Jbig2Context* pJbig2Context, std::unique_ptr<CFX_Deletable>* pContextHolder, uint32_t width, uint32_t height, @@ -80,62 +66,59 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( uint8_t* dest_buf, uint32_t dest_pitch, IFX_Pause* pPause) { - if (!pJbig2Context) { + if (!pJbig2Context) return FXCODEC_STATUS_ERR_PARAMS; - } + JBig2DocumentContext* pJBig2DocumentContext = GetJBig2DocumentContext(pContextHolder); - CCodec_Jbig2Context* m_pJbig2Context = (CCodec_Jbig2Context*)pJbig2Context; - m_pJbig2Context->m_width = width; - m_pJbig2Context->m_height = height; - 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; + pJbig2Context->m_width = width; + pJbig2Context->m_height = height; + pJbig2Context->m_pSrcStream = src_stream; + pJbig2Context->m_pGlobalStream = global_stream; + pJbig2Context->m_dest_buf = dest_buf; + pJbig2Context->m_dest_pitch = dest_pitch; + pJbig2Context->m_pPause = pPause; FXSYS_memset(dest_buf, 0, height * dest_pitch); - m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext( + pJbig2Context->m_pContext = CJBig2_Context::CreateContext( global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(), pPause); - if (!m_pJbig2Context->m_pContext) { + if (!pJbig2Context->m_pContext) return FXCODEC_STATUS_ERROR; - } - int ret = m_pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, - dest_pitch, pPause); - if (m_pJbig2Context->m_pContext->GetProcessingStatus() == + + int ret = pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, + dest_pitch, pPause); + if (pJbig2Context->m_pContext->GetProcessingStatus() == FXCODEC_STATUS_DECODE_FINISH) { - CJBig2_Context::DestroyContext(m_pJbig2Context->m_pContext); - m_pJbig2Context->m_pContext = nullptr; - if (ret != JBIG2_SUCCESS) { + CJBig2_Context::DestroyContext(pJbig2Context->m_pContext); + pJbig2Context->m_pContext = nullptr; + if (ret != JBIG2_SUCCESS) return FXCODEC_STATUS_ERROR; - } + int dword_size = height * dest_pitch / 4; uint32_t* dword_buf = (uint32_t*)dest_buf; - for (int i = 0; i < dword_size; i++) { + for (int i = 0; i < dword_size; i++) dword_buf[i] = ~dword_buf[i]; - } return FXCODEC_STATUS_DECODE_FINISH; } - return m_pJbig2Context->m_pContext->GetProcessingStatus(); + return pJbig2Context->m_pContext->GetProcessingStatus(); } -FXCODEC_STATUS CCodec_Jbig2Module::ContinueDecode(void* pJbig2Context, - IFX_Pause* pPause) { - CCodec_Jbig2Context* m_pJbig2Context = (CCodec_Jbig2Context*)pJbig2Context; - int ret = m_pJbig2Context->m_pContext->Continue(pPause); - if (m_pJbig2Context->m_pContext->GetProcessingStatus() != + +FXCODEC_STATUS CCodec_Jbig2Module::ContinueDecode( + CCodec_Jbig2Context* pJbig2Context, + IFX_Pause* pPause) { + int ret = pJbig2Context->m_pContext->Continue(pPause); + if (pJbig2Context->m_pContext->GetProcessingStatus() != FXCODEC_STATUS_DECODE_FINISH) { - return m_pJbig2Context->m_pContext->GetProcessingStatus(); + return pJbig2Context->m_pContext->GetProcessingStatus(); } - CJBig2_Context::DestroyContext(m_pJbig2Context->m_pContext); - m_pJbig2Context->m_pContext = nullptr; - if (ret != JBIG2_SUCCESS) { + CJBig2_Context::DestroyContext(pJbig2Context->m_pContext); + pJbig2Context->m_pContext = nullptr; + if (ret != JBIG2_SUCCESS) return FXCODEC_STATUS_ERROR; - } - int dword_size = - m_pJbig2Context->m_height * m_pJbig2Context->m_dest_pitch / 4; - uint32_t* dword_buf = (uint32_t*)m_pJbig2Context->m_dest_buf; - for (int i = 0; i < dword_size; i++) { + + int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4; + uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf; + for (int i = 0; i < dword_size; i++) dword_buf[i] = ~dword_buf[i]; - } return FXCODEC_STATUS_DECODE_FINISH; } |