| 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 "../../../include/fxge/fx_dib.h" | 8 #include "../../../include/fxge/fx_dib.h" |
| 9 #include "codec_int.h" | 9 #include "codec_int.h" |
| 10 #include "../lgif/fx_gif.h" | 10 #include "../lgif/fx_gif.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 if(p != NULL) { | 26 if(p != NULL) { |
| 27 FX_Free(p); | 27 FX_Free(p); |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 }; | 30 }; |
| 31 static void _gif_error_data(gif_decompress_struct_p gif_ptr, FX_LPCSTR err_msg) | 31 static void _gif_error_data(gif_decompress_struct_p gif_ptr, FX_LPCSTR err_msg) |
| 32 { | 32 { |
| 33 FXSYS_strncpy((char*)gif_ptr->err_ptr, err_msg, GIF_MAX_ERROR_SIZE - 1); | 33 FXSYS_strncpy((char*)gif_ptr->err_ptr, err_msg, GIF_MAX_ERROR_SIZE - 1); |
| 34 longjmp(gif_ptr->jmpbuf, 1); | 34 longjmp(gif_ptr->jmpbuf, 1); |
| 35 } | 35 } |
| 36 static FX_LPBYTE _gif_ask_buf_for_pal(gif_decompress_struct_p gif_ptr, FX_INT32
pal_size) | 36 static FX_LPBYTE _gif_ask_buf_for_pal(gif_decompress_struct_p gif_ptr, int32_t p
al_size) |
| 37 { | 37 { |
| 38 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; | 38 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; |
| 39 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; | 39 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; |
| 40 return pModule->AskLocalPaletteBufCallback(p->child_ptr, | 40 return pModule->AskLocalPaletteBufCallback(p->child_ptr, |
| 41 _gif_get_frame_num(gif_ptr), | 41 _gif_get_frame_num(gif_ptr), |
| 42 pal_size); | 42 pal_size); |
| 43 } | 43 } |
| 44 static void _gif_record_current_position(gif_decompress_struct_p gif_ptr, FX_DWO
RD* cur_pos_ptr) | 44 static void _gif_record_current_position(gif_decompress_struct_p gif_ptr, FX_DWO
RD* cur_pos_ptr) |
| 45 { | 45 { |
| 46 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; | 46 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; |
| 47 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; | 47 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; |
| 48 pModule->RecordCurrentPositionCallback(p->child_ptr, *cur_pos_ptr); | 48 pModule->RecordCurrentPositionCallback(p->child_ptr, *cur_pos_ptr); |
| 49 } | 49 } |
| 50 static void _gif_read_scanline(gif_decompress_struct_p gif_ptr, FX_INT32 row_num
, FX_LPBYTE row_buf) | 50 static void _gif_read_scanline(gif_decompress_struct_p gif_ptr, int32_t row_num,
FX_LPBYTE row_buf) |
| 51 { | 51 { |
| 52 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; | 52 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; |
| 53 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; | 53 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; |
| 54 pModule->ReadScanlineCallback(p->child_ptr, row_num, row_buf); | 54 pModule->ReadScanlineCallback(p->child_ptr, row_num, row_buf); |
| 55 } | 55 } |
| 56 static FX_BOOL _gif_get_record_position(gif_decompress_struct_p gif_ptr, FX_DWOR
D cur_pos, | 56 static FX_BOOL _gif_get_record_position(gif_decompress_struct_p gif_ptr, FX_DWOR
D cur_pos, |
| 57 FX_INT32 left, FX_INT32 top, FX_INT32 wi
dth, FX_INT32 height, | 57 int32_t left, int32_t top, int32_t width
, int32_t height, |
| 58 FX_INT32 pal_num, void* pal_ptr, | 58 int32_t pal_num, void* pal_ptr, |
| 59 FX_INT32 delay_time, FX_BOOL user_input, | 59 int32_t delay_time, FX_BOOL user_input, |
| 60 FX_INT32 trans_index, FX_INT32 disposal_
method, FX_BOOL interlace) | 60 int32_t trans_index, int32_t disposal_me
thod, FX_BOOL interlace) |
| 61 { | 61 { |
| 62 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; | 62 FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; |
| 63 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; | 63 CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; |
| 64 return pModule->InputRecordPositionBufCallback(p->child_ptr, cur_pos, FX_REC
T(left, top, left + width, top + height), | 64 return pModule->InputRecordPositionBufCallback(p->child_ptr, cur_pos, FX_REC
T(left, top, left + width, top + height), |
| 65 pal_num, pal_ptr, delay_time, user_input, trans_index, disposal_meth
od, interlace); | 65 pal_num, pal_ptr, delay_time, user_input, trans_index, disposal_meth
od, interlace); |
| 66 } | 66 } |
| 67 void* CCodec_GifModule::Start(void* pModule) | 67 void* CCodec_GifModule::Start(void* pModule) |
| 68 { | 68 { |
| 69 FXGIF_Context* p = (FXGIF_Context*)FX_Alloc(FX_BYTE, sizeof(FXGIF_Context)); | 69 FXGIF_Context* p = (FXGIF_Context*)FX_Alloc(uint8_t, sizeof(FXGIF_Context)); |
| 70 if (p == NULL) { | 70 if (p == NULL) { |
| 71 return NULL; | 71 return NULL; |
| 72 } | 72 } |
| 73 FXSYS_memset32(p, 0, sizeof(FXGIF_Context)); | 73 FXSYS_memset32(p, 0, sizeof(FXGIF_Context)); |
| 74 p->m_AllocFunc = _gif_alloc_func; | 74 p->m_AllocFunc = _gif_alloc_func; |
| 75 p->m_FreeFunc = _gif_free_func; | 75 p->m_FreeFunc = _gif_free_func; |
| 76 p->gif_ptr = NULL; | 76 p->gif_ptr = NULL; |
| 77 p->parent_ptr = (void*)this; | 77 p->parent_ptr = (void*)this; |
| 78 p->child_ptr = pModule; | 78 p->child_ptr = pModule; |
| 79 p->gif_ptr = _gif_create_decompress(); | 79 p->gif_ptr = _gif_create_decompress(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 return p; | 91 return p; |
| 92 } | 92 } |
| 93 void CCodec_GifModule::Finish(void* pContext) | 93 void CCodec_GifModule::Finish(void* pContext) |
| 94 { | 94 { |
| 95 FXGIF_Context* p = (FXGIF_Context*)pContext; | 95 FXGIF_Context* p = (FXGIF_Context*)pContext; |
| 96 if(p != NULL) { | 96 if(p != NULL) { |
| 97 _gif_destroy_decompress(&p->gif_ptr); | 97 _gif_destroy_decompress(&p->gif_ptr); |
| 98 p->m_FreeFunc(p); | 98 p->m_FreeFunc(p); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 FX_INT32 CCodec_GifModule::ReadHeader(void* pContext, int* width, int* height, | 101 int32_t CCodec_GifModule::ReadHeader(void* pContext, int* width, int* height, |
| 102 int* pal_num, void** pal_pp, int* bg_index
, CFX_DIBAttribute* pAttribute) | 102 int* pal_num, void** pal_pp, int* bg_index
, CFX_DIBAttribute* pAttribute) |
| 103 { | 103 { |
| 104 FXGIF_Context* p = (FXGIF_Context*)pContext; | 104 FXGIF_Context* p = (FXGIF_Context*)pContext; |
| 105 if(setjmp(p->gif_ptr->jmpbuf)) { | 105 if(setjmp(p->gif_ptr->jmpbuf)) { |
| 106 return 0; | 106 return 0; |
| 107 } | 107 } |
| 108 FX_INT32 ret = _gif_read_header(p->gif_ptr); | 108 int32_t ret = _gif_read_header(p->gif_ptr); |
| 109 if (ret != 1) { | 109 if (ret != 1) { |
| 110 return ret; | 110 return ret; |
| 111 } | 111 } |
| 112 if (pAttribute) { | 112 if (pAttribute) { |
| 113 } | 113 } |
| 114 *width = p->gif_ptr->width; | 114 *width = p->gif_ptr->width; |
| 115 *height = p->gif_ptr->height; | 115 *height = p->gif_ptr->height; |
| 116 *pal_num = p->gif_ptr->global_pal_num; | 116 *pal_num = p->gif_ptr->global_pal_num; |
| 117 *pal_pp = p->gif_ptr->global_pal_ptr; | 117 *pal_pp = p->gif_ptr->global_pal_ptr; |
| 118 *bg_index = p->gif_ptr->bc_index; | 118 *bg_index = p->gif_ptr->bc_index; |
| 119 return 1; | 119 return 1; |
| 120 } | 120 } |
| 121 FX_INT32 CCodec_GifModule::LoadFrameInfo(void* pContext, int* frame_num) | 121 int32_t CCodec_GifModule::LoadFrameInfo(void* pContext, int* frame_num) |
| 122 { | 122 { |
| 123 FXGIF_Context* p = (FXGIF_Context*)pContext; | 123 FXGIF_Context* p = (FXGIF_Context*)pContext; |
| 124 if(setjmp(p->gif_ptr->jmpbuf)) { | 124 if(setjmp(p->gif_ptr->jmpbuf)) { |
| 125 return 0; | 125 return 0; |
| 126 } | 126 } |
| 127 FX_INT32 ret = _gif_get_frame(p->gif_ptr); | 127 int32_t ret = _gif_get_frame(p->gif_ptr); |
| 128 if (ret != 1) { | 128 if (ret != 1) { |
| 129 return ret; | 129 return ret; |
| 130 } | 130 } |
| 131 *frame_num = _gif_get_frame_num(p->gif_ptr); | 131 *frame_num = _gif_get_frame_num(p->gif_ptr); |
| 132 return 1; | 132 return 1; |
| 133 } | 133 } |
| 134 FX_INT32 CCodec_GifModule::LoadFrame(void* pContext, int frame_num, CFX_DIBAttri
bute* pAttribute) | 134 int32_t CCodec_GifModule::LoadFrame(void* pContext, int frame_num, CFX_DIBAttrib
ute* pAttribute) |
| 135 { | 135 { |
| 136 FXGIF_Context* p = (FXGIF_Context*)pContext; | 136 FXGIF_Context* p = (FXGIF_Context*)pContext; |
| 137 if(setjmp(p->gif_ptr->jmpbuf)) { | 137 if(setjmp(p->gif_ptr->jmpbuf)) { |
| 138 return 0; | 138 return 0; |
| 139 } | 139 } |
| 140 FX_INT32 ret = _gif_load_frame(p->gif_ptr, frame_num); | 140 int32_t ret = _gif_load_frame(p->gif_ptr, frame_num); |
| 141 if (ret == 1) { | 141 if (ret == 1) { |
| 142 if (pAttribute) { | 142 if (pAttribute) { |
| 143 pAttribute->m_nGifLeft = p->gif_ptr->img_ptr_arr_ptr->GetAt(frame_nu
m)->image_info_ptr->left; | 143 pAttribute->m_nGifLeft = p->gif_ptr->img_ptr_arr_ptr->GetAt(frame_nu
m)->image_info_ptr->left; |
| 144 pAttribute->m_nGifTop = p->gif_ptr->img_ptr_arr_ptr->GetAt(frame_num
)->image_info_ptr->top; | 144 pAttribute->m_nGifTop = p->gif_ptr->img_ptr_arr_ptr->GetAt(frame_num
)->image_info_ptr->top; |
| 145 pAttribute->m_fAspectRatio = p->gif_ptr->pixel_aspect; | 145 pAttribute->m_fAspectRatio = p->gif_ptr->pixel_aspect; |
| 146 if (p->gif_ptr->cmt_data_ptr) { | 146 if (p->gif_ptr->cmt_data_ptr) { |
| 147 FX_LPCBYTE buf = (FX_LPCBYTE)p->gif_ptr->cmt_data_ptr->GetBuffer
(0); | 147 FX_LPCBYTE buf = (FX_LPCBYTE)p->gif_ptr->cmt_data_ptr->GetBuffer
(0); |
| 148 FX_DWORD len = p->gif_ptr->cmt_data_ptr->GetLength(); | 148 FX_DWORD len = p->gif_ptr->cmt_data_ptr->GetLength(); |
| 149 if (len > 21) { | 149 if (len > 21) { |
| 150 FX_BYTE size = *buf++; | 150 uint8_t size = *buf++; |
| 151 if (size) { | 151 if (size) { |
| 152 pAttribute->m_strAuthor = CFX_ByteString(buf, size); | 152 pAttribute->m_strAuthor = CFX_ByteString(buf, size); |
| 153 } else { | 153 } else { |
| 154 pAttribute->m_strAuthor.Empty(); | 154 pAttribute->m_strAuthor.Empty(); |
| 155 } | 155 } |
| 156 buf += size; | 156 buf += size; |
| 157 size = *buf++; | 157 size = *buf++; |
| 158 if (size == 20) { | 158 if (size == 20) { |
| 159 FXSYS_memcpy32(pAttribute->m_strTime, buf, size); | 159 FXSYS_memcpy32(pAttribute->m_strTime, buf, size); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 return ret; | 165 return ret; |
| 166 } | 166 } |
| 167 FX_DWORD CCodec_GifModule::GetAvailInput(void* pContext, FX_LPBYTE* avial_buf_pt
r) | 167 FX_DWORD CCodec_GifModule::GetAvailInput(void* pContext, FX_LPBYTE* avial_buf_pt
r) |
| 168 { | 168 { |
| 169 FXGIF_Context* p = (FXGIF_Context*)pContext; | 169 FXGIF_Context* p = (FXGIF_Context*)pContext; |
| 170 return _gif_get_avail_input(p->gif_ptr, avial_buf_ptr); | 170 return _gif_get_avail_input(p->gif_ptr, avial_buf_ptr); |
| 171 } | 171 } |
| 172 void CCodec_GifModule::Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_si
ze) | 172 void CCodec_GifModule::Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_si
ze) |
| 173 { | 173 { |
| 174 FXGIF_Context* p = (FXGIF_Context*)pContext; | 174 FXGIF_Context* p = (FXGIF_Context*)pContext; |
| 175 _gif_input_buffer(p->gif_ptr, (FX_LPBYTE)src_buf, src_size); | 175 _gif_input_buffer(p->gif_ptr, (FX_LPBYTE)src_buf, src_size); |
| 176 } | 176 } |
| OLD | NEW |