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 "../../../include/fxcodec/fx_codec.h" | 7 #include "../../../include/fxcodec/fx_codec.h" |
8 #include "codec_int.h" | 8 #include "codec_int.h" |
9 | 9 |
| 10 // Holds per-document JBig2 related data. |
| 11 class JBig2DocumentContext : public CFX_DestructObject { |
| 12 public: |
| 13 std::list<CJBig2_CachePair>* GetSymbolDictCache() { |
| 14 return &m_SymbolDictCache; |
| 15 } |
| 16 |
| 17 ~JBig2DocumentContext() { |
| 18 for (auto it : m_SymbolDictCache) { |
| 19 delete it.second; |
| 20 } |
| 21 } |
| 22 |
| 23 private: |
| 24 std::list<CJBig2_CachePair> m_SymbolDictCache; |
| 25 }; |
| 26 |
| 27 JBig2DocumentContext* GetJBig2DocumentContext(CCodec_Jbig2Module* pModule, |
| 28 CFX_PrivateData* pPrivateData) { |
| 29 void* pModulePrivateData = pPrivateData->GetPrivateData(pModule); |
| 30 if (pModulePrivateData) { |
| 31 CFX_DestructObject* pDestructObject = |
| 32 reinterpret_cast<CFX_DestructObject*>(pModulePrivateData); |
| 33 return static_cast<JBig2DocumentContext*>(pDestructObject); |
| 34 } |
| 35 JBig2DocumentContext* pJBig2DocumentContext = new JBig2DocumentContext(); |
| 36 pPrivateData->SetPrivateObj(pModule, pJBig2DocumentContext); |
| 37 return pJBig2DocumentContext; |
| 38 } |
| 39 |
10 CCodec_Jbig2Context::CCodec_Jbig2Context() { | 40 CCodec_Jbig2Context::CCodec_Jbig2Context() { |
11 FXSYS_memset(this, 0, sizeof(CCodec_Jbig2Context)); | 41 FXSYS_memset(this, 0, sizeof(CCodec_Jbig2Context)); |
12 } | 42 } |
13 | 43 |
14 CCodec_Jbig2Module::~CCodec_Jbig2Module() { | 44 CCodec_Jbig2Module::~CCodec_Jbig2Module() { |
15 for (auto it : m_SymbolDictCache) { | |
16 delete it.second; | |
17 } | |
18 } | 45 } |
19 | 46 |
20 void* CCodec_Jbig2Module::CreateJbig2Context() { | 47 void* CCodec_Jbig2Module::CreateJbig2Context() { |
21 return new CCodec_Jbig2Context(); | 48 return new CCodec_Jbig2Context(); |
22 } | 49 } |
23 void CCodec_Jbig2Module::DestroyJbig2Context(void* pJbig2Content) { | 50 void CCodec_Jbig2Module::DestroyJbig2Context(void* pJbig2Content) { |
24 if (pJbig2Content) { | 51 if (pJbig2Content) { |
25 CJBig2_Context::DestroyContext( | 52 CJBig2_Context::DestroyContext( |
26 ((CCodec_Jbig2Context*)pJbig2Content)->m_pContext); | 53 ((CCodec_Jbig2Context*)pJbig2Content)->m_pContext); |
27 delete (CCodec_Jbig2Context*)pJbig2Content; | 54 delete (CCodec_Jbig2Context*)pJbig2Content; |
28 } | 55 } |
29 pJbig2Content = NULL; | 56 pJbig2Content = NULL; |
30 } | 57 } |
31 FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(void* pJbig2Context, | 58 FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(void* pJbig2Context, |
| 59 CFX_PrivateData* pPrivateData, |
32 FX_DWORD width, | 60 FX_DWORD width, |
33 FX_DWORD height, | 61 FX_DWORD height, |
34 const uint8_t* src_buf, | 62 CPDF_StreamAcc* src_stream, |
35 FX_DWORD src_size, | 63 CPDF_StreamAcc* global_stream, |
36 const uint8_t* global_data, | |
37 FX_DWORD global_size, | |
38 uint8_t* dest_buf, | 64 uint8_t* dest_buf, |
39 FX_DWORD dest_pitch, | 65 FX_DWORD dest_pitch, |
40 IFX_Pause* pPause) { | 66 IFX_Pause* pPause) { |
41 if (!pJbig2Context) { | 67 if (!pJbig2Context) { |
42 return FXCODEC_STATUS_ERR_PARAMS; | 68 return FXCODEC_STATUS_ERR_PARAMS; |
43 } | 69 } |
| 70 JBig2DocumentContext* pJBig2DocumentContext = |
| 71 GetJBig2DocumentContext(this, pPrivateData); |
44 CCodec_Jbig2Context* m_pJbig2Context = (CCodec_Jbig2Context*)pJbig2Context; | 72 CCodec_Jbig2Context* m_pJbig2Context = (CCodec_Jbig2Context*)pJbig2Context; |
45 m_pJbig2Context->m_width = width; | 73 m_pJbig2Context->m_width = width; |
46 m_pJbig2Context->m_height = height; | 74 m_pJbig2Context->m_height = height; |
47 m_pJbig2Context->m_src_buf = (unsigned char*)src_buf; | 75 m_pJbig2Context->m_pSrcStream = src_stream; |
48 m_pJbig2Context->m_src_size = src_size; | 76 m_pJbig2Context->m_pGlobalStream = global_stream; |
49 m_pJbig2Context->m_global_data = global_data; | |
50 m_pJbig2Context->m_global_size = global_size; | |
51 m_pJbig2Context->m_dest_buf = dest_buf; | 77 m_pJbig2Context->m_dest_buf = dest_buf; |
52 m_pJbig2Context->m_dest_pitch = dest_pitch; | 78 m_pJbig2Context->m_dest_pitch = dest_pitch; |
53 m_pJbig2Context->m_pPause = pPause; | 79 m_pJbig2Context->m_pPause = pPause; |
54 FXSYS_memset(dest_buf, 0, height * dest_pitch); | 80 FXSYS_memset(dest_buf, 0, height * dest_pitch); |
55 m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext( | 81 m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext( |
56 global_data, global_size, src_buf, src_size, &m_SymbolDictCache, pPause); | 82 global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(), |
| 83 pPause); |
57 if (!m_pJbig2Context->m_pContext) { | 84 if (!m_pJbig2Context->m_pContext) { |
58 return FXCODEC_STATUS_ERROR; | 85 return FXCODEC_STATUS_ERROR; |
59 } | 86 } |
60 int ret = m_pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, | 87 int ret = m_pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, |
61 dest_pitch, pPause); | 88 dest_pitch, pPause); |
62 if (m_pJbig2Context->m_pContext->GetProcessingStatus() == | 89 if (m_pJbig2Context->m_pContext->GetProcessingStatus() == |
63 FXCODEC_STATUS_DECODE_FINISH) { | 90 FXCODEC_STATUS_DECODE_FINISH) { |
64 CJBig2_Context::DestroyContext(m_pJbig2Context->m_pContext); | 91 CJBig2_Context::DestroyContext(m_pJbig2Context->m_pContext); |
65 m_pJbig2Context->m_pContext = NULL; | 92 m_pJbig2Context->m_pContext = NULL; |
66 if (ret != JBIG2_SUCCESS) { | 93 if (ret != JBIG2_SUCCESS) { |
(...skipping 22 matching lines...) Expand all Loading... |
89 return FXCODEC_STATUS_ERROR; | 116 return FXCODEC_STATUS_ERROR; |
90 } | 117 } |
91 int dword_size = | 118 int dword_size = |
92 m_pJbig2Context->m_height * m_pJbig2Context->m_dest_pitch / 4; | 119 m_pJbig2Context->m_height * m_pJbig2Context->m_dest_pitch / 4; |
93 FX_DWORD* dword_buf = (FX_DWORD*)m_pJbig2Context->m_dest_buf; | 120 FX_DWORD* dword_buf = (FX_DWORD*)m_pJbig2Context->m_dest_buf; |
94 for (int i = 0; i < dword_size; i++) { | 121 for (int i = 0; i < dword_size; i++) { |
95 dword_buf[i] = ~dword_buf[i]; | 122 dword_buf[i] = ~dword_buf[i]; |
96 } | 123 } |
97 return FXCODEC_STATUS_DECODE_FINISH; | 124 return FXCODEC_STATUS_DECODE_FINISH; |
98 } | 125 } |
OLD | NEW |