| 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 #ifndef CORE_FXCODEC_LGIF_FX_GIF_H_ | 7 #ifndef CORE_FXCODEC_LGIF_FX_GIF_H_ |
| 8 #define CORE_FXCODEC_LGIF_FX_GIF_H_ | 8 #define CORE_FXCODEC_LGIF_FX_GIF_H_ |
| 9 | 9 |
| 10 #include <setjmp.h> | 10 #include <setjmp.h> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 uint8_t reserved : 2; | 45 uint8_t reserved : 2; |
| 46 uint8_t sort_flag : 1; | 46 uint8_t sort_flag : 1; |
| 47 uint8_t interlace : 1; | 47 uint8_t interlace : 1; |
| 48 uint8_t local_pal : 1; | 48 uint8_t local_pal : 1; |
| 49 } GifLF; | 49 } GifLF; |
| 50 typedef struct tagGifHeader { | 50 typedef struct tagGifHeader { |
| 51 char signature[3]; | 51 char signature[3]; |
| 52 char version[3]; | 52 char version[3]; |
| 53 } GifHeader; | 53 } GifHeader; |
| 54 typedef struct tagGifLSD { | 54 typedef struct tagGifLSD { |
| 55 FX_WORD width; | 55 uint16_t width; |
| 56 FX_WORD height; | 56 uint16_t height; |
| 57 uint8_t global_flag; | 57 uint8_t global_flag; |
| 58 uint8_t bc_index; | 58 uint8_t bc_index; |
| 59 uint8_t pixel_aspect; | 59 uint8_t pixel_aspect; |
| 60 } GifLSD; | 60 } GifLSD; |
| 61 typedef struct tagGifImageInfo { | 61 typedef struct tagGifImageInfo { |
| 62 FX_WORD left; | 62 uint16_t left; |
| 63 FX_WORD top; | 63 uint16_t top; |
| 64 FX_WORD width; | 64 uint16_t width; |
| 65 FX_WORD height; | 65 uint16_t height; |
| 66 | 66 |
| 67 uint8_t local_flag; | 67 uint8_t local_flag; |
| 68 } GifImageInfo; | 68 } GifImageInfo; |
| 69 typedef struct tagGifCEF { | 69 typedef struct tagGifCEF { |
| 70 uint8_t transparency : 1; | 70 uint8_t transparency : 1; |
| 71 uint8_t user_input : 1; | 71 uint8_t user_input : 1; |
| 72 uint8_t disposal_method : 3; | 72 uint8_t disposal_method : 3; |
| 73 uint8_t reserved : 3; | 73 uint8_t reserved : 3; |
| 74 } GifCEF; | 74 } GifCEF; |
| 75 typedef struct tagGifGCE { | 75 typedef struct tagGifGCE { |
| 76 uint8_t block_size; | 76 uint8_t block_size; |
| 77 uint8_t gce_flag; | 77 uint8_t gce_flag; |
| 78 FX_WORD delay_time; | 78 uint16_t delay_time; |
| 79 uint8_t trans_index; | 79 uint8_t trans_index; |
| 80 } GifGCE; | 80 } GifGCE; |
| 81 typedef struct tagGifPTE { | 81 typedef struct tagGifPTE { |
| 82 uint8_t block_size; | 82 uint8_t block_size; |
| 83 FX_WORD grid_left; | 83 uint16_t grid_left; |
| 84 FX_WORD grid_top; | 84 uint16_t grid_top; |
| 85 FX_WORD grid_width; | 85 uint16_t grid_width; |
| 86 FX_WORD grid_height; | 86 uint16_t grid_height; |
| 87 | 87 |
| 88 uint8_t char_width; | 88 uint8_t char_width; |
| 89 uint8_t char_height; | 89 uint8_t char_height; |
| 90 | 90 |
| 91 uint8_t fc_index; | 91 uint8_t fc_index; |
| 92 uint8_t bc_index; | 92 uint8_t bc_index; |
| 93 } GifPTE; | 93 } GifPTE; |
| 94 typedef struct tagGifAE { | 94 typedef struct tagGifAE { |
| 95 uint8_t block_size; | 95 uint8_t block_size; |
| 96 uint8_t app_identify[8]; | 96 uint8_t app_identify[8]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 108 int32_t image_row_num; | 108 int32_t image_row_num; |
| 109 } GifImage; | 109 } GifImage; |
| 110 typedef struct tagGifPlainText { | 110 typedef struct tagGifPlainText { |
| 111 GifGCE* gce_ptr; | 111 GifGCE* gce_ptr; |
| 112 GifPTE* pte_ptr; | 112 GifPTE* pte_ptr; |
| 113 CFX_ByteString* string_ptr; | 113 CFX_ByteString* string_ptr; |
| 114 } GifPlainText; | 114 } GifPlainText; |
| 115 class CGifLZWDecoder { | 115 class CGifLZWDecoder { |
| 116 public: | 116 public: |
| 117 struct tag_Table { | 117 struct tag_Table { |
| 118 FX_WORD prefix; | 118 uint16_t prefix; |
| 119 uint8_t suffix; | 119 uint8_t suffix; |
| 120 }; | 120 }; |
| 121 CGifLZWDecoder(FX_CHAR* error_ptr = NULL) { err_msg_ptr = error_ptr; } | 121 CGifLZWDecoder(FX_CHAR* error_ptr = NULL) { err_msg_ptr = error_ptr; } |
| 122 void InitTable(uint8_t code_len); | 122 void InitTable(uint8_t code_len); |
| 123 | 123 |
| 124 int32_t Decode(uint8_t* des_buf, FX_DWORD& des_size); | 124 int32_t Decode(uint8_t* des_buf, FX_DWORD& des_size); |
| 125 | 125 |
| 126 void Input(uint8_t* src_buf, FX_DWORD src_size); | 126 void Input(uint8_t* src_buf, FX_DWORD src_size); |
| 127 FX_DWORD GetAvailInput(); | 127 FX_DWORD GetAvailInput(); |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 void ClearTable(); | 130 void ClearTable(); |
| 131 void AddCode(FX_WORD prefix_code, uint8_t append_char); | 131 void AddCode(uint16_t prefix_code, uint8_t append_char); |
| 132 void DecodeString(FX_WORD code); | 132 void DecodeString(uint16_t code); |
| 133 uint8_t code_size; | 133 uint8_t code_size; |
| 134 uint8_t code_size_cur; | 134 uint8_t code_size_cur; |
| 135 FX_WORD code_clear; | 135 uint16_t code_clear; |
| 136 FX_WORD code_end; | 136 uint16_t code_end; |
| 137 FX_WORD code_next; | 137 uint16_t code_next; |
| 138 uint8_t code_first; | 138 uint8_t code_first; |
| 139 uint8_t stack[GIF_MAX_LZW_CODE]; | 139 uint8_t stack[GIF_MAX_LZW_CODE]; |
| 140 FX_WORD stack_size; | 140 uint16_t stack_size; |
| 141 tag_Table code_table[GIF_MAX_LZW_CODE]; | 141 tag_Table code_table[GIF_MAX_LZW_CODE]; |
| 142 FX_WORD code_old; | 142 uint16_t code_old; |
| 143 | 143 |
| 144 uint8_t* next_in; | 144 uint8_t* next_in; |
| 145 FX_DWORD avail_in; | 145 FX_DWORD avail_in; |
| 146 | 146 |
| 147 uint8_t bits_left; | 147 uint8_t bits_left; |
| 148 FX_DWORD code_store; | 148 FX_DWORD code_store; |
| 149 | 149 |
| 150 FX_CHAR* err_msg_ptr; | 150 FX_CHAR* err_msg_ptr; |
| 151 }; | 151 }; |
| 152 class CGifLZWEncoder { | 152 class CGifLZWEncoder { |
| 153 public: | 153 public: |
| 154 struct tag_Table { | 154 struct tag_Table { |
| 155 FX_WORD prefix; | 155 uint16_t prefix; |
| 156 uint8_t suffix; | 156 uint8_t suffix; |
| 157 }; | 157 }; |
| 158 CGifLZWEncoder(); | 158 CGifLZWEncoder(); |
| 159 ~CGifLZWEncoder(); | 159 ~CGifLZWEncoder(); |
| 160 void Start(uint8_t code_len, | 160 void Start(uint8_t code_len, |
| 161 const uint8_t* src_buf, | 161 const uint8_t* src_buf, |
| 162 uint8_t*& dst_buf, | 162 uint8_t*& dst_buf, |
| 163 FX_DWORD& offset); | 163 FX_DWORD& offset); |
| 164 FX_BOOL Encode(const uint8_t* src_buf, | 164 FX_BOOL Encode(const uint8_t* src_buf, |
| 165 FX_DWORD src_len, | 165 FX_DWORD src_len, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 177 uint8_t*& dst_buf, | 177 uint8_t*& dst_buf, |
| 178 FX_DWORD& dst_len, | 178 FX_DWORD& dst_len, |
| 179 FX_DWORD& offset); | 179 FX_DWORD& offset); |
| 180 void WriteBlock(uint8_t*& dst_buf, FX_DWORD& dst_len, FX_DWORD& offset); | 180 void WriteBlock(uint8_t*& dst_buf, FX_DWORD& dst_len, FX_DWORD& offset); |
| 181 jmp_buf jmp; | 181 jmp_buf jmp; |
| 182 FX_DWORD src_offset; | 182 FX_DWORD src_offset; |
| 183 uint8_t src_bit_offset; | 183 uint8_t src_bit_offset; |
| 184 uint8_t src_bit_cut; | 184 uint8_t src_bit_cut; |
| 185 FX_DWORD src_bit_num; | 185 FX_DWORD src_bit_num; |
| 186 uint8_t code_size; | 186 uint8_t code_size; |
| 187 FX_WORD code_clear; | 187 uint16_t code_clear; |
| 188 FX_WORD code_end; | 188 uint16_t code_end; |
| 189 FX_WORD index_num; | 189 uint16_t index_num; |
| 190 uint8_t bit_offset; | 190 uint8_t bit_offset; |
| 191 uint8_t index_bit_cur; | 191 uint8_t index_bit_cur; |
| 192 uint8_t index_buf[GIF_DATA_BLOCK]; | 192 uint8_t index_buf[GIF_DATA_BLOCK]; |
| 193 uint8_t index_buf_len; | 193 uint8_t index_buf_len; |
| 194 tag_Table code_table[GIF_MAX_LZW_CODE]; | 194 tag_Table code_table[GIF_MAX_LZW_CODE]; |
| 195 FX_WORD table_cur; | 195 uint16_t table_cur; |
| 196 }; | 196 }; |
| 197 typedef struct tag_gif_decompress_struct gif_decompress_struct; | 197 typedef struct tag_gif_decompress_struct gif_decompress_struct; |
| 198 typedef gif_decompress_struct* gif_decompress_struct_p; | 198 typedef gif_decompress_struct* gif_decompress_struct_p; |
| 199 typedef gif_decompress_struct_p* gif_decompress_struct_pp; | 199 typedef gif_decompress_struct_p* gif_decompress_struct_pp; |
| 200 static const int32_t s_gif_interlace_step[4] = {8, 8, 4, 2}; | 200 static const int32_t s_gif_interlace_step[4] = {8, 8, 4, 2}; |
| 201 struct tag_gif_decompress_struct { | 201 struct tag_gif_decompress_struct { |
| 202 jmp_buf jmpbuf; | 202 jmp_buf jmpbuf; |
| 203 FX_CHAR* err_ptr; | 203 FX_CHAR* err_ptr; |
| 204 void (*gif_error_fn)(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg); | 204 void (*gif_error_fn)(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg); |
| 205 void* context_ptr; | 205 void* context_ptr; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 struct tag_gif_compress_struct { | 244 struct tag_gif_compress_struct { |
| 245 const uint8_t* src_buf; | 245 const uint8_t* src_buf; |
| 246 FX_DWORD src_pitch; | 246 FX_DWORD src_pitch; |
| 247 FX_DWORD src_width; | 247 FX_DWORD src_width; |
| 248 FX_DWORD src_row; | 248 FX_DWORD src_row; |
| 249 FX_DWORD cur_offset; | 249 FX_DWORD cur_offset; |
| 250 FX_DWORD frames; | 250 FX_DWORD frames; |
| 251 GifHeader* header_ptr; | 251 GifHeader* header_ptr; |
| 252 GifLSD* lsd_ptr; | 252 GifLSD* lsd_ptr; |
| 253 GifPalette* global_pal; | 253 GifPalette* global_pal; |
| 254 FX_WORD gpal_num; | 254 uint16_t gpal_num; |
| 255 GifPalette* local_pal; | 255 GifPalette* local_pal; |
| 256 FX_WORD lpal_num; | 256 uint16_t lpal_num; |
| 257 GifImageInfo* image_info_ptr; | 257 GifImageInfo* image_info_ptr; |
| 258 CGifLZWEncoder* img_encoder_ptr; | 258 CGifLZWEncoder* img_encoder_ptr; |
| 259 | 259 |
| 260 uint8_t* cmt_data_ptr; | 260 uint8_t* cmt_data_ptr; |
| 261 FX_DWORD cmt_data_len; | 261 FX_DWORD cmt_data_len; |
| 262 GifGCE* gce_ptr; | 262 GifGCE* gce_ptr; |
| 263 GifPTE* pte_ptr; | 263 GifPTE* pte_ptr; |
| 264 const uint8_t* pte_data_ptr; | 264 const uint8_t* pte_data_ptr; |
| 265 FX_DWORD pte_data_len; | 265 FX_DWORD pte_data_len; |
| 266 }; | 266 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 287 uint8_t* src_buf, | 287 uint8_t* src_buf, |
| 288 FX_DWORD src_size); | 288 FX_DWORD src_size); |
| 289 FX_DWORD gif_get_avail_input(gif_decompress_struct_p gif_ptr, | 289 FX_DWORD gif_get_avail_input(gif_decompress_struct_p gif_ptr, |
| 290 uint8_t** avial_buf_ptr); | 290 uint8_t** avial_buf_ptr); |
| 291 void interlace_buf(const uint8_t* buf, FX_DWORD width, FX_DWORD height); | 291 void interlace_buf(const uint8_t* buf, FX_DWORD width, FX_DWORD height); |
| 292 FX_BOOL gif_encode(gif_compress_struct_p gif_ptr, | 292 FX_BOOL gif_encode(gif_compress_struct_p gif_ptr, |
| 293 uint8_t*& dst_buf, | 293 uint8_t*& dst_buf, |
| 294 FX_DWORD& dst_len); | 294 FX_DWORD& dst_len); |
| 295 | 295 |
| 296 #endif // CORE_FXCODEC_LGIF_FX_GIF_H_ | 296 #endif // CORE_FXCODEC_LGIF_FX_GIF_H_ |
| OLD | NEW |