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 CCodec_Jbig2Context::CCodec_Jbig2Context() | 9 CCodec_Jbig2Context::CCodec_Jbig2Context() |
10 { | 10 { |
(...skipping 12 matching lines...) Expand all Loading... |
23 CJBig2_Context::DestroyContext(((CCodec_Jbig2Context*)pJbig2Content)->m_
pContext); | 23 CJBig2_Context::DestroyContext(((CCodec_Jbig2Context*)pJbig2Content)->m_
pContext); |
24 delete (CCodec_Jbig2Context*)pJbig2Content; | 24 delete (CCodec_Jbig2Context*)pJbig2Content; |
25 } | 25 } |
26 pJbig2Content = NULL; | 26 pJbig2Content = NULL; |
27 } | 27 } |
28 FX_BOOL CCodec_Jbig2Module::Decode(FX_DWORD width, FX_DWORD height, FX_LPCBYTE s
rc_buf, FX_DWORD src_size, | 28 FX_BOOL CCodec_Jbig2Module::Decode(FX_DWORD width, FX_DWORD height, FX_LPCBYTE s
rc_buf, FX_DWORD src_size, |
29 FX_LPCBYTE global_data, FX_DWORD global_size,
FX_LPBYTE dest_buf, FX_DWORD dest_pitch) | 29 FX_LPCBYTE global_data, FX_DWORD global_size,
FX_LPBYTE dest_buf, FX_DWORD dest_pitch) |
30 { | 30 { |
31 FXSYS_memset32(dest_buf, 0, height * dest_pitch); | 31 FXSYS_memset32(dest_buf, 0, height * dest_pitch); |
32 CJBig2_Context* pContext = CJBig2_Context::CreateContext(&m_Module, | 32 CJBig2_Context* pContext = CJBig2_Context::CreateContext(&m_Module, |
33 (FX_LPBYTE)global_data, global_size, (FX_LPBYTE)s
rc_buf, src_size, JBIG2_EMBED_STREAM); | 33 (FX_LPBYTE)global_data, global_size, (FX_LPBYTE)s
rc_buf, src_size, JBIG2_EMBED_STREAM, &m_SymbolDictCache); |
34 if (pContext == NULL) { | 34 if (pContext == NULL) { |
35 return FALSE; | 35 return FALSE; |
36 } | 36 } |
37 int ret = pContext->getFirstPage(dest_buf, width, height, dest_pitch, NULL); | 37 int ret = pContext->getFirstPage(dest_buf, width, height, dest_pitch, NULL); |
38 CJBig2_Context::DestroyContext(pContext); | 38 CJBig2_Context::DestroyContext(pContext); |
39 if (ret != JBIG2_SUCCESS) { | 39 if (ret != JBIG2_SUCCESS) { |
40 return FALSE; | 40 return FALSE; |
41 } | 41 } |
42 int dword_size = height * dest_pitch / 4; | 42 int dword_size = height * dest_pitch / 4; |
43 FX_DWORD* dword_buf = (FX_DWORD*)dest_buf; | 43 FX_DWORD* dword_buf = (FX_DWORD*)dest_buf; |
44 for (int i = 0; i < dword_size; i ++) { | 44 for (int i = 0; i < dword_size; i ++) { |
45 dword_buf[i] = ~dword_buf[i]; | 45 dword_buf[i] = ~dword_buf[i]; |
46 } | 46 } |
47 return TRUE; | 47 return TRUE; |
48 } | 48 } |
49 FX_BOOL CCodec_Jbig2Module::Decode(IFX_FileRead* file_ptr, | 49 FX_BOOL CCodec_Jbig2Module::Decode(IFX_FileRead* file_ptr, |
50 FX_DWORD& width, FX_DWORD& height, FX_DWORD&
pitch, FX_LPBYTE& dest_buf) | 50 FX_DWORD& width, FX_DWORD& height, FX_DWORD&
pitch, FX_LPBYTE& dest_buf) |
51 { | 51 { |
52 CJBig2_Context* pContext = NULL; | 52 CJBig2_Context* pContext = NULL; |
53 CJBig2_Image* dest_image = NULL; | 53 CJBig2_Image* dest_image = NULL; |
54 FX_DWORD src_size = (FX_DWORD)file_ptr->GetSize(); | 54 FX_DWORD src_size = (FX_DWORD)file_ptr->GetSize(); |
55 FX_LPBYTE src_buf = FX_Alloc(FX_BYTE, src_size); | 55 FX_LPBYTE src_buf = FX_Alloc(FX_BYTE, src_size); |
56 if (src_buf == NULL) { | 56 if (src_buf == NULL) { |
57 return FALSE; | 57 return FALSE; |
58 } | 58 } |
59 int ret = 0; | 59 int ret = 0; |
60 if(!file_ptr->ReadBlock(src_buf, 0, src_size)) { | 60 if(!file_ptr->ReadBlock(src_buf, 0, src_size)) { |
61 goto failed; | 61 goto failed; |
62 } | 62 } |
63 pContext = CJBig2_Context::CreateContext(&m_Module, NULL, 0, src_buf, src_si
ze, JBIG2_FILE_STREAM); | 63 pContext = CJBig2_Context::CreateContext(&m_Module, NULL, 0, src_buf, src_si
ze, JBIG2_FILE_STREAM, &m_SymbolDictCache); |
64 if(pContext == NULL) { | 64 if(pContext == NULL) { |
65 goto failed; | 65 goto failed; |
66 } | 66 } |
67 ret = pContext->getFirstPage(&dest_image, NULL); | 67 ret = pContext->getFirstPage(&dest_image, NULL); |
68 CJBig2_Context::DestroyContext(pContext); | 68 CJBig2_Context::DestroyContext(pContext); |
69 if (ret != JBIG2_SUCCESS) { | 69 if (ret != JBIG2_SUCCESS) { |
70 goto failed; | 70 goto failed; |
71 } | 71 } |
72 width = (FX_DWORD)dest_image->m_nWidth; | 72 width = (FX_DWORD)dest_image->m_nWidth; |
73 height = (FX_DWORD)dest_image->m_nHeight; | 73 height = (FX_DWORD)dest_image->m_nHeight; |
(...skipping 21 matching lines...) Expand all Loading... |
95 m_pJbig2Context->m_src_buf = (unsigned char *)src_buf; | 95 m_pJbig2Context->m_src_buf = (unsigned char *)src_buf; |
96 m_pJbig2Context->m_src_size = src_size; | 96 m_pJbig2Context->m_src_size = src_size; |
97 m_pJbig2Context->m_global_data = global_data; | 97 m_pJbig2Context->m_global_data = global_data; |
98 m_pJbig2Context->m_global_size = global_size; | 98 m_pJbig2Context->m_global_size = global_size; |
99 m_pJbig2Context->m_dest_buf = dest_buf; | 99 m_pJbig2Context->m_dest_buf = dest_buf; |
100 m_pJbig2Context->m_dest_pitch = dest_pitch; | 100 m_pJbig2Context->m_dest_pitch = dest_pitch; |
101 m_pJbig2Context->m_pPause = pPause; | 101 m_pJbig2Context->m_pPause = pPause; |
102 m_pJbig2Context->m_bFileReader = FALSE; | 102 m_pJbig2Context->m_bFileReader = FALSE; |
103 FXSYS_memset32(dest_buf, 0, height * dest_pitch); | 103 FXSYS_memset32(dest_buf, 0, height * dest_pitch); |
104 m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(&m_Module, | 104 m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(&m_Module, |
105 (FX_LPBYTE)global_data, global_size, (FX_LPBYT
E)src_buf, src_size, JBIG2_EMBED_STREAM, pPause); | 105 (FX_LPBYTE)global_data, global_size, (FX_LPBYT
E)src_buf, src_size, JBIG2_EMBED_STREAM, &m_SymbolDictCache, pPause); |
106 if(!m_pJbig2Context->m_pContext) { | 106 if(!m_pJbig2Context->m_pContext) { |
107 return FXCODEC_STATUS_ERROR; | 107 return FXCODEC_STATUS_ERROR; |
108 } | 108 } |
109 int ret = m_pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height,
dest_pitch, pPause); | 109 int ret = m_pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height,
dest_pitch, pPause); |
110 if(m_pJbig2Context->m_pContext->GetProcessiveStatus() == FXCODEC_STATUS_DECO
DE_FINISH) { | 110 if(m_pJbig2Context->m_pContext->GetProcessiveStatus() == FXCODEC_STATUS_DECO
DE_FINISH) { |
111 CJBig2_Context::DestroyContext(m_pJbig2Context->m_pContext); | 111 CJBig2_Context::DestroyContext(m_pJbig2Context->m_pContext); |
112 m_pJbig2Context->m_pContext = NULL; | 112 m_pJbig2Context->m_pContext = NULL; |
113 if (ret != JBIG2_SUCCESS) { | 113 if (ret != JBIG2_SUCCESS) { |
114 return FXCODEC_STATUS_ERROR; | 114 return FXCODEC_STATUS_ERROR; |
115 } | 115 } |
(...skipping 17 matching lines...) Expand all Loading... |
133 m_pJbig2Context->m_dest_image = NULL; | 133 m_pJbig2Context->m_dest_image = NULL; |
134 m_pJbig2Context->m_src_size = (FX_DWORD)file_ptr->GetSize(); | 134 m_pJbig2Context->m_src_size = (FX_DWORD)file_ptr->GetSize(); |
135 m_pJbig2Context->m_src_buf = FX_Alloc(FX_BYTE, m_pJbig2Context->m_src_size); | 135 m_pJbig2Context->m_src_buf = FX_Alloc(FX_BYTE, m_pJbig2Context->m_src_size); |
136 if (m_pJbig2Context->m_src_buf == NULL) { | 136 if (m_pJbig2Context->m_src_buf == NULL) { |
137 return FXCODEC_STATUS_ERR_MEMORY; | 137 return FXCODEC_STATUS_ERR_MEMORY; |
138 } | 138 } |
139 int ret = 0; | 139 int ret = 0; |
140 if(!file_ptr->ReadBlock((void*)m_pJbig2Context->m_src_buf, 0, m_pJbig2Contex
t->m_src_size)) { | 140 if(!file_ptr->ReadBlock((void*)m_pJbig2Context->m_src_buf, 0, m_pJbig2Contex
t->m_src_size)) { |
141 goto failed; | 141 goto failed; |
142 } | 142 } |
143 m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(&m_Module, NULL,
0, m_pJbig2Context->m_src_buf, m_pJbig2Context->m_src_size, JBIG2_FILE_STREAM,
pPause); | 143 m_pJbig2Context->m_pContext = CJBig2_Context::CreateContext(&m_Module, NULL,
0, m_pJbig2Context->m_src_buf, m_pJbig2Context->m_src_size, JBIG2_FILE_STREAM,
&m_SymbolDictCache, pPause); |
144 if(m_pJbig2Context->m_pContext == NULL) { | 144 if(m_pJbig2Context->m_pContext == NULL) { |
145 goto failed; | 145 goto failed; |
146 } | 146 } |
147 ret = m_pJbig2Context->m_pContext->getFirstPage(&m_pJbig2Context->m_dest_ima
ge, pPause); | 147 ret = m_pJbig2Context->m_pContext->getFirstPage(&m_pJbig2Context->m_dest_ima
ge, pPause); |
148 if(m_pJbig2Context->m_pContext->GetProcessiveStatus() == FXCODEC_STATUS_DECO
DE_TOBECONTINUE) { | 148 if(m_pJbig2Context->m_pContext->GetProcessiveStatus() == FXCODEC_STATUS_DECO
DE_TOBECONTINUE) { |
149 width = (FX_DWORD)m_pJbig2Context->m_dest_image->m_nWidth; | 149 width = (FX_DWORD)m_pJbig2Context->m_dest_image->m_nWidth; |
150 height = (FX_DWORD)m_pJbig2Context->m_dest_image->m_nHeight; | 150 height = (FX_DWORD)m_pJbig2Context->m_dest_image->m_nHeight; |
151 pitch = (FX_DWORD)m_pJbig2Context->m_dest_image->m_nStride; | 151 pitch = (FX_DWORD)m_pJbig2Context->m_dest_image->m_nStride; |
152 dest_buf = m_pJbig2Context->m_dest_image->m_pData; | 152 dest_buf = m_pJbig2Context->m_dest_image->m_pData; |
153 m_pJbig2Context->m_dest_image->m_bNeedFree = FALSE; | 153 m_pJbig2Context->m_dest_image->m_bNeedFree = FALSE; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 dword_buf[i] = ~dword_buf[i]; | 203 dword_buf[i] = ~dword_buf[i]; |
204 } | 204 } |
205 return FXCODEC_STATUS_DECODE_FINISH; | 205 return FXCODEC_STATUS_DECODE_FINISH; |
206 } | 206 } |
207 } | 207 } |
208 return m_pJbig2Context->m_pContext->GetProcessiveStatus(); | 208 return m_pJbig2Context->m_pContext->GetProcessiveStatus(); |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 | 212 |
OLD | NEW |