| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fxcodec/codec/ccodec_jbig2module.h" | 7 #include "core/fxcodec/codec/ccodec_jbig2module.h" |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 std::list<CJBig2_CachePair> m_SymbolDictCache; | 30 std::list<CJBig2_CachePair> m_SymbolDictCache; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 JBig2DocumentContext* GetJBig2DocumentContext( | 33 JBig2DocumentContext* GetJBig2DocumentContext( |
| 34 std::unique_ptr<CFX_Deletable>* pContextHolder) { | 34 std::unique_ptr<CFX_Deletable>* pContextHolder) { |
| 35 if (!pContextHolder->get()) | 35 if (!pContextHolder->get()) |
| 36 pContextHolder->reset(new JBig2DocumentContext()); | 36 pContextHolder->reset(new JBig2DocumentContext()); |
| 37 return static_cast<JBig2DocumentContext*>(pContextHolder->get()); | 37 return static_cast<JBig2DocumentContext*>(pContextHolder->get()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 CCodec_Jbig2Context::CCodec_Jbig2Context() { | 40 CCodec_Jbig2Context::CCodec_Jbig2Context() |
| 41 FXSYS_memset(this, 0, sizeof(CCodec_Jbig2Context)); | 41 : m_width(0), |
| 42 } | 42 m_height(0), |
| 43 m_pGlobalStream(nullptr), |
| 44 m_pSrcStream(nullptr), |
| 45 m_dest_buf(0), |
| 46 m_dest_pitch(0), |
| 47 m_pPause(nullptr) {} |
| 48 |
| 49 CCodec_Jbig2Context::~CCodec_Jbig2Context() {} |
| 43 | 50 |
| 44 CCodec_Jbig2Module::~CCodec_Jbig2Module() {} | 51 CCodec_Jbig2Module::~CCodec_Jbig2Module() {} |
| 45 | 52 |
| 46 CCodec_Jbig2Context* CCodec_Jbig2Module::CreateJbig2Context() { | |
| 47 return new CCodec_Jbig2Context(); | |
| 48 } | |
| 49 | |
| 50 void CCodec_Jbig2Module::DestroyJbig2Context( | |
| 51 CCodec_Jbig2Context* pJbig2Context) { | |
| 52 if (pJbig2Context) { | |
| 53 CJBig2_Context::DestroyContext(pJbig2Context->m_pContext); | |
| 54 delete pJbig2Context; | |
| 55 } | |
| 56 pJbig2Context = nullptr; | |
| 57 } | |
| 58 | |
| 59 FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( | 53 FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( |
| 60 CCodec_Jbig2Context* pJbig2Context, | 54 CCodec_Jbig2Context* pJbig2Context, |
| 61 std::unique_ptr<CFX_Deletable>* pContextHolder, | 55 std::unique_ptr<CFX_Deletable>* pContextHolder, |
| 62 uint32_t width, | 56 uint32_t width, |
| 63 uint32_t height, | 57 uint32_t height, |
| 64 CPDF_StreamAcc* src_stream, | 58 CPDF_StreamAcc* src_stream, |
| 65 CPDF_StreamAcc* global_stream, | 59 CPDF_StreamAcc* global_stream, |
| 66 uint8_t* dest_buf, | 60 uint8_t* dest_buf, |
| 67 uint32_t dest_pitch, | 61 uint32_t dest_pitch, |
| 68 IFX_Pause* pPause) { | 62 IFX_Pause* pPause) { |
| 69 if (!pJbig2Context) | 63 if (!pJbig2Context) |
| 70 return FXCODEC_STATUS_ERR_PARAMS; | 64 return FXCODEC_STATUS_ERR_PARAMS; |
| 71 | 65 |
| 72 JBig2DocumentContext* pJBig2DocumentContext = | 66 JBig2DocumentContext* pJBig2DocumentContext = |
| 73 GetJBig2DocumentContext(pContextHolder); | 67 GetJBig2DocumentContext(pContextHolder); |
| 74 pJbig2Context->m_width = width; | 68 pJbig2Context->m_width = width; |
| 75 pJbig2Context->m_height = height; | 69 pJbig2Context->m_height = height; |
| 76 pJbig2Context->m_pSrcStream = src_stream; | 70 pJbig2Context->m_pSrcStream = src_stream; |
| 77 pJbig2Context->m_pGlobalStream = global_stream; | 71 pJbig2Context->m_pGlobalStream = global_stream; |
| 78 pJbig2Context->m_dest_buf = dest_buf; | 72 pJbig2Context->m_dest_buf = dest_buf; |
| 79 pJbig2Context->m_dest_pitch = dest_pitch; | 73 pJbig2Context->m_dest_pitch = dest_pitch; |
| 80 pJbig2Context->m_pPause = pPause; | 74 pJbig2Context->m_pPause = pPause; |
| 81 FXSYS_memset(dest_buf, 0, height * dest_pitch); | 75 FXSYS_memset(dest_buf, 0, height * dest_pitch); |
| 82 pJbig2Context->m_pContext = CJBig2_Context::CreateContext( | 76 pJbig2Context->m_pContext.reset(new CJBig2_Context( |
| 83 global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(), | 77 global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(), |
| 84 pPause); | 78 pPause, false)); |
| 85 if (!pJbig2Context->m_pContext) | 79 if (!pJbig2Context->m_pContext) |
| 86 return FXCODEC_STATUS_ERROR; | 80 return FXCODEC_STATUS_ERROR; |
| 87 | 81 |
| 88 int ret = pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, | 82 int ret = pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, |
| 89 dest_pitch, pPause); | 83 dest_pitch, pPause); |
| 90 if (pJbig2Context->m_pContext->GetProcessingStatus() == | 84 if (pJbig2Context->m_pContext->GetProcessingStatus() == |
| 91 FXCODEC_STATUS_DECODE_FINISH) { | 85 FXCODEC_STATUS_DECODE_FINISH) { |
| 92 CJBig2_Context::DestroyContext(pJbig2Context->m_pContext); | 86 pJbig2Context->m_pContext.reset(); |
| 93 pJbig2Context->m_pContext = nullptr; | |
| 94 if (ret != JBIG2_SUCCESS) | 87 if (ret != JBIG2_SUCCESS) |
| 95 return FXCODEC_STATUS_ERROR; | 88 return FXCODEC_STATUS_ERROR; |
| 96 | 89 |
| 97 int dword_size = height * dest_pitch / 4; | 90 int dword_size = height * dest_pitch / 4; |
| 98 uint32_t* dword_buf = (uint32_t*)dest_buf; | 91 uint32_t* dword_buf = (uint32_t*)dest_buf; |
| 99 for (int i = 0; i < dword_size; i++) | 92 for (int i = 0; i < dword_size; i++) |
| 100 dword_buf[i] = ~dword_buf[i]; | 93 dword_buf[i] = ~dword_buf[i]; |
| 101 return FXCODEC_STATUS_DECODE_FINISH; | 94 return FXCODEC_STATUS_DECODE_FINISH; |
| 102 } | 95 } |
| 103 return pJbig2Context->m_pContext->GetProcessingStatus(); | 96 return pJbig2Context->m_pContext->GetProcessingStatus(); |
| 104 } | 97 } |
| 105 | 98 |
| 106 FXCODEC_STATUS CCodec_Jbig2Module::ContinueDecode( | 99 FXCODEC_STATUS CCodec_Jbig2Module::ContinueDecode( |
| 107 CCodec_Jbig2Context* pJbig2Context, | 100 CCodec_Jbig2Context* pJbig2Context, |
| 108 IFX_Pause* pPause) { | 101 IFX_Pause* pPause) { |
| 109 int ret = pJbig2Context->m_pContext->Continue(pPause); | 102 int ret = pJbig2Context->m_pContext->Continue(pPause); |
| 110 if (pJbig2Context->m_pContext->GetProcessingStatus() != | 103 if (pJbig2Context->m_pContext->GetProcessingStatus() != |
| 111 FXCODEC_STATUS_DECODE_FINISH) { | 104 FXCODEC_STATUS_DECODE_FINISH) { |
| 112 return pJbig2Context->m_pContext->GetProcessingStatus(); | 105 return pJbig2Context->m_pContext->GetProcessingStatus(); |
| 113 } | 106 } |
| 114 CJBig2_Context::DestroyContext(pJbig2Context->m_pContext); | 107 pJbig2Context->m_pContext.reset(); |
| 115 pJbig2Context->m_pContext = nullptr; | |
| 116 if (ret != JBIG2_SUCCESS) | 108 if (ret != JBIG2_SUCCESS) |
| 117 return FXCODEC_STATUS_ERROR; | 109 return FXCODEC_STATUS_ERROR; |
| 118 | 110 |
| 119 int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4; | 111 int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4; |
| 120 uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf; | 112 uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf; |
| 121 for (int i = 0; i < dword_size; i++) | 113 for (int i = 0; i < dword_size; i++) |
| 122 dword_buf[i] = ~dword_buf[i]; | 114 dword_buf[i] = ~dword_buf[i]; |
| 123 return FXCODEC_STATUS_DECODE_FINISH; | 115 return FXCODEC_STATUS_DECODE_FINISH; |
| 124 } | 116 } |
| OLD | NEW |