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/include/fxcodec/fx_codec.h" | 7 #include "core/include/fxcodec/fx_codec.h" |
8 #include "core/include/fxge/fx_dib.h" | 8 #include "core/include/fxge/fx_dib.h" |
9 #include "core/src/fxcodec/codec/codec_int.h" | 9 #include "core/src/fxcodec/codec/codec_int.h" |
10 #include "core/src/fxcodec/lbmp/fx_bmp.h" | 10 #include "core/src/fxcodec/lbmp/fx_bmp.h" |
11 struct FXBMP_Context { | 11 struct FXBMP_Context { |
12 bmp_decompress_struct_p bmp_ptr; | 12 bmp_decompress_struct_p bmp_ptr; |
13 void* parent_ptr; | 13 void* parent_ptr; |
14 void* child_ptr; | 14 void* child_ptr; |
15 | 15 |
16 void* (*m_AllocFunc)(unsigned int); | 16 void* (*m_AllocFunc)(unsigned int); |
17 void (*m_FreeFunc)(void*); | 17 void (*m_FreeFunc)(void*); |
18 }; | 18 }; |
19 extern "C" { | 19 extern "C" { |
20 static void* _bmp_alloc_func(unsigned int size) { | 20 static void* bmp_alloc_func(unsigned int size) { |
21 return FX_Alloc(char, size); | 21 return FX_Alloc(char, size); |
22 } | 22 } |
23 static void _bmp_free_func(void* p) { | 23 static void bmp_free_func(void* p) { |
24 FX_Free(p); | 24 FX_Free(p); |
25 } | 25 } |
26 }; | 26 }; |
27 static void _bmp_error_data(bmp_decompress_struct_p bmp_ptr, | 27 static void bmp_error_data(bmp_decompress_struct_p bmp_ptr, |
28 const FX_CHAR* err_msg) { | 28 const FX_CHAR* err_msg) { |
29 FXSYS_strncpy((char*)bmp_ptr->err_ptr, err_msg, BMP_MAX_ERROR_SIZE - 1); | 29 FXSYS_strncpy((char*)bmp_ptr->err_ptr, err_msg, BMP_MAX_ERROR_SIZE - 1); |
30 longjmp(bmp_ptr->jmpbuf, 1); | 30 longjmp(bmp_ptr->jmpbuf, 1); |
31 } | 31 } |
32 static void _bmp_read_scanline(bmp_decompress_struct_p bmp_ptr, | 32 static void bmp_read_scanline(bmp_decompress_struct_p bmp_ptr, |
33 int32_t row_num, | 33 int32_t row_num, |
34 uint8_t* row_buf) { | 34 uint8_t* row_buf) { |
35 FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr; | 35 FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr; |
36 CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr; | 36 CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr; |
37 pModule->ReadScanlineCallback(p->child_ptr, row_num, row_buf); | 37 pModule->ReadScanlineCallback(p->child_ptr, row_num, row_buf); |
38 } | 38 } |
39 static FX_BOOL _bmp_get_data_position(bmp_decompress_struct_p bmp_ptr, | 39 static FX_BOOL bmp_get_data_position(bmp_decompress_struct_p bmp_ptr, |
40 FX_DWORD rcd_pos) { | 40 FX_DWORD rcd_pos) { |
41 FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr; | 41 FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr; |
42 CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr; | 42 CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr; |
43 return pModule->InputImagePositionBufCallback(p->child_ptr, rcd_pos); | 43 return pModule->InputImagePositionBufCallback(p->child_ptr, rcd_pos); |
44 } | 44 } |
45 void* CCodec_BmpModule::Start(void* pModule) { | 45 void* CCodec_BmpModule::Start(void* pModule) { |
46 FXBMP_Context* p = (FXBMP_Context*)FX_Alloc(uint8_t, sizeof(FXBMP_Context)); | 46 FXBMP_Context* p = (FXBMP_Context*)FX_Alloc(uint8_t, sizeof(FXBMP_Context)); |
47 if (p == NULL) { | 47 if (p == NULL) { |
48 return NULL; | 48 return NULL; |
49 } | 49 } |
50 FXSYS_memset(p, 0, sizeof(FXBMP_Context)); | 50 FXSYS_memset(p, 0, sizeof(FXBMP_Context)); |
51 if (p == NULL) { | 51 if (p == NULL) { |
52 return NULL; | 52 return NULL; |
53 } | 53 } |
54 p->m_AllocFunc = _bmp_alloc_func; | 54 p->m_AllocFunc = bmp_alloc_func; |
55 p->m_FreeFunc = _bmp_free_func; | 55 p->m_FreeFunc = bmp_free_func; |
56 p->bmp_ptr = NULL; | 56 p->bmp_ptr = NULL; |
57 p->parent_ptr = (void*)this; | 57 p->parent_ptr = (void*)this; |
58 p->child_ptr = pModule; | 58 p->child_ptr = pModule; |
59 p->bmp_ptr = _bmp_create_decompress(); | 59 p->bmp_ptr = bmp_create_decompress(); |
60 if (p->bmp_ptr == NULL) { | 60 if (p->bmp_ptr == NULL) { |
61 FX_Free(p); | 61 FX_Free(p); |
62 return NULL; | 62 return NULL; |
63 } | 63 } |
64 p->bmp_ptr->context_ptr = (void*)p; | 64 p->bmp_ptr->context_ptr = (void*)p; |
65 p->bmp_ptr->err_ptr = m_szLastError; | 65 p->bmp_ptr->err_ptr = m_szLastError; |
66 p->bmp_ptr->_bmp_error_fn = _bmp_error_data; | 66 p->bmp_ptr->bmp_error_fn = bmp_error_data; |
67 p->bmp_ptr->_bmp_get_row_fn = _bmp_read_scanline; | 67 p->bmp_ptr->bmp_get_row_fn = bmp_read_scanline; |
68 p->bmp_ptr->_bmp_get_data_position_fn = _bmp_get_data_position; | 68 p->bmp_ptr->bmp_get_data_position_fn = bmp_get_data_position; |
69 return p; | 69 return p; |
70 } | 70 } |
71 void CCodec_BmpModule::Finish(void* pContext) { | 71 void CCodec_BmpModule::Finish(void* pContext) { |
72 FXBMP_Context* p = (FXBMP_Context*)pContext; | 72 FXBMP_Context* p = (FXBMP_Context*)pContext; |
73 if (p) { | 73 if (p) { |
74 _bmp_destroy_decompress(&p->bmp_ptr); | 74 bmp_destroy_decompress(&p->bmp_ptr); |
75 p->m_FreeFunc(p); | 75 p->m_FreeFunc(p); |
76 } | 76 } |
77 } | 77 } |
78 int32_t CCodec_BmpModule::ReadHeader(void* pContext, | 78 int32_t CCodec_BmpModule::ReadHeader(void* pContext, |
79 int32_t* width, | 79 int32_t* width, |
80 int32_t* height, | 80 int32_t* height, |
81 FX_BOOL* tb_flag, | 81 FX_BOOL* tb_flag, |
82 int32_t* components, | 82 int32_t* components, |
83 int32_t* pal_num, | 83 int32_t* pal_num, |
84 FX_DWORD** pal_pp, | 84 FX_DWORD** pal_pp, |
85 CFX_DIBAttribute* pAttribute) { | 85 CFX_DIBAttribute* pAttribute) { |
86 FXBMP_Context* p = (FXBMP_Context*)pContext; | 86 FXBMP_Context* p = (FXBMP_Context*)pContext; |
87 if (setjmp(p->bmp_ptr->jmpbuf)) { | 87 if (setjmp(p->bmp_ptr->jmpbuf)) { |
88 return 0; | 88 return 0; |
89 } | 89 } |
90 int32_t ret = _bmp_read_header(p->bmp_ptr); | 90 int32_t ret = bmp_read_header(p->bmp_ptr); |
91 if (ret != 1) { | 91 if (ret != 1) { |
92 return ret; | 92 return ret; |
93 } | 93 } |
94 *width = p->bmp_ptr->width; | 94 *width = p->bmp_ptr->width; |
95 *height = p->bmp_ptr->height; | 95 *height = p->bmp_ptr->height; |
96 *tb_flag = p->bmp_ptr->imgTB_flag; | 96 *tb_flag = p->bmp_ptr->imgTB_flag; |
97 *components = p->bmp_ptr->components; | 97 *components = p->bmp_ptr->components; |
98 *pal_num = p->bmp_ptr->pal_num; | 98 *pal_num = p->bmp_ptr->pal_num; |
99 *pal_pp = p->bmp_ptr->pal_ptr; | 99 *pal_pp = p->bmp_ptr->pal_ptr; |
100 if (pAttribute) { | 100 if (pAttribute) { |
101 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_METER; | 101 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_METER; |
102 pAttribute->m_nXDPI = p->bmp_ptr->dpi_x; | 102 pAttribute->m_nXDPI = p->bmp_ptr->dpi_x; |
103 pAttribute->m_nYDPI = p->bmp_ptr->dpi_y; | 103 pAttribute->m_nYDPI = p->bmp_ptr->dpi_y; |
104 pAttribute->m_nBmpCompressType = p->bmp_ptr->compress_flag; | 104 pAttribute->m_nBmpCompressType = p->bmp_ptr->compress_flag; |
105 } | 105 } |
106 return 1; | 106 return 1; |
107 } | 107 } |
108 int32_t CCodec_BmpModule::LoadImage(void* pContext) { | 108 int32_t CCodec_BmpModule::LoadImage(void* pContext) { |
109 FXBMP_Context* p = (FXBMP_Context*)pContext; | 109 FXBMP_Context* p = (FXBMP_Context*)pContext; |
110 if (setjmp(p->bmp_ptr->jmpbuf)) { | 110 if (setjmp(p->bmp_ptr->jmpbuf)) { |
111 return 0; | 111 return 0; |
112 } | 112 } |
113 return _bmp_decode_image(p->bmp_ptr); | 113 return bmp_decode_image(p->bmp_ptr); |
114 } | 114 } |
115 FX_DWORD CCodec_BmpModule::GetAvailInput(void* pContext, | 115 FX_DWORD CCodec_BmpModule::GetAvailInput(void* pContext, |
116 uint8_t** avial_buf_ptr) { | 116 uint8_t** avial_buf_ptr) { |
117 FXBMP_Context* p = (FXBMP_Context*)pContext; | 117 FXBMP_Context* p = (FXBMP_Context*)pContext; |
118 return _bmp_get_avail_input(p->bmp_ptr, avial_buf_ptr); | 118 return bmp_get_avail_input(p->bmp_ptr, avial_buf_ptr); |
119 } | 119 } |
120 void CCodec_BmpModule::Input(void* pContext, | 120 void CCodec_BmpModule::Input(void* pContext, |
121 const uint8_t* src_buf, | 121 const uint8_t* src_buf, |
122 FX_DWORD src_size) { | 122 FX_DWORD src_size) { |
123 FXBMP_Context* p = (FXBMP_Context*)pContext; | 123 FXBMP_Context* p = (FXBMP_Context*)pContext; |
124 _bmp_input_buffer(p->bmp_ptr, (uint8_t*)src_buf, src_size); | 124 bmp_input_buffer(p->bmp_ptr, (uint8_t*)src_buf, src_size); |
125 } | 125 } |
OLD | NEW |