| 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 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 12 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
| 13 #include "core/fxcodec/JBig2_DocumentContext.h" | 13 #include "core/fxcodec/JBig2_DocumentContext.h" |
| 14 #include "core/fxcodec/jbig2/JBig2_Context.h" | 14 #include "core/fxcodec/jbig2/JBig2_Context.h" |
| 15 #include "core/fxcodec/jbig2/JBig2_Image.h" | 15 #include "core/fxcodec/jbig2/JBig2_Image.h" |
| 16 #include "core/fxcrt/fx_memory.h" | 16 #include "core/fxcrt/fx_memory.h" |
| 17 #include "third_party/base/ptr_util.h" |
| 17 | 18 |
| 18 JBig2_DocumentContext::JBig2_DocumentContext() {} | 19 JBig2_DocumentContext::JBig2_DocumentContext() {} |
| 19 | 20 |
| 20 JBig2_DocumentContext::~JBig2_DocumentContext() {} | 21 JBig2_DocumentContext::~JBig2_DocumentContext() {} |
| 21 | 22 |
| 22 JBig2_DocumentContext* GetJBig2DocumentContext( | 23 JBig2_DocumentContext* GetJBig2DocumentContext( |
| 23 std::unique_ptr<JBig2_DocumentContext>* pContextHolder) { | 24 std::unique_ptr<JBig2_DocumentContext>* pContextHolder) { |
| 24 if (!pContextHolder->get()) | 25 if (!pContextHolder->get()) |
| 25 pContextHolder->reset(new JBig2_DocumentContext()); | 26 *pContextHolder = pdfium::MakeUnique<JBig2_DocumentContext>(); |
| 26 return pContextHolder->get(); | 27 return pContextHolder->get(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 CCodec_Jbig2Context::CCodec_Jbig2Context() | 30 CCodec_Jbig2Context::CCodec_Jbig2Context() |
| 30 : m_width(0), | 31 : m_width(0), |
| 31 m_height(0), | 32 m_height(0), |
| 32 m_pGlobalStream(nullptr), | 33 m_pGlobalStream(nullptr), |
| 33 m_pSrcStream(nullptr), | 34 m_pSrcStream(nullptr), |
| 34 m_dest_buf(0), | 35 m_dest_buf(0), |
| 35 m_dest_pitch(0), | 36 m_dest_pitch(0), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 55 JBig2_DocumentContext* pJBig2DocumentContext = | 56 JBig2_DocumentContext* pJBig2DocumentContext = |
| 56 GetJBig2DocumentContext(pContextHolder); | 57 GetJBig2DocumentContext(pContextHolder); |
| 57 pJbig2Context->m_width = width; | 58 pJbig2Context->m_width = width; |
| 58 pJbig2Context->m_height = height; | 59 pJbig2Context->m_height = height; |
| 59 pJbig2Context->m_pSrcStream = src_stream; | 60 pJbig2Context->m_pSrcStream = src_stream; |
| 60 pJbig2Context->m_pGlobalStream = global_stream; | 61 pJbig2Context->m_pGlobalStream = global_stream; |
| 61 pJbig2Context->m_dest_buf = dest_buf; | 62 pJbig2Context->m_dest_buf = dest_buf; |
| 62 pJbig2Context->m_dest_pitch = dest_pitch; | 63 pJbig2Context->m_dest_pitch = dest_pitch; |
| 63 pJbig2Context->m_pPause = pPause; | 64 pJbig2Context->m_pPause = pPause; |
| 64 FXSYS_memset(dest_buf, 0, height * dest_pitch); | 65 FXSYS_memset(dest_buf, 0, height * dest_pitch); |
| 65 pJbig2Context->m_pContext.reset(new CJBig2_Context( | 66 pJbig2Context->m_pContext = pdfium::MakeUnique<CJBig2_Context>( |
| 66 global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(), | 67 global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(), |
| 67 pPause, false)); | 68 pPause, false); |
| 68 if (!pJbig2Context->m_pContext) | 69 if (!pJbig2Context->m_pContext) |
| 69 return FXCODEC_STATUS_ERROR; | 70 return FXCODEC_STATUS_ERROR; |
| 70 | 71 |
| 71 int ret = pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, | 72 int ret = pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, |
| 72 dest_pitch, pPause); | 73 dest_pitch, pPause); |
| 73 if (pJbig2Context->m_pContext->GetProcessingStatus() == | 74 if (pJbig2Context->m_pContext->GetProcessingStatus() == |
| 74 FXCODEC_STATUS_DECODE_FINISH) { | 75 FXCODEC_STATUS_DECODE_FINISH) { |
| 75 pJbig2Context->m_pContext.reset(); | 76 pJbig2Context->m_pContext.reset(); |
| 76 if (ret != JBIG2_SUCCESS) | 77 if (ret != JBIG2_SUCCESS) |
| 77 return FXCODEC_STATUS_ERROR; | 78 return FXCODEC_STATUS_ERROR; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 96 pJbig2Context->m_pContext.reset(); | 97 pJbig2Context->m_pContext.reset(); |
| 97 if (ret != JBIG2_SUCCESS) | 98 if (ret != JBIG2_SUCCESS) |
| 98 return FXCODEC_STATUS_ERROR; | 99 return FXCODEC_STATUS_ERROR; |
| 99 | 100 |
| 100 int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4; | 101 int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4; |
| 101 uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf; | 102 uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf; |
| 102 for (int i = 0; i < dword_size; i++) | 103 for (int i = 0; i < dword_size; i++) |
| 103 dword_buf[i] = ~dword_buf[i]; | 104 dword_buf[i] = ~dword_buf[i]; |
| 104 return FXCODEC_STATUS_DECODE_FINISH; | 105 return FXCODEC_STATUS_DECODE_FINISH; |
| 105 } | 106 } |
| OLD | NEW |