| 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 |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
| 12 #include "core/fxcodec/include/JBig2_DocumentContext.h" |
| 12 #include "core/fxcodec/jbig2/JBig2_Context.h" | 13 #include "core/fxcodec/jbig2/JBig2_Context.h" |
| 13 #include "core/fxcodec/jbig2/JBig2_Image.h" | 14 #include "core/fxcodec/jbig2/JBig2_Image.h" |
| 14 #include "core/fxcrt/include/fx_memory.h" | 15 #include "core/fxcrt/include/fx_memory.h" |
| 15 | 16 |
| 16 // Holds per-document JBig2 related data. | 17 JBig2_DocumentContext::JBig2_DocumentContext() {} |
| 17 class JBig2DocumentContext : public CFX_Deletable { | |
| 18 public: | |
| 19 std::list<CJBig2_CachePair>* GetSymbolDictCache() { | |
| 20 return &m_SymbolDictCache; | |
| 21 } | |
| 22 | 18 |
| 23 ~JBig2DocumentContext() override { | 19 JBig2_DocumentContext::~JBig2_DocumentContext() {} |
| 24 for (auto it : m_SymbolDictCache) { | |
| 25 delete it.second; | |
| 26 } | |
| 27 } | |
| 28 | 20 |
| 29 private: | 21 JBig2_DocumentContext* GetJBig2DocumentContext( |
| 30 std::list<CJBig2_CachePair> m_SymbolDictCache; | 22 std::unique_ptr<JBig2_DocumentContext>* pContextHolder) { |
| 31 }; | 23 if (!pContextHolder) |
| 32 | 24 pContextHolder->reset(new JBig2_DocumentContext()); |
| 33 JBig2DocumentContext* GetJBig2DocumentContext( | 25 return pContextHolder->get(); |
| 34 std::unique_ptr<CFX_Deletable>* pContextHolder) { | |
| 35 if (!pContextHolder->get()) | |
| 36 pContextHolder->reset(new JBig2DocumentContext()); | |
| 37 return static_cast<JBig2DocumentContext*>(pContextHolder->get()); | |
| 38 } | 26 } |
| 39 | 27 |
| 40 CCodec_Jbig2Context::CCodec_Jbig2Context() | 28 CCodec_Jbig2Context::CCodec_Jbig2Context() |
| 41 : m_width(0), | 29 : m_width(0), |
| 42 m_height(0), | 30 m_height(0), |
| 43 m_pGlobalStream(nullptr), | 31 m_pGlobalStream(nullptr), |
| 44 m_pSrcStream(nullptr), | 32 m_pSrcStream(nullptr), |
| 45 m_dest_buf(0), | 33 m_dest_buf(0), |
| 46 m_dest_pitch(0), | 34 m_dest_pitch(0), |
| 47 m_pPause(nullptr) {} | 35 m_pPause(nullptr) {} |
| 48 | 36 |
| 49 CCodec_Jbig2Context::~CCodec_Jbig2Context() {} | 37 CCodec_Jbig2Context::~CCodec_Jbig2Context() {} |
| 50 | 38 |
| 51 CCodec_Jbig2Module::~CCodec_Jbig2Module() {} | 39 CCodec_Jbig2Module::~CCodec_Jbig2Module() {} |
| 52 | 40 |
| 53 FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( | 41 FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( |
| 54 CCodec_Jbig2Context* pJbig2Context, | 42 CCodec_Jbig2Context* pJbig2Context, |
| 55 std::unique_ptr<CFX_Deletable>* pContextHolder, | 43 std::unique_ptr<JBig2_DocumentContext>* pContextHolder, |
| 56 uint32_t width, | 44 uint32_t width, |
| 57 uint32_t height, | 45 uint32_t height, |
| 58 CPDF_StreamAcc* src_stream, | 46 CPDF_StreamAcc* src_stream, |
| 59 CPDF_StreamAcc* global_stream, | 47 CPDF_StreamAcc* global_stream, |
| 60 uint8_t* dest_buf, | 48 uint8_t* dest_buf, |
| 61 uint32_t dest_pitch, | 49 uint32_t dest_pitch, |
| 62 IFX_Pause* pPause) { | 50 IFX_Pause* pPause) { |
| 63 if (!pJbig2Context) | 51 if (!pJbig2Context) |
| 64 return FXCODEC_STATUS_ERR_PARAMS; | 52 return FXCODEC_STATUS_ERR_PARAMS; |
| 65 | 53 |
| 66 JBig2DocumentContext* pJBig2DocumentContext = | 54 JBig2_DocumentContext* pJBig2DocumentContext = |
| 67 GetJBig2DocumentContext(pContextHolder); | 55 GetJBig2DocumentContext(pContextHolder); |
| 68 pJbig2Context->m_width = width; | 56 pJbig2Context->m_width = width; |
| 69 pJbig2Context->m_height = height; | 57 pJbig2Context->m_height = height; |
| 70 pJbig2Context->m_pSrcStream = src_stream; | 58 pJbig2Context->m_pSrcStream = src_stream; |
| 71 pJbig2Context->m_pGlobalStream = global_stream; | 59 pJbig2Context->m_pGlobalStream = global_stream; |
| 72 pJbig2Context->m_dest_buf = dest_buf; | 60 pJbig2Context->m_dest_buf = dest_buf; |
| 73 pJbig2Context->m_dest_pitch = dest_pitch; | 61 pJbig2Context->m_dest_pitch = dest_pitch; |
| 74 pJbig2Context->m_pPause = pPause; | 62 pJbig2Context->m_pPause = pPause; |
| 75 FXSYS_memset(dest_buf, 0, height * dest_pitch); | 63 FXSYS_memset(dest_buf, 0, height * dest_pitch); |
| 76 pJbig2Context->m_pContext.reset(new CJBig2_Context( | 64 pJbig2Context->m_pContext.reset(new CJBig2_Context( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 107 pJbig2Context->m_pContext.reset(); | 95 pJbig2Context->m_pContext.reset(); |
| 108 if (ret != JBIG2_SUCCESS) | 96 if (ret != JBIG2_SUCCESS) |
| 109 return FXCODEC_STATUS_ERROR; | 97 return FXCODEC_STATUS_ERROR; |
| 110 | 98 |
| 111 int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4; | 99 int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4; |
| 112 uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf; | 100 uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf; |
| 113 for (int i = 0; i < dword_size; i++) | 101 for (int i = 0; i < dword_size; i++) |
| 114 dword_buf[i] = ~dword_buf[i]; | 102 dword_buf[i] = ~dword_buf[i]; |
| 115 return FXCODEC_STATUS_DECODE_FINISH; | 103 return FXCODEC_STATUS_DECODE_FINISH; |
| 116 } | 104 } |
| OLD | NEW |