| 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/src/fxcodec/lgif/fx_gif.h" | 7 #include "core/src/fxcodec/lgif/fx_gif.h" |
| 8 |
| 9 #include "core/src/fxcodec/lbmp/fx_bmp.h" |
| 10 |
| 8 void CGifLZWDecoder::Input(uint8_t* src_buf, FX_DWORD src_size) { | 11 void CGifLZWDecoder::Input(uint8_t* src_buf, FX_DWORD src_size) { |
| 9 next_in = src_buf; | 12 next_in = src_buf; |
| 10 avail_in = src_size; | 13 avail_in = src_size; |
| 11 } | 14 } |
| 12 FX_DWORD CGifLZWDecoder::GetAvailInput() { | 15 FX_DWORD CGifLZWDecoder::GetAvailInput() { |
| 13 return avail_in; | 16 return avail_in; |
| 14 } | 17 } |
| 15 void CGifLZWDecoder::InitTable(uint8_t code_len) { | 18 void CGifLZWDecoder::InitTable(uint8_t code_len) { |
| 16 code_size = code_len; | 19 code_size = code_len; |
| 17 code_clear = 1 << code_size; | 20 code_clear = 1 << code_size; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 stack_size = 0; | 137 stack_size = 0; |
| 135 } | 138 } |
| 136 } | 139 } |
| 137 } | 140 } |
| 138 if (avail_in == 0) { | 141 if (avail_in == 0) { |
| 139 des_size = i; | 142 des_size = i; |
| 140 return 2; | 143 return 2; |
| 141 } | 144 } |
| 142 return 0; | 145 return 0; |
| 143 } | 146 } |
| 144 static FX_BOOL _gif_grow_buf(uint8_t*& dst_buf, | 147 static FX_BOOL gif_grow_buf(uint8_t*& dst_buf, |
| 145 FX_DWORD& dst_len, | 148 FX_DWORD& dst_len, |
| 146 FX_DWORD size) { | 149 FX_DWORD size) { |
| 147 if (dst_len < size) { | 150 if (dst_len < size) { |
| 148 FX_DWORD len_org = dst_len; | 151 FX_DWORD len_org = dst_len; |
| 149 while (dst_buf && dst_len < size) { | 152 while (dst_buf && dst_len < size) { |
| 150 dst_len <<= 1; | 153 dst_len <<= 1; |
| 151 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); | 154 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); |
| 152 } | 155 } |
| 153 if (dst_buf == NULL) { | 156 if (dst_buf == NULL) { |
| 154 dst_len = size; | 157 dst_len = size; |
| 155 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); | 158 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); |
| 156 if (dst_buf == NULL) { | 159 if (dst_buf == NULL) { |
| 157 return FALSE; | 160 return FALSE; |
| 158 } | 161 } |
| 159 } | 162 } |
| 160 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org); | 163 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org); |
| 161 return dst_buf != NULL; | 164 return dst_buf != NULL; |
| 162 } | 165 } |
| 163 return TRUE; | 166 return TRUE; |
| 164 } | 167 } |
| 165 static inline void _gif_cut_index(uint8_t& val, | 168 static inline void gif_cut_index(uint8_t& val, |
| 166 FX_DWORD index, | 169 FX_DWORD index, |
| 167 uint8_t index_bit, | 170 uint8_t index_bit, |
| 168 uint8_t index_bit_use, | 171 uint8_t index_bit_use, |
| 169 uint8_t bit_use) { | 172 uint8_t bit_use) { |
| 170 FX_DWORD cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use; | 173 FX_DWORD cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use; |
| 171 val |= ((index & cut) >> index_bit_use) << bit_use; | 174 val |= ((index & cut) >> index_bit_use) << bit_use; |
| 172 } | 175 } |
| 173 static inline uint8_t _gif_cut_buf(const uint8_t* buf, | 176 static inline uint8_t gif_cut_buf(const uint8_t* buf, |
| 174 FX_DWORD& offset, | 177 FX_DWORD& offset, |
| 175 uint8_t bit_cut, | 178 uint8_t bit_cut, |
| 176 uint8_t& bit_offset, | 179 uint8_t& bit_offset, |
| 177 FX_DWORD& bit_num) { | 180 FX_DWORD& bit_num) { |
| 178 if (bit_cut != 8) { | 181 if (bit_cut != 8) { |
| 179 FX_WORD index = 0; | 182 FX_WORD index = 0; |
| 180 index |= ((1 << bit_cut) - 1) << (7 - bit_offset); | 183 index |= ((1 << bit_cut) - 1) << (7 - bit_offset); |
| 181 uint8_t ret = ((index & buf[offset]) >> (7 - bit_offset)); | 184 uint8_t ret = ((index & buf[offset]) >> (7 - bit_offset)); |
| 182 bit_offset += bit_cut; | 185 bit_offset += bit_cut; |
| 183 if (bit_offset >= 8) { | 186 if (bit_offset >= 8) { |
| 184 if (bit_offset > 8) { | 187 if (bit_offset > 8) { |
| 185 ret |= ((index & (buf[offset + 1] << 8)) >> 8); | 188 ret |= ((index & (buf[offset + 1] << 8)) >> 8); |
| 186 } | 189 } |
| 187 bit_offset -= 8; | 190 bit_offset -= 8; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 217 code_size = 2; | 220 code_size = 2; |
| 218 } | 221 } |
| 219 code_clear = 1 << code_size; | 222 code_clear = 1 << code_size; |
| 220 code_end = code_clear + 1; | 223 code_end = code_clear + 1; |
| 221 dst_buf[offset++] = code_size; | 224 dst_buf[offset++] = code_size; |
| 222 bit_offset = 0; | 225 bit_offset = 0; |
| 223 ClearTable(); | 226 ClearTable(); |
| 224 src_offset = 0; | 227 src_offset = 0; |
| 225 src_bit_offset = 0; | 228 src_bit_offset = 0; |
| 226 src_bit_num = 0; | 229 src_bit_num = 0; |
| 227 code_table[index_num].prefix = _gif_cut_buf(src_buf, src_offset, src_bit_cut, | 230 code_table[index_num].prefix = gif_cut_buf(src_buf, src_offset, src_bit_cut, |
| 228 src_bit_offset, src_bit_num); | 231 src_bit_offset, src_bit_num); |
| 229 code_table[index_num].suffix = _gif_cut_buf(src_buf, src_offset, src_bit_cut, | 232 code_table[index_num].suffix = gif_cut_buf(src_buf, src_offset, src_bit_cut, |
| 230 src_bit_offset, src_bit_num); | 233 src_bit_offset, src_bit_num); |
| 231 } | 234 } |
| 232 void CGifLZWEncoder::WriteBlock(uint8_t*& dst_buf, | 235 void CGifLZWEncoder::WriteBlock(uint8_t*& dst_buf, |
| 233 FX_DWORD& dst_len, | 236 FX_DWORD& dst_len, |
| 234 FX_DWORD& offset) { | 237 FX_DWORD& offset) { |
| 235 if (!_gif_grow_buf(dst_buf, dst_len, offset + GIF_DATA_BLOCK + 1)) { | 238 if (!gif_grow_buf(dst_buf, dst_len, offset + GIF_DATA_BLOCK + 1)) { |
| 236 longjmp(jmp, 1); | 239 longjmp(jmp, 1); |
| 237 } | 240 } |
| 238 dst_buf[offset++] = index_buf_len; | 241 dst_buf[offset++] = index_buf_len; |
| 239 FXSYS_memcpy(&dst_buf[offset], index_buf, index_buf_len); | 242 FXSYS_memcpy(&dst_buf[offset], index_buf, index_buf_len); |
| 240 offset += index_buf_len; | 243 offset += index_buf_len; |
| 241 FXSYS_memset(index_buf, 0, GIF_DATA_BLOCK); | 244 FXSYS_memset(index_buf, 0, GIF_DATA_BLOCK); |
| 242 index_buf_len = 0; | 245 index_buf_len = 0; |
| 243 } | 246 } |
| 244 void CGifLZWEncoder::EncodeString(FX_DWORD index, | 247 void CGifLZWEncoder::EncodeString(FX_DWORD index, |
| 245 uint8_t*& dst_buf, | 248 uint8_t*& dst_buf, |
| 246 FX_DWORD& dst_len, | 249 FX_DWORD& dst_len, |
| 247 FX_DWORD& offset) { | 250 FX_DWORD& offset) { |
| 248 uint8_t index_bit_use; | 251 uint8_t index_bit_use; |
| 249 index_bit_use = 0; | 252 index_bit_use = 0; |
| 250 if (index_buf_len == GIF_DATA_BLOCK) { | 253 if (index_buf_len == GIF_DATA_BLOCK) { |
| 251 WriteBlock(dst_buf, dst_len, offset); | 254 WriteBlock(dst_buf, dst_len, offset); |
| 252 } | 255 } |
| 253 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use, | 256 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use, |
| 254 bit_offset); | 257 bit_offset); |
| 255 if (index_bit_cur <= (8 - bit_offset)) { | 258 if (index_bit_cur <= (8 - bit_offset)) { |
| 256 bit_offset += index_bit_cur; | 259 bit_offset += index_bit_cur; |
| 257 } else if (index_bit_cur <= (16 - bit_offset)) { | 260 } else if (index_bit_cur <= (16 - bit_offset)) { |
| 258 index_bit_use += (8 - bit_offset); | 261 index_bit_use += (8 - bit_offset); |
| 259 bit_offset = 0; | 262 bit_offset = 0; |
| 260 index_buf_len++; | 263 index_buf_len++; |
| 261 if (index_buf_len == GIF_DATA_BLOCK) { | 264 if (index_buf_len == GIF_DATA_BLOCK) { |
| 262 WriteBlock(dst_buf, dst_len, offset); | 265 WriteBlock(dst_buf, dst_len, offset); |
| 263 } | 266 } |
| 264 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, | 267 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use, |
| 265 index_bit_use, bit_offset); | 268 bit_offset); |
| 266 bit_offset = index_bit_cur - index_bit_use; | 269 bit_offset = index_bit_cur - index_bit_use; |
| 267 } else { | 270 } else { |
| 268 index_bit_use += (8 - bit_offset); | 271 index_bit_use += (8 - bit_offset); |
| 269 bit_offset = 0; | 272 bit_offset = 0; |
| 270 index_buf_len++; | 273 index_buf_len++; |
| 271 if (index_buf_len == GIF_DATA_BLOCK) { | 274 if (index_buf_len == GIF_DATA_BLOCK) { |
| 272 WriteBlock(dst_buf, dst_len, offset); | 275 WriteBlock(dst_buf, dst_len, offset); |
| 273 } | 276 } |
| 274 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, | 277 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use, |
| 275 index_bit_use, bit_offset); | 278 bit_offset); |
| 276 index_bit_use += 8; | 279 index_bit_use += 8; |
| 277 bit_offset = 0; | 280 bit_offset = 0; |
| 278 index_buf_len++; | 281 index_buf_len++; |
| 279 if (index_buf_len == GIF_DATA_BLOCK) { | 282 if (index_buf_len == GIF_DATA_BLOCK) { |
| 280 WriteBlock(dst_buf, dst_len, offset); | 283 WriteBlock(dst_buf, dst_len, offset); |
| 281 } | 284 } |
| 282 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, | 285 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use, |
| 283 index_bit_use, bit_offset); | 286 bit_offset); |
| 284 bit_offset = index_bit_cur - index_bit_use; | 287 bit_offset = index_bit_cur - index_bit_use; |
| 285 } | 288 } |
| 286 if (bit_offset == 8) { | 289 if (bit_offset == 8) { |
| 287 bit_offset = 0; | 290 bit_offset = 0; |
| 288 index_buf_len++; | 291 index_buf_len++; |
| 289 if (index_buf_len == GIF_DATA_BLOCK) { | 292 if (index_buf_len == GIF_DATA_BLOCK) { |
| 290 WriteBlock(dst_buf, dst_len, offset); | 293 WriteBlock(dst_buf, dst_len, offset); |
| 291 } | 294 } |
| 292 } | 295 } |
| 293 if (index == code_end) { | 296 if (index == code_end) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 308 return FALSE; | 311 return FALSE; |
| 309 } | 312 } |
| 310 while (src_bit_num < src_len) { | 313 while (src_bit_num < src_len) { |
| 311 if (!LookUpInTable(src_buf, src_offset, src_bit_offset)) { | 314 if (!LookUpInTable(src_buf, src_offset, src_bit_offset)) { |
| 312 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); | 315 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); |
| 313 if (index_num == GIF_MAX_LZW_CODE) { | 316 if (index_num == GIF_MAX_LZW_CODE) { |
| 314 suffix = code_table[index_num - 1].suffix; | 317 suffix = code_table[index_num - 1].suffix; |
| 315 EncodeString(code_clear, dst_buf, dst_len, offset); | 318 EncodeString(code_clear, dst_buf, dst_len, offset); |
| 316 ClearTable(); | 319 ClearTable(); |
| 317 code_table[index_num].prefix = suffix; | 320 code_table[index_num].prefix = suffix; |
| 318 code_table[index_num].suffix = _gif_cut_buf( | 321 code_table[index_num].suffix = gif_cut_buf( |
| 319 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); | 322 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); |
| 320 } else { | 323 } else { |
| 321 code_table[index_num].prefix = code_table[index_num - 1].suffix; | 324 code_table[index_num].prefix = code_table[index_num - 1].suffix; |
| 322 code_table[index_num].suffix = _gif_cut_buf( | 325 code_table[index_num].suffix = gif_cut_buf( |
| 323 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); | 326 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); |
| 324 } | 327 } |
| 325 } | 328 } |
| 326 } | 329 } |
| 327 src_offset = 0; | 330 src_offset = 0; |
| 328 src_bit_offset = 0; | 331 src_bit_offset = 0; |
| 329 src_bit_num = 0; | 332 src_bit_num = 0; |
| 330 return TRUE; | 333 return TRUE; |
| 331 } | 334 } |
| 332 FX_BOOL CGifLZWEncoder::LookUpInTable(const uint8_t* buf, | 335 FX_BOOL CGifLZWEncoder::LookUpInTable(const uint8_t* buf, |
| 333 FX_DWORD& offset, | 336 FX_DWORD& offset, |
| 334 uint8_t& bit_offset) { | 337 uint8_t& bit_offset) { |
| 335 for (FX_WORD i = table_cur; i < index_num; i++) { | 338 for (FX_WORD i = table_cur; i < index_num; i++) { |
| 336 if (code_table[i].prefix == code_table[index_num].prefix && | 339 if (code_table[i].prefix == code_table[index_num].prefix && |
| 337 code_table[i].suffix == code_table[index_num].suffix) { | 340 code_table[i].suffix == code_table[index_num].suffix) { |
| 338 code_table[index_num].prefix = i; | 341 code_table[index_num].prefix = i; |
| 339 code_table[index_num].suffix = | 342 code_table[index_num].suffix = |
| 340 _gif_cut_buf(buf, offset, src_bit_cut, bit_offset, src_bit_num); | 343 gif_cut_buf(buf, offset, src_bit_cut, bit_offset, src_bit_num); |
| 341 table_cur = i; | 344 table_cur = i; |
| 342 return TRUE; | 345 return TRUE; |
| 343 } | 346 } |
| 344 } | 347 } |
| 345 table_cur = code_end + 1; | 348 table_cur = code_end + 1; |
| 346 return FALSE; | 349 return FALSE; |
| 347 } | 350 } |
| 348 void CGifLZWEncoder::Finish(uint8_t*& dst_buf, | 351 void CGifLZWEncoder::Finish(uint8_t*& dst_buf, |
| 349 FX_DWORD& dst_len, | 352 FX_DWORD& dst_len, |
| 350 FX_DWORD& offset) { | 353 FX_DWORD& offset) { |
| 351 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); | 354 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); |
| 352 EncodeString(code_end, dst_buf, dst_len, offset); | 355 EncodeString(code_end, dst_buf, dst_len, offset); |
| 353 bit_offset = 0; | 356 bit_offset = 0; |
| 354 ClearTable(); | 357 ClearTable(); |
| 355 } | 358 } |
| 356 gif_decompress_struct_p _gif_create_decompress() { | 359 gif_decompress_struct_p gif_create_decompress() { |
| 357 gif_decompress_struct_p gif_ptr = | 360 gif_decompress_struct_p gif_ptr = |
| 358 (gif_decompress_struct*)FX_Alloc(uint8_t, sizeof(gif_decompress_struct)); | 361 (gif_decompress_struct*)FX_Alloc(uint8_t, sizeof(gif_decompress_struct)); |
| 359 if (gif_ptr == NULL) { | 362 if (gif_ptr == NULL) { |
| 360 return NULL; | 363 return NULL; |
| 361 } | 364 } |
| 362 FXSYS_memset(gif_ptr, 0, sizeof(gif_decompress_struct)); | 365 FXSYS_memset(gif_ptr, 0, sizeof(gif_decompress_struct)); |
| 363 gif_ptr->decode_status = GIF_D_STATUS_SIG; | 366 gif_ptr->decode_status = GIF_D_STATUS_SIG; |
| 364 gif_ptr->img_ptr_arr_ptr = new CFX_ArrayTemplate<GifImage*>; | 367 gif_ptr->img_ptr_arr_ptr = new CFX_ArrayTemplate<GifImage*>; |
| 365 #ifdef GIF_SUPPORT_COMMENT_EXTENSION | |
| 366 gif_ptr->cmt_data_ptr = new CFX_ByteString; | 368 gif_ptr->cmt_data_ptr = new CFX_ByteString; |
| 367 #endif | |
| 368 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 369 gif_ptr->pt_ptr_arr_ptr = new CFX_ArrayTemplate<GifPlainText*>; | 369 gif_ptr->pt_ptr_arr_ptr = new CFX_ArrayTemplate<GifPlainText*>; |
| 370 #endif | |
| 371 return gif_ptr; | 370 return gif_ptr; |
| 372 } | 371 } |
| 373 void _gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) { | 372 void gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) { |
| 374 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { | 373 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { |
| 375 return; | 374 return; |
| 376 } | 375 } |
| 377 gif_decompress_struct_p gif_ptr = *gif_ptr_ptr; | 376 gif_decompress_struct_p gif_ptr = *gif_ptr_ptr; |
| 378 *gif_ptr_ptr = NULL; | 377 *gif_ptr_ptr = NULL; |
| 379 FX_Free(gif_ptr->global_pal_ptr); | 378 FX_Free(gif_ptr->global_pal_ptr); |
| 380 delete gif_ptr->img_decoder_ptr; | 379 delete gif_ptr->img_decoder_ptr; |
| 381 if (gif_ptr->img_ptr_arr_ptr) { | 380 if (gif_ptr->img_ptr_arr_ptr) { |
| 382 int32_t size_img_arr = gif_ptr->img_ptr_arr_ptr->GetSize(); | 381 int32_t size_img_arr = gif_ptr->img_ptr_arr_ptr->GetSize(); |
| 383 for (int32_t i = 0; i < size_img_arr; i++) { | 382 for (int32_t i = 0; i < size_img_arr; i++) { |
| 384 GifImage* p = gif_ptr->img_ptr_arr_ptr->GetAt(i); | 383 GifImage* p = gif_ptr->img_ptr_arr_ptr->GetAt(i); |
| 385 FX_Free(p->image_info_ptr); | 384 FX_Free(p->image_info_ptr); |
| 386 FX_Free(p->image_gce_ptr); | 385 FX_Free(p->image_gce_ptr); |
| 387 FX_Free(p->image_row_buf); | 386 FX_Free(p->image_row_buf); |
| 388 if (p->local_pal_ptr && p->local_pal_ptr != gif_ptr->global_pal_ptr) { | 387 if (p->local_pal_ptr && p->local_pal_ptr != gif_ptr->global_pal_ptr) { |
| 389 FX_Free(p->local_pal_ptr); | 388 FX_Free(p->local_pal_ptr); |
| 390 } | 389 } |
| 391 FX_Free(p); | 390 FX_Free(p); |
| 392 } | 391 } |
| 393 gif_ptr->img_ptr_arr_ptr->RemoveAll(); | 392 gif_ptr->img_ptr_arr_ptr->RemoveAll(); |
| 394 delete gif_ptr->img_ptr_arr_ptr; | 393 delete gif_ptr->img_ptr_arr_ptr; |
| 395 } | 394 } |
| 396 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION | |
| 397 FX_Free(gif_ptr->app_data); | |
| 398 #endif | |
| 399 #ifdef GIF_SUPPORT_COMMENT_EXTENSION | |
| 400 delete gif_ptr->cmt_data_ptr; | 395 delete gif_ptr->cmt_data_ptr; |
| 401 #endif | |
| 402 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | |
| 403 FX_Free(gif_ptr->gce_ptr); | 396 FX_Free(gif_ptr->gce_ptr); |
| 404 #endif | |
| 405 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 406 if (gif_ptr->pt_ptr_arr_ptr) { | 397 if (gif_ptr->pt_ptr_arr_ptr) { |
| 407 int32_t size_pt_arr = gif_ptr->pt_ptr_arr_ptr->GetSize(); | 398 int32_t size_pt_arr = gif_ptr->pt_ptr_arr_ptr->GetSize(); |
| 408 for (int32_t i = 0; i < size_pt_arr; i++) { | 399 for (int32_t i = 0; i < size_pt_arr; i++) { |
| 409 GifPlainText* p = gif_ptr->pt_ptr_arr_ptr->GetAt(i); | 400 GifPlainText* p = gif_ptr->pt_ptr_arr_ptr->GetAt(i); |
| 410 FX_Free(p->gce_ptr); | 401 FX_Free(p->gce_ptr); |
| 411 FX_Free(p->pte_ptr); | 402 FX_Free(p->pte_ptr); |
| 412 delete p->string_ptr; | 403 delete p->string_ptr; |
| 413 } | 404 } |
| 414 gif_ptr->pt_ptr_arr_ptr->RemoveAll(); | 405 gif_ptr->pt_ptr_arr_ptr->RemoveAll(); |
| 415 delete gif_ptr->pt_ptr_arr_ptr; | 406 delete gif_ptr->pt_ptr_arr_ptr; |
| 416 } | 407 } |
| 417 #endif | |
| 418 FX_Free(gif_ptr); | 408 FX_Free(gif_ptr); |
| 419 } | 409 } |
| 420 gif_compress_struct_p _gif_create_compress() { | 410 gif_compress_struct_p gif_create_compress() { |
| 421 gif_compress_struct_p gif_ptr = | 411 gif_compress_struct_p gif_ptr = |
| 422 (gif_compress_struct*)FX_Alloc(uint8_t, sizeof(gif_compress_struct)); | 412 (gif_compress_struct*)FX_Alloc(uint8_t, sizeof(gif_compress_struct)); |
| 423 if (gif_ptr == NULL) { | 413 if (gif_ptr == NULL) { |
| 424 return NULL; | 414 return NULL; |
| 425 } | 415 } |
| 426 FXSYS_memset(gif_ptr, 0, sizeof(gif_compress_struct)); | 416 FXSYS_memset(gif_ptr, 0, sizeof(gif_compress_struct)); |
| 427 gif_ptr->img_encoder_ptr = new CGifLZWEncoder; | 417 gif_ptr->img_encoder_ptr = new CGifLZWEncoder; |
| 428 gif_ptr->header_ptr = (GifHeader*)FX_Alloc(uint8_t, sizeof(GifHeader)); | 418 gif_ptr->header_ptr = (GifHeader*)FX_Alloc(uint8_t, sizeof(GifHeader)); |
| 429 if (gif_ptr->header_ptr == NULL) { | 419 if (gif_ptr->header_ptr == NULL) { |
| 430 delete (gif_ptr->img_encoder_ptr); | 420 delete (gif_ptr->img_encoder_ptr); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 444 gif_ptr->image_info_ptr = | 434 gif_ptr->image_info_ptr = |
| 445 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); | 435 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); |
| 446 if (gif_ptr->image_info_ptr == NULL) { | 436 if (gif_ptr->image_info_ptr == NULL) { |
| 447 FX_Free(gif_ptr->lsd_ptr); | 437 FX_Free(gif_ptr->lsd_ptr); |
| 448 FX_Free(gif_ptr->header_ptr); | 438 FX_Free(gif_ptr->header_ptr); |
| 449 delete (gif_ptr->img_encoder_ptr); | 439 delete (gif_ptr->img_encoder_ptr); |
| 450 FX_Free(gif_ptr); | 440 FX_Free(gif_ptr); |
| 451 return NULL; | 441 return NULL; |
| 452 } | 442 } |
| 453 FXSYS_memset(gif_ptr->image_info_ptr, 0, sizeof(GifImageInfo)); | 443 FXSYS_memset(gif_ptr->image_info_ptr, 0, sizeof(GifImageInfo)); |
| 454 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION | |
| 455 FXSYS_memcpy(gif_ptr->app_identify, "netscape", 8); | |
| 456 FXSYS_memcpy(gif_ptr->app_authentication, "2.0", 3); | |
| 457 #endif | |
| 458 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | |
| 459 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); | 444 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); |
| 460 if (gif_ptr->gce_ptr == NULL) { | 445 if (gif_ptr->gce_ptr == NULL) { |
| 461 FX_Free(gif_ptr->image_info_ptr); | 446 FX_Free(gif_ptr->image_info_ptr); |
| 462 FX_Free(gif_ptr->lsd_ptr); | 447 FX_Free(gif_ptr->lsd_ptr); |
| 463 FX_Free(gif_ptr->header_ptr); | 448 FX_Free(gif_ptr->header_ptr); |
| 464 delete (gif_ptr->img_encoder_ptr); | 449 delete (gif_ptr->img_encoder_ptr); |
| 465 FX_Free(gif_ptr); | 450 FX_Free(gif_ptr); |
| 466 return NULL; | 451 return NULL; |
| 467 } | 452 } |
| 468 #endif | |
| 469 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 470 gif_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); | 453 gif_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); |
| 471 if (gif_ptr->pte_ptr == NULL) { | 454 if (gif_ptr->pte_ptr == NULL) { |
| 472 FX_Free(gif_ptr->gce_ptr); | 455 FX_Free(gif_ptr->gce_ptr); |
| 473 FX_Free(gif_ptr->image_info_ptr); | 456 FX_Free(gif_ptr->image_info_ptr); |
| 474 FX_Free(gif_ptr->lsd_ptr); | 457 FX_Free(gif_ptr->lsd_ptr); |
| 475 FX_Free(gif_ptr->header_ptr); | 458 FX_Free(gif_ptr->header_ptr); |
| 476 delete (gif_ptr->img_encoder_ptr); | 459 delete (gif_ptr->img_encoder_ptr); |
| 477 FX_Free(gif_ptr); | 460 FX_Free(gif_ptr); |
| 478 return NULL; | 461 return NULL; |
| 479 } | 462 } |
| 480 FXSYS_memset(gif_ptr->pte_ptr, 0, sizeof(GifPTE)); | 463 FXSYS_memset(gif_ptr->pte_ptr, 0, sizeof(GifPTE)); |
| 481 gif_ptr->pte_ptr->block_size = 12; | 464 gif_ptr->pte_ptr->block_size = 12; |
| 482 #endif | |
| 483 return gif_ptr; | 465 return gif_ptr; |
| 484 } | 466 } |
| 485 void _gif_destroy_compress(gif_compress_struct_pp gif_ptr_ptr) { | 467 void gif_destroy_compress(gif_compress_struct_pp gif_ptr_ptr) { |
| 486 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { | 468 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { |
| 487 return; | 469 return; |
| 488 } | 470 } |
| 489 gif_compress_struct_p gif_ptr = *gif_ptr_ptr; | 471 gif_compress_struct_p gif_ptr = *gif_ptr_ptr; |
| 490 *gif_ptr_ptr = NULL; | 472 *gif_ptr_ptr = NULL; |
| 491 FX_Free(gif_ptr->header_ptr); | 473 FX_Free(gif_ptr->header_ptr); |
| 492 FX_Free(gif_ptr->lsd_ptr); | 474 FX_Free(gif_ptr->lsd_ptr); |
| 493 FX_Free(gif_ptr->global_pal); | 475 FX_Free(gif_ptr->global_pal); |
| 494 FX_Free(gif_ptr->image_info_ptr); | 476 FX_Free(gif_ptr->image_info_ptr); |
| 495 FX_Free(gif_ptr->local_pal); | 477 FX_Free(gif_ptr->local_pal); |
| 496 delete gif_ptr->img_encoder_ptr; | 478 delete gif_ptr->img_encoder_ptr; |
| 497 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION | |
| 498 FX_Free(gif_ptr->app_data); | |
| 499 #endif | |
| 500 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | |
| 501 FX_Free(gif_ptr->gce_ptr); | 479 FX_Free(gif_ptr->gce_ptr); |
| 502 #endif | |
| 503 #ifdef GIF_SUPPORT_COMMENT_EXTENSION | |
| 504 FX_Free(gif_ptr->cmt_data_ptr); | 480 FX_Free(gif_ptr->cmt_data_ptr); |
| 505 #endif | |
| 506 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 507 FX_Free(gif_ptr->pte_ptr); | 481 FX_Free(gif_ptr->pte_ptr); |
| 508 #endif | |
| 509 FX_Free(gif_ptr); | 482 FX_Free(gif_ptr); |
| 510 } | 483 } |
| 511 void _gif_error(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) { | 484 void gif_error(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) { |
| 512 if (gif_ptr && gif_ptr->_gif_error_fn) { | 485 if (gif_ptr && gif_ptr->gif_error_fn) { |
| 513 gif_ptr->_gif_error_fn(gif_ptr, err_msg); | 486 gif_ptr->gif_error_fn(gif_ptr, err_msg); |
| 514 } | 487 } |
| 515 } | 488 } |
| 516 void _gif_warn(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {} | 489 void gif_warn(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {} |
| 517 int32_t _gif_read_header(gif_decompress_struct_p gif_ptr) { | 490 int32_t gif_read_header(gif_decompress_struct_p gif_ptr) { |
| 518 if (gif_ptr == NULL) { | 491 if (gif_ptr == NULL) { |
| 519 return 0; | 492 return 0; |
| 520 } | 493 } |
| 521 FX_DWORD skip_size_org = gif_ptr->skip_size; | 494 FX_DWORD skip_size_org = gif_ptr->skip_size; |
| 522 ASSERT(sizeof(GifHeader) == 6); | 495 ASSERT(sizeof(GifHeader) == 6); |
| 523 GifHeader* gif_header_ptr = NULL; | 496 GifHeader* gif_header_ptr = NULL; |
| 524 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6) == NULL) { | 497 if (gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6) == NULL) { |
| 525 return 2; | 498 return 2; |
| 526 } | 499 } |
| 527 if (FXSYS_strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 || | 500 if (FXSYS_strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 || |
| 528 gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') { | 501 gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') { |
| 529 _gif_error(gif_ptr, "Not A Gif Image"); | 502 gif_error(gif_ptr, "Not A Gif Image"); |
| 530 return 0; | 503 return 0; |
| 531 } | 504 } |
| 532 ASSERT(sizeof(GifLSD) == 7); | 505 ASSERT(sizeof(GifLSD) == 7); |
| 533 GifLSD* gif_lsd_ptr = NULL; | 506 GifLSD* gif_lsd_ptr = NULL; |
| 534 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7) == NULL) { | 507 if (gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7) == NULL) { |
| 535 gif_ptr->skip_size = skip_size_org; | 508 gif_ptr->skip_size = skip_size_org; |
| 536 return 2; | 509 return 2; |
| 537 } | 510 } |
| 538 if (((GifGF*)&gif_lsd_ptr->global_flag)->global_pal) { | 511 if (((GifGF*)&gif_lsd_ptr->global_flag)->global_pal) { |
| 539 gif_ptr->global_pal_num = 2 | 512 gif_ptr->global_pal_num = 2 |
| 540 << ((GifGF*)&gif_lsd_ptr->global_flag)->pal_bits; | 513 << ((GifGF*)&gif_lsd_ptr->global_flag)->pal_bits; |
| 541 ASSERT(sizeof(GifPalette) == 3); | 514 ASSERT(sizeof(GifPalette) == 3); |
| 542 int32_t global_pal_size = gif_ptr->global_pal_num * 3; | 515 int32_t global_pal_size = gif_ptr->global_pal_num * 3; |
| 543 uint8_t* global_pal_ptr = NULL; | 516 uint8_t* global_pal_ptr = NULL; |
| 544 if (_gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size) == NULL) { | 517 if (gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size) == NULL) { |
| 545 gif_ptr->skip_size = skip_size_org; | 518 gif_ptr->skip_size = skip_size_org; |
| 546 return 2; | 519 return 2; |
| 547 } | 520 } |
| 548 gif_ptr->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag; | 521 gif_ptr->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag; |
| 549 gif_ptr->global_color_resolution = | 522 gif_ptr->global_color_resolution = |
| 550 ((GifGF*)&gif_lsd_ptr->global_flag)->color_resolution; | 523 ((GifGF*)&gif_lsd_ptr->global_flag)->color_resolution; |
| 551 FX_Free(gif_ptr->global_pal_ptr); | 524 FX_Free(gif_ptr->global_pal_ptr); |
| 552 gif_ptr->global_pal_ptr = (GifPalette*)FX_Alloc(uint8_t, global_pal_size); | 525 gif_ptr->global_pal_ptr = (GifPalette*)FX_Alloc(uint8_t, global_pal_size); |
| 553 FXSYS_memcpy(gif_ptr->global_pal_ptr, global_pal_ptr, global_pal_size); | 526 FXSYS_memcpy(gif_ptr->global_pal_ptr, global_pal_ptr, global_pal_size); |
| 554 } | 527 } |
| 555 gif_ptr->width = (int)_GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->width); | 528 gif_ptr->width = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->width); |
| 556 gif_ptr->height = (int)_GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height); | 529 gif_ptr->height = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height); |
| 557 gif_ptr->bc_index = gif_lsd_ptr->bc_index; | 530 gif_ptr->bc_index = gif_lsd_ptr->bc_index; |
| 558 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect; | 531 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect; |
| 559 return 1; | 532 return 1; |
| 560 } | 533 } |
| 561 int32_t _gif_get_frame(gif_decompress_struct_p gif_ptr) { | 534 int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { |
| 562 if (gif_ptr == NULL) { | 535 if (gif_ptr == NULL) { |
| 563 return 0; | 536 return 0; |
| 564 } | 537 } |
| 565 int32_t ret = 1; | 538 int32_t ret = 1; |
| 566 while (TRUE) { | 539 while (TRUE) { |
| 567 switch (gif_ptr->decode_status) { | 540 switch (gif_ptr->decode_status) { |
| 568 case GIF_D_STATUS_TAIL: | 541 case GIF_D_STATUS_TAIL: |
| 569 return 1; | 542 return 1; |
| 570 case GIF_D_STATUS_SIG: { | 543 case GIF_D_STATUS_SIG: { |
| 571 uint8_t* sig_ptr = NULL; | 544 uint8_t* sig_ptr = NULL; |
| 572 if (_gif_read_data(gif_ptr, &sig_ptr, 1) == NULL) { | 545 if (gif_read_data(gif_ptr, &sig_ptr, 1) == NULL) { |
| 573 return 2; | 546 return 2; |
| 574 } | 547 } |
| 575 switch (*sig_ptr) { | 548 switch (*sig_ptr) { |
| 576 case GIF_SIG_EXTENSION: | 549 case GIF_SIG_EXTENSION: |
| 577 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT); | 550 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT); |
| 578 continue; | 551 continue; |
| 579 case GIF_SIG_IMAGE: | 552 case GIF_SIG_IMAGE: |
| 580 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_INFO); | 553 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_INFO); |
| 581 continue; | 554 continue; |
| 582 case GIF_SIG_TRAILER: | 555 case GIF_SIG_TRAILER: |
| 583 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 556 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 584 return 1; | 557 return 1; |
| 585 default: | 558 default: |
| 586 if (gif_ptr->avail_in) { | 559 if (gif_ptr->avail_in) { |
| 587 _gif_warn(gif_ptr, "The Gif File has non_standard Tag!"); | 560 gif_warn(gif_ptr, "The Gif File has non_standard Tag!"); |
| 588 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); | 561 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); |
| 589 continue; | 562 continue; |
| 590 } | 563 } |
| 591 _gif_warn(gif_ptr, "The Gif File Doesn't have Trailer Tag!"); | 564 gif_warn(gif_ptr, "The Gif File Doesn't have Trailer Tag!"); |
| 592 return 1; | 565 return 1; |
| 593 } | 566 } |
| 594 } | 567 } |
| 595 case GIF_D_STATUS_EXT: { | 568 case GIF_D_STATUS_EXT: { |
| 596 uint8_t* ext_ptr = NULL; | 569 uint8_t* ext_ptr = NULL; |
| 597 if (_gif_read_data(gif_ptr, &ext_ptr, 1) == NULL) { | 570 if (gif_read_data(gif_ptr, &ext_ptr, 1) == NULL) { |
| 598 return 2; | 571 return 2; |
| 599 } | 572 } |
| 600 switch (*ext_ptr) { | 573 switch (*ext_ptr) { |
| 601 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION | 574 case GIF_BLOCK_CE: |
| 602 case GIF_BLOCK_AE: | 575 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE); |
| 603 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_AE); | |
| 604 continue; | 576 continue; |
| 605 #endif | 577 case GIF_BLOCK_GCE: |
| 606 #ifdef GIF_SUPPORT_COMMENT_EXTENSION | 578 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_GCE); |
| 607 case GIF_BLOCK_CE: | |
| 608 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE); | |
| 609 continue; | 579 continue; |
| 610 #endif | 580 case GIF_BLOCK_PTE: |
| 611 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | 581 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_PTE); |
| 612 case GIF_BLOCK_GCE: | |
| 613 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_GCE); | |
| 614 continue; | 582 continue; |
| 615 #endif | |
| 616 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 617 case GIF_BLOCK_PTE: | |
| 618 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_PTE); | |
| 619 continue; | |
| 620 #endif | |
| 621 default: { | 583 default: { |
| 622 int32_t status = GIF_D_STATUS_EXT_UNE; | 584 int32_t status = GIF_D_STATUS_EXT_UNE; |
| 623 #ifndef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 624 if (*ext_ptr == GIF_BLOCK_PTE) { | 585 if (*ext_ptr == GIF_BLOCK_PTE) { |
| 625 status = GIF_D_STATUS_EXT_PTE; | 586 status = GIF_D_STATUS_EXT_PTE; |
| 626 } | 587 } |
| 627 #endif | 588 gif_save_decoding_status(gif_ptr, status); |
| 628 _gif_save_decoding_status(gif_ptr, status); | |
| 629 continue; | 589 continue; |
| 630 } | 590 } |
| 631 } | 591 } |
| 632 } | 592 } |
| 633 case GIF_D_STATUS_IMG_INFO: { | 593 case GIF_D_STATUS_IMG_INFO: { |
| 634 ret = _gif_decode_image_info(gif_ptr); | 594 ret = gif_decode_image_info(gif_ptr); |
| 635 if (ret != 1) { | 595 if (ret != 1) { |
| 636 return ret; | 596 return ret; |
| 637 } | 597 } |
| 638 continue; | 598 continue; |
| 639 } | 599 } |
| 640 case GIF_D_STATUS_IMG_DATA: { | 600 case GIF_D_STATUS_IMG_DATA: { |
| 641 uint8_t* data_size_ptr = NULL; | 601 uint8_t* data_size_ptr = NULL; |
| 642 uint8_t* data_ptr = NULL; | 602 uint8_t* data_ptr = NULL; |
| 643 FX_DWORD skip_size_org = gif_ptr->skip_size; | 603 FX_DWORD skip_size_org = gif_ptr->skip_size; |
| 644 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 604 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 645 return 2; | 605 return 2; |
| 646 } | 606 } |
| 647 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 607 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
| 648 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { | 608 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { |
| 649 gif_ptr->skip_size = skip_size_org; | 609 gif_ptr->skip_size = skip_size_org; |
| 650 return 2; | 610 return 2; |
| 651 } | 611 } |
| 652 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 612 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
| 653 skip_size_org = gif_ptr->skip_size; | 613 skip_size_org = gif_ptr->skip_size; |
| 654 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 614 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 655 return 2; | 615 return 2; |
| 656 } | 616 } |
| 657 } | 617 } |
| 658 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); | 618 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); |
| 659 continue; | 619 continue; |
| 660 } | 620 } |
| 661 default: { | 621 default: { |
| 662 ret = _gif_decode_extension(gif_ptr); | 622 ret = gif_decode_extension(gif_ptr); |
| 663 if (ret != 1) { | 623 if (ret != 1) { |
| 664 return ret; | 624 return ret; |
| 665 } | 625 } |
| 666 continue; | 626 continue; |
| 667 } | 627 } |
| 668 } | 628 } |
| 669 } | 629 } |
| 670 return 1; | 630 return 1; |
| 671 } | 631 } |
| 672 void _gif_takeover_gce_ptr(gif_decompress_struct_p gif_ptr, | 632 void gif_takeover_gce_ptr(gif_decompress_struct_p gif_ptr, |
| 673 GifGCE** gce_ptr_ptr) { | 633 GifGCE** gce_ptr_ptr) { |
| 674 *gce_ptr_ptr = NULL; | 634 *gce_ptr_ptr = NULL; |
| 675 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | |
| 676 if (gif_ptr->gce_ptr && gce_ptr_ptr) { | 635 if (gif_ptr->gce_ptr && gce_ptr_ptr) { |
| 677 *gce_ptr_ptr = gif_ptr->gce_ptr; | 636 *gce_ptr_ptr = gif_ptr->gce_ptr; |
| 678 gif_ptr->gce_ptr = NULL; | 637 gif_ptr->gce_ptr = NULL; |
| 679 } | 638 } |
| 680 #endif | |
| 681 } | 639 } |
| 682 int32_t _gif_decode_extension(gif_decompress_struct_p gif_ptr) { | 640 int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
| 683 uint8_t* data_size_ptr = NULL; | 641 uint8_t* data_size_ptr = NULL; |
| 684 uint8_t* data_ptr = NULL; | 642 uint8_t* data_ptr = NULL; |
| 685 FX_DWORD skip_size_org = gif_ptr->skip_size; | 643 FX_DWORD skip_size_org = gif_ptr->skip_size; |
| 686 switch (gif_ptr->decode_status) { | 644 switch (gif_ptr->decode_status) { |
| 687 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION | |
| 688 case GIF_D_STATUS_EXT_AE: { | |
| 689 ASSERT(sizeof(GifAE) == 12); | |
| 690 GifAE* gif_ae_ptr = NULL; | |
| 691 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_ae_ptr, 12) == NULL) { | |
| 692 return 2; | |
| 693 } | |
| 694 CFX_ByteString gif_ae_data_str; | |
| 695 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | |
| 696 gif_ptr->skip_size = skip_size_org; | |
| 697 return 2; | |
| 698 } | |
| 699 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | |
| 700 uint8_t data_size = *data_size_ptr; | |
| 701 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || | |
| 702 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | |
| 703 gif_ptr->skip_size = skip_size_org; | |
| 704 return 2; | |
| 705 } | |
| 706 gif_ae_data_str += CFX_ByteString((const uint8_t*)data_ptr, data_size); | |
| 707 } | |
| 708 FXSYS_memcpy(gif_ptr->app_identify, gif_ae_ptr->app_identify, 8); | |
| 709 FXSYS_memcpy(gif_ptr->app_authentication, gif_ae_ptr->app_authentication, | |
| 710 3); | |
| 711 gif_ptr->app_data_size = gif_ae_data_str.GetLength(); | |
| 712 FX_Free(gif_ptr->app_data); | |
| 713 gif_ptr->app_data = FX_Alloc(uint8_t, gif_ptr->app_data_size); | |
| 714 FXSYS_memcpy(gif_ptr->app_data, const uint8_t*(gif_ae_data_str), | |
| 715 gif_ptr->app_data_size); | |
| 716 } break; | |
| 717 #endif | |
| 718 #ifdef GIF_SUPPORT_COMMENT_EXTENSION | |
| 719 case GIF_D_STATUS_EXT_CE: { | 645 case GIF_D_STATUS_EXT_CE: { |
| 720 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 646 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 721 gif_ptr->skip_size = skip_size_org; | 647 gif_ptr->skip_size = skip_size_org; |
| 722 return 2; | 648 return 2; |
| 723 } | 649 } |
| 724 gif_ptr->cmt_data_ptr->Empty(); | 650 gif_ptr->cmt_data_ptr->Empty(); |
| 725 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 651 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
| 726 uint8_t data_size = *data_size_ptr; | 652 uint8_t data_size = *data_size_ptr; |
| 727 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || | 653 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || |
| 728 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 654 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 729 gif_ptr->skip_size = skip_size_org; | 655 gif_ptr->skip_size = skip_size_org; |
| 730 return 2; | 656 return 2; |
| 731 } | 657 } |
| 732 *(gif_ptr->cmt_data_ptr) += | 658 *(gif_ptr->cmt_data_ptr) += |
| 733 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); | 659 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); |
| 734 } | 660 } |
| 735 } break; | 661 } break; |
| 736 #endif | |
| 737 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 738 case GIF_D_STATUS_EXT_PTE: { | 662 case GIF_D_STATUS_EXT_PTE: { |
| 739 ASSERT(sizeof(GifPTE) == 13); | 663 ASSERT(sizeof(GifPTE) == 13); |
| 740 GifPTE* gif_pte_ptr = NULL; | 664 GifPTE* gif_pte_ptr = NULL; |
| 741 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13) == NULL) { | 665 if (gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13) == NULL) { |
| 742 return 2; | 666 return 2; |
| 743 } | 667 } |
| 744 GifPlainText* gif_pt_ptr = FX_Alloc(GifPlainText, 1); | 668 GifPlainText* gif_pt_ptr = FX_Alloc(GifPlainText, 1); |
| 745 FXSYS_memset(gif_pt_ptr, 0, sizeof(GifPlainText)); | 669 FXSYS_memset(gif_pt_ptr, 0, sizeof(GifPlainText)); |
| 746 _gif_takeover_gce_ptr(gif_ptr, &gif_pt_ptr->gce_ptr); | 670 gif_takeover_gce_ptr(gif_ptr, &gif_pt_ptr->gce_ptr); |
| 747 gif_pt_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); | 671 gif_pt_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); |
| 748 gif_pt_ptr->string_ptr = new CFX_ByteString; | 672 gif_pt_ptr->string_ptr = new CFX_ByteString; |
| 749 gif_pt_ptr->pte_ptr->block_size = gif_pte_ptr->block_size; | 673 gif_pt_ptr->pte_ptr->block_size = gif_pte_ptr->block_size; |
| 750 gif_pt_ptr->pte_ptr->grid_left = | 674 gif_pt_ptr->pte_ptr->grid_left = |
| 751 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_left); | 675 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_left); |
| 752 gif_pt_ptr->pte_ptr->grid_top = | 676 gif_pt_ptr->pte_ptr->grid_top = |
| 753 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_top); | 677 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_top); |
| 754 gif_pt_ptr->pte_ptr->grid_width = | 678 gif_pt_ptr->pte_ptr->grid_width = |
| 755 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_width); | 679 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_width); |
| 756 gif_pt_ptr->pte_ptr->grid_height = | 680 gif_pt_ptr->pte_ptr->grid_height = |
| 757 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_height); | 681 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_height); |
| 758 gif_pt_ptr->pte_ptr->char_width = gif_pte_ptr->char_width; | 682 gif_pt_ptr->pte_ptr->char_width = gif_pte_ptr->char_width; |
| 759 gif_pt_ptr->pte_ptr->char_height = gif_pte_ptr->char_height; | 683 gif_pt_ptr->pte_ptr->char_height = gif_pte_ptr->char_height; |
| 760 gif_pt_ptr->pte_ptr->fc_index = gif_pte_ptr->fc_index; | 684 gif_pt_ptr->pte_ptr->fc_index = gif_pte_ptr->fc_index; |
| 761 gif_pt_ptr->pte_ptr->bc_index = gif_pte_ptr->bc_index; | 685 gif_pt_ptr->pte_ptr->bc_index = gif_pte_ptr->bc_index; |
| 762 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 686 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 763 gif_ptr->skip_size = skip_size_org; | 687 gif_ptr->skip_size = skip_size_org; |
| 764 if (gif_pt_ptr) { | 688 if (gif_pt_ptr) { |
| 765 FX_Free(gif_pt_ptr->gce_ptr); | 689 FX_Free(gif_pt_ptr->gce_ptr); |
| 766 FX_Free(gif_pt_ptr->pte_ptr); | 690 FX_Free(gif_pt_ptr->pte_ptr); |
| 767 delete gif_pt_ptr->string_ptr; | 691 delete gif_pt_ptr->string_ptr; |
| 768 FX_Free(gif_pt_ptr); | 692 FX_Free(gif_pt_ptr); |
| 769 } | 693 } |
| 770 return 2; | 694 return 2; |
| 771 } | 695 } |
| 772 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 696 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
| 773 uint8_t data_size = *data_size_ptr; | 697 uint8_t data_size = *data_size_ptr; |
| 774 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || | 698 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || |
| 775 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 699 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 776 gif_ptr->skip_size = skip_size_org; | 700 gif_ptr->skip_size = skip_size_org; |
| 777 if (gif_pt_ptr) { | 701 if (gif_pt_ptr) { |
| 778 FX_Free(gif_pt_ptr->gce_ptr); | 702 FX_Free(gif_pt_ptr->gce_ptr); |
| 779 FX_Free(gif_pt_ptr->pte_ptr); | 703 FX_Free(gif_pt_ptr->pte_ptr); |
| 780 delete gif_pt_ptr->string_ptr; | 704 delete gif_pt_ptr->string_ptr; |
| 781 FX_Free(gif_pt_ptr); | 705 FX_Free(gif_pt_ptr); |
| 782 } | 706 } |
| 783 return 2; | 707 return 2; |
| 784 } | 708 } |
| 785 *(gif_pt_ptr->string_ptr) += | 709 *(gif_pt_ptr->string_ptr) += |
| 786 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); | 710 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); |
| 787 } | 711 } |
| 788 gif_ptr->pt_ptr_arr_ptr->Add(gif_pt_ptr); | 712 gif_ptr->pt_ptr_arr_ptr->Add(gif_pt_ptr); |
| 789 } break; | 713 } break; |
| 790 #endif | |
| 791 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | |
| 792 case GIF_D_STATUS_EXT_GCE: { | 714 case GIF_D_STATUS_EXT_GCE: { |
| 793 ASSERT(sizeof(GifGCE) == 5); | 715 ASSERT(sizeof(GifGCE) == 5); |
| 794 GifGCE* gif_gce_ptr = NULL; | 716 GifGCE* gif_gce_ptr = NULL; |
| 795 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6) == NULL) { | 717 if (gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6) == NULL) { |
| 796 return 2; | 718 return 2; |
| 797 } | 719 } |
| 798 if (gif_ptr->gce_ptr == NULL) { | 720 if (gif_ptr->gce_ptr == NULL) { |
| 799 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); | 721 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); |
| 800 } | 722 } |
| 801 gif_ptr->gce_ptr->block_size = gif_gce_ptr->block_size; | 723 gif_ptr->gce_ptr->block_size = gif_gce_ptr->block_size; |
| 802 gif_ptr->gce_ptr->gce_flag = gif_gce_ptr->gce_flag; | 724 gif_ptr->gce_ptr->gce_flag = gif_gce_ptr->gce_flag; |
| 803 gif_ptr->gce_ptr->delay_time = | 725 gif_ptr->gce_ptr->delay_time = |
| 804 _GetWord_LSBFirst((uint8_t*)&gif_gce_ptr->delay_time); | 726 GetWord_LSBFirst((uint8_t*)&gif_gce_ptr->delay_time); |
| 805 gif_ptr->gce_ptr->trans_index = gif_gce_ptr->trans_index; | 727 gif_ptr->gce_ptr->trans_index = gif_gce_ptr->trans_index; |
| 806 } break; | 728 } break; |
| 807 #endif | |
| 808 default: { | 729 default: { |
| 809 #ifndef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 810 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | |
| 811 if (gif_ptr->decode_status == GIF_D_STATUS_EXT_PTE) { | 730 if (gif_ptr->decode_status == GIF_D_STATUS_EXT_PTE) { |
| 812 FX_Free(gif_ptr->gce_ptr); | 731 FX_Free(gif_ptr->gce_ptr); |
| 813 gif_ptr->gce_ptr = NULL; | 732 gif_ptr->gce_ptr = NULL; |
| 814 } | 733 } |
| 815 #endif | 734 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 816 #endif | |
| 817 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | |
| 818 return 2; | 735 return 2; |
| 819 } | 736 } |
| 820 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 737 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
| 821 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || | 738 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || |
| 822 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 739 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 823 gif_ptr->skip_size = skip_size_org; | 740 gif_ptr->skip_size = skip_size_org; |
| 824 return 2; | 741 return 2; |
| 825 } | 742 } |
| 826 } | 743 } |
| 827 } | 744 } |
| 828 } | 745 } |
| 829 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); | 746 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); |
| 830 return 1; | 747 return 1; |
| 831 } | 748 } |
| 832 int32_t _gif_decode_image_info(gif_decompress_struct_p gif_ptr) { | 749 int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) { |
| 833 if (gif_ptr->width == 0 || gif_ptr->height == 0) { | 750 if (gif_ptr->width == 0 || gif_ptr->height == 0) { |
| 834 _gif_error(gif_ptr, "No Image Header Info"); | 751 gif_error(gif_ptr, "No Image Header Info"); |
| 835 return 0; | 752 return 0; |
| 836 } | 753 } |
| 837 FX_DWORD skip_size_org = gif_ptr->skip_size; | 754 FX_DWORD skip_size_org = gif_ptr->skip_size; |
| 838 ASSERT(sizeof(GifImageInfo) == 9); | 755 ASSERT(sizeof(GifImageInfo) == 9); |
| 839 GifImageInfo* gif_img_info_ptr = NULL; | 756 GifImageInfo* gif_img_info_ptr = NULL; |
| 840 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9) == NULL) { | 757 if (gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9) == NULL) { |
| 841 return 2; | 758 return 2; |
| 842 } | 759 } |
| 843 GifImage* gif_image_ptr = (GifImage*)FX_Alloc(uint8_t, sizeof(GifImage)); | 760 GifImage* gif_image_ptr = (GifImage*)FX_Alloc(uint8_t, sizeof(GifImage)); |
| 844 FXSYS_memset(gif_image_ptr, 0, sizeof(GifImage)); | 761 FXSYS_memset(gif_image_ptr, 0, sizeof(GifImage)); |
| 845 gif_image_ptr->image_info_ptr = | 762 gif_image_ptr->image_info_ptr = |
| 846 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); | 763 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); |
| 847 gif_image_ptr->image_info_ptr->left = | 764 gif_image_ptr->image_info_ptr->left = |
| 848 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->left); | 765 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->left); |
| 849 gif_image_ptr->image_info_ptr->top = | 766 gif_image_ptr->image_info_ptr->top = |
| 850 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->top); | 767 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->top); |
| 851 gif_image_ptr->image_info_ptr->width = | 768 gif_image_ptr->image_info_ptr->width = |
| 852 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->width); | 769 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->width); |
| 853 gif_image_ptr->image_info_ptr->height = | 770 gif_image_ptr->image_info_ptr->height = |
| 854 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->height); | 771 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->height); |
| 855 gif_image_ptr->image_info_ptr->local_flag = gif_img_info_ptr->local_flag; | 772 gif_image_ptr->image_info_ptr->local_flag = gif_img_info_ptr->local_flag; |
| 856 if (gif_image_ptr->image_info_ptr->left + | 773 if (gif_image_ptr->image_info_ptr->left + |
| 857 gif_image_ptr->image_info_ptr->width > | 774 gif_image_ptr->image_info_ptr->width > |
| 858 gif_ptr->width || | 775 gif_ptr->width || |
| 859 gif_image_ptr->image_info_ptr->top + | 776 gif_image_ptr->image_info_ptr->top + |
| 860 gif_image_ptr->image_info_ptr->height > | 777 gif_image_ptr->image_info_ptr->height > |
| 861 gif_ptr->height) { | 778 gif_ptr->height) { |
| 862 FX_Free(gif_image_ptr->image_info_ptr); | 779 FX_Free(gif_image_ptr->image_info_ptr); |
| 863 FX_Free(gif_image_ptr->image_row_buf); | 780 FX_Free(gif_image_ptr->image_row_buf); |
| 864 FX_Free(gif_image_ptr); | 781 FX_Free(gif_image_ptr); |
| 865 _gif_error(gif_ptr, "Image Data Out Of LSD, The File May Be Corrupt"); | 782 gif_error(gif_ptr, "Image Data Out Of LSD, The File May Be Corrupt"); |
| 866 return 0; | 783 return 0; |
| 867 } | 784 } |
| 868 GifLF* gif_img_info_lf_ptr = (GifLF*)&gif_img_info_ptr->local_flag; | 785 GifLF* gif_img_info_lf_ptr = (GifLF*)&gif_img_info_ptr->local_flag; |
| 869 if (gif_img_info_lf_ptr->local_pal) { | 786 if (gif_img_info_lf_ptr->local_pal) { |
| 870 ASSERT(sizeof(GifPalette) == 3); | 787 ASSERT(sizeof(GifPalette) == 3); |
| 871 int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3; | 788 int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3; |
| 872 uint8_t* loc_pal_ptr = NULL; | 789 uint8_t* loc_pal_ptr = NULL; |
| 873 if (_gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size) == NULL) { | 790 if (gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size) == NULL) { |
| 874 gif_ptr->skip_size = skip_size_org; | 791 gif_ptr->skip_size = skip_size_org; |
| 875 FX_Free(gif_image_ptr->image_info_ptr); | 792 FX_Free(gif_image_ptr->image_info_ptr); |
| 876 FX_Free(gif_image_ptr->image_row_buf); | 793 FX_Free(gif_image_ptr->image_row_buf); |
| 877 FX_Free(gif_image_ptr); | 794 FX_Free(gif_image_ptr); |
| 878 return 2; | 795 return 2; |
| 879 } | 796 } |
| 880 gif_image_ptr->local_pal_ptr = | 797 gif_image_ptr->local_pal_ptr = |
| 881 (GifPalette*)gif_ptr->_gif_ask_buf_for_pal_fn(gif_ptr, loc_pal_size); | 798 (GifPalette*)gif_ptr->gif_ask_buf_for_pal_fn(gif_ptr, loc_pal_size); |
| 882 if (gif_image_ptr->local_pal_ptr) { | 799 if (gif_image_ptr->local_pal_ptr) { |
| 883 FXSYS_memcpy((uint8_t*)gif_image_ptr->local_pal_ptr, loc_pal_ptr, | 800 FXSYS_memcpy((uint8_t*)gif_image_ptr->local_pal_ptr, loc_pal_ptr, |
| 884 loc_pal_size); | 801 loc_pal_size); |
| 885 } | 802 } |
| 886 } | 803 } |
| 887 uint8_t* code_size_ptr = NULL; | 804 uint8_t* code_size_ptr = NULL; |
| 888 if (_gif_read_data(gif_ptr, &code_size_ptr, 1) == NULL) { | 805 if (gif_read_data(gif_ptr, &code_size_ptr, 1) == NULL) { |
| 889 gif_ptr->skip_size = skip_size_org; | 806 gif_ptr->skip_size = skip_size_org; |
| 890 FX_Free(gif_image_ptr->image_info_ptr); | 807 FX_Free(gif_image_ptr->image_info_ptr); |
| 891 FX_Free(gif_image_ptr->local_pal_ptr); | 808 FX_Free(gif_image_ptr->local_pal_ptr); |
| 892 FX_Free(gif_image_ptr->image_row_buf); | 809 FX_Free(gif_image_ptr->image_row_buf); |
| 893 FX_Free(gif_image_ptr); | 810 FX_Free(gif_image_ptr); |
| 894 return 2; | 811 return 2; |
| 895 } | 812 } |
| 896 gif_image_ptr->image_code_size = *code_size_ptr; | 813 gif_image_ptr->image_code_size = *code_size_ptr; |
| 897 gif_ptr->_gif_record_current_position_fn(gif_ptr, | 814 gif_ptr->gif_record_current_position_fn(gif_ptr, |
| 898 &gif_image_ptr->image_data_pos); | 815 &gif_image_ptr->image_data_pos); |
| 899 gif_image_ptr->image_data_pos += gif_ptr->skip_size; | 816 gif_image_ptr->image_data_pos += gif_ptr->skip_size; |
| 900 _gif_takeover_gce_ptr(gif_ptr, &gif_image_ptr->image_gce_ptr); | 817 gif_takeover_gce_ptr(gif_ptr, &gif_image_ptr->image_gce_ptr); |
| 901 gif_ptr->img_ptr_arr_ptr->Add(gif_image_ptr); | 818 gif_ptr->img_ptr_arr_ptr->Add(gif_image_ptr); |
| 902 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 819 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
| 903 return 1; | 820 return 1; |
| 904 } | 821 } |
| 905 int32_t _gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { | 822 int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { |
| 906 if (gif_ptr == NULL || frame_num < 0 || | 823 if (gif_ptr == NULL || frame_num < 0 || |
| 907 frame_num >= gif_ptr->img_ptr_arr_ptr->GetSize()) { | 824 frame_num >= gif_ptr->img_ptr_arr_ptr->GetSize()) { |
| 908 return 0; | 825 return 0; |
| 909 } | 826 } |
| 910 uint8_t* data_size_ptr = NULL; | 827 uint8_t* data_size_ptr = NULL; |
| 911 uint8_t* data_ptr = NULL; | 828 uint8_t* data_ptr = NULL; |
| 912 FX_DWORD skip_size_org = gif_ptr->skip_size; | 829 FX_DWORD skip_size_org = gif_ptr->skip_size; |
| 913 GifImage* gif_image_ptr = gif_ptr->img_ptr_arr_ptr->GetAt(frame_num); | 830 GifImage* gif_image_ptr = gif_ptr->img_ptr_arr_ptr->GetAt(frame_num); |
| 914 FX_DWORD gif_img_row_bytes = gif_image_ptr->image_info_ptr->width; | 831 FX_DWORD gif_img_row_bytes = gif_image_ptr->image_info_ptr->width; |
| 915 if (gif_ptr->decode_status == GIF_D_STATUS_TAIL) { | 832 if (gif_ptr->decode_status == GIF_D_STATUS_TAIL) { |
| 916 if (gif_image_ptr->image_row_buf) { | 833 if (gif_image_ptr->image_row_buf) { |
| 917 FX_Free(gif_image_ptr->image_row_buf); | 834 FX_Free(gif_image_ptr->image_row_buf); |
| 918 gif_image_ptr->image_row_buf = NULL; | 835 gif_image_ptr->image_row_buf = NULL; |
| 919 } | 836 } |
| 920 gif_image_ptr->image_row_buf = FX_Alloc(uint8_t, gif_img_row_bytes); | 837 gif_image_ptr->image_row_buf = FX_Alloc(uint8_t, gif_img_row_bytes); |
| 921 GifGCE* gif_img_gce_ptr = gif_image_ptr->image_gce_ptr; | 838 GifGCE* gif_img_gce_ptr = gif_image_ptr->image_gce_ptr; |
| 922 int32_t loc_pal_num = | 839 int32_t loc_pal_num = |
| 923 ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->local_pal | 840 ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->local_pal |
| 924 ? (2 << ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) | 841 ? (2 << ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) |
| 925 ->pal_bits) | 842 ->pal_bits) |
| 926 : 0; | 843 : 0; |
| 927 gif_ptr->avail_in = 0; | 844 gif_ptr->avail_in = 0; |
| 928 if (gif_img_gce_ptr == NULL) { | 845 if (gif_img_gce_ptr == NULL) { |
| 929 FX_BOOL bRes = gif_ptr->_gif_get_record_position_fn( | 846 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( |
| 930 gif_ptr, gif_image_ptr->image_data_pos, | 847 gif_ptr, gif_image_ptr->image_data_pos, |
| 931 gif_image_ptr->image_info_ptr->left, | 848 gif_image_ptr->image_info_ptr->left, |
| 932 gif_image_ptr->image_info_ptr->top, | 849 gif_image_ptr->image_info_ptr->top, |
| 933 gif_image_ptr->image_info_ptr->width, | 850 gif_image_ptr->image_info_ptr->width, |
| 934 gif_image_ptr->image_info_ptr->height, loc_pal_num, | 851 gif_image_ptr->image_info_ptr->height, loc_pal_num, |
| 935 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0, | 852 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0, |
| 936 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) | 853 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) |
| 937 ->interlace); | 854 ->interlace); |
| 938 if (!bRes) { | 855 if (!bRes) { |
| 939 FX_Free(gif_image_ptr->image_row_buf); | 856 FX_Free(gif_image_ptr->image_row_buf); |
| 940 gif_image_ptr->image_row_buf = NULL; | 857 gif_image_ptr->image_row_buf = NULL; |
| 941 _gif_error(gif_ptr, "Error Read Record Position Data"); | 858 gif_error(gif_ptr, "Error Read Record Position Data"); |
| 942 return 0; | 859 return 0; |
| 943 } | 860 } |
| 944 } else { | 861 } else { |
| 945 FX_BOOL bRes = gif_ptr->_gif_get_record_position_fn( | 862 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( |
| 946 gif_ptr, gif_image_ptr->image_data_pos, | 863 gif_ptr, gif_image_ptr->image_data_pos, |
| 947 gif_image_ptr->image_info_ptr->left, | 864 gif_image_ptr->image_info_ptr->left, |
| 948 gif_image_ptr->image_info_ptr->top, | 865 gif_image_ptr->image_info_ptr->top, |
| 949 gif_image_ptr->image_info_ptr->width, | 866 gif_image_ptr->image_info_ptr->width, |
| 950 gif_image_ptr->image_info_ptr->height, loc_pal_num, | 867 gif_image_ptr->image_info_ptr->height, loc_pal_num, |
| 951 gif_image_ptr->local_pal_ptr, | 868 gif_image_ptr->local_pal_ptr, |
| 952 (int32_t)gif_image_ptr->image_gce_ptr->delay_time, | 869 (int32_t)gif_image_ptr->image_gce_ptr->delay_time, |
| 953 (FX_BOOL)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) | 870 (FX_BOOL)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) |
| 954 ->user_input, | 871 ->user_input, |
| 955 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency | 872 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency |
| 956 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index | 873 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index |
| 957 : -1, | 874 : -1, |
| 958 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) | 875 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) |
| 959 ->disposal_method, | 876 ->disposal_method, |
| 960 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) | 877 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) |
| 961 ->interlace); | 878 ->interlace); |
| 962 if (!bRes) { | 879 if (!bRes) { |
| 963 FX_Free(gif_image_ptr->image_row_buf); | 880 FX_Free(gif_image_ptr->image_row_buf); |
| 964 gif_image_ptr->image_row_buf = NULL; | 881 gif_image_ptr->image_row_buf = NULL; |
| 965 _gif_error(gif_ptr, "Error Read Record Position Data"); | 882 gif_error(gif_ptr, "Error Read Record Position Data"); |
| 966 return 0; | 883 return 0; |
| 967 } | 884 } |
| 968 } | 885 } |
| 969 if (gif_ptr->img_decoder_ptr == NULL) { | 886 if (gif_ptr->img_decoder_ptr == NULL) { |
| 970 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr); | 887 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr); |
| 971 } | 888 } |
| 972 gif_ptr->img_decoder_ptr->InitTable(gif_image_ptr->image_code_size); | 889 gif_ptr->img_decoder_ptr->InitTable(gif_image_ptr->image_code_size); |
| 973 gif_ptr->img_row_offset = 0; | 890 gif_ptr->img_row_offset = 0; |
| 974 gif_ptr->img_row_avail_size = 0; | 891 gif_ptr->img_row_avail_size = 0; |
| 975 gif_ptr->img_pass_num = 0; | 892 gif_ptr->img_pass_num = 0; |
| 976 gif_image_ptr->image_row_num = 0; | 893 gif_image_ptr->image_row_num = 0; |
| 977 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 894 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
| 978 } | 895 } |
| 979 CGifLZWDecoder* img_decoder_ptr = gif_ptr->img_decoder_ptr; | 896 CGifLZWDecoder* img_decoder_ptr = gif_ptr->img_decoder_ptr; |
| 980 if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) { | 897 if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) { |
| 981 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 898 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 982 return 2; | 899 return 2; |
| 983 } | 900 } |
| 984 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 901 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
| 985 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { | 902 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { |
| 986 gif_ptr->skip_size = skip_size_org; | 903 gif_ptr->skip_size = skip_size_org; |
| 987 return 2; | 904 return 2; |
| 988 } | 905 } |
| 989 img_decoder_ptr->Input(data_ptr, *data_size_ptr); | 906 img_decoder_ptr->Input(data_ptr, *data_size_ptr); |
| 990 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 907 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
| 991 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; | 908 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; |
| 992 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset; | 909 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset; |
| 993 int32_t ret = img_decoder_ptr->Decode( | 910 int32_t ret = img_decoder_ptr->Decode( |
| 994 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 911 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
| 995 gif_ptr->img_row_avail_size); | 912 gif_ptr->img_row_avail_size); |
| 996 if (ret == 0) { | 913 if (ret == 0) { |
| 997 FX_Free(gif_image_ptr->image_row_buf); | 914 FX_Free(gif_image_ptr->image_row_buf); |
| 998 gif_image_ptr->image_row_buf = NULL; | 915 gif_image_ptr->image_row_buf = NULL; |
| 999 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 916 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 1000 _gif_error(gif_ptr, "Decode Image Data Error"); | 917 gif_error(gif_ptr, "Decode Image Data Error"); |
| 1001 return 0; | 918 return 0; |
| 1002 } | 919 } |
| 1003 while (ret != 0) { | 920 while (ret != 0) { |
| 1004 if (ret == 1) { | 921 if (ret == 1) { |
| 1005 gif_ptr->_gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, | 922 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, |
| 1006 gif_image_ptr->image_row_buf); | 923 gif_image_ptr->image_row_buf); |
| 1007 FX_Free(gif_image_ptr->image_row_buf); | 924 FX_Free(gif_image_ptr->image_row_buf); |
| 1008 gif_image_ptr->image_row_buf = NULL; | 925 gif_image_ptr->image_row_buf = NULL; |
| 1009 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 926 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 1010 return 1; | 927 return 1; |
| 1011 } | 928 } |
| 1012 if (ret == 2) { | 929 if (ret == 2) { |
| 1013 ASSERT(img_decoder_ptr->GetAvailInput() == 0); | 930 ASSERT(img_decoder_ptr->GetAvailInput() == 0); |
| 1014 skip_size_org = gif_ptr->skip_size; | 931 skip_size_org = gif_ptr->skip_size; |
| 1015 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 932 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
| 1016 return 2; | 933 return 2; |
| 1017 } | 934 } |
| 1018 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 935 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
| 1019 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { | 936 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { |
| 1020 gif_ptr->skip_size = skip_size_org; | 937 gif_ptr->skip_size = skip_size_org; |
| 1021 return 2; | 938 return 2; |
| 1022 } | 939 } |
| 1023 img_decoder_ptr->Input(data_ptr, *data_size_ptr); | 940 img_decoder_ptr->Input(data_ptr, *data_size_ptr); |
| 1024 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 941 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
| 1025 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; | 942 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; |
| 1026 gif_ptr->img_row_avail_size = | 943 gif_ptr->img_row_avail_size = |
| 1027 gif_img_row_bytes - gif_ptr->img_row_offset; | 944 gif_img_row_bytes - gif_ptr->img_row_offset; |
| 1028 ret = img_decoder_ptr->Decode( | 945 ret = img_decoder_ptr->Decode( |
| 1029 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 946 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
| 1030 gif_ptr->img_row_avail_size); | 947 gif_ptr->img_row_avail_size); |
| 1031 } | 948 } |
| 1032 } | 949 } |
| 1033 if (ret == 3) { | 950 if (ret == 3) { |
| 1034 if (((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->interlace) { | 951 if (((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->interlace) { |
| 1035 gif_ptr->_gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, | 952 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, |
| 1036 gif_image_ptr->image_row_buf); | 953 gif_image_ptr->image_row_buf); |
| 1037 gif_image_ptr->image_row_num += | 954 gif_image_ptr->image_row_num += |
| 1038 s_gif_interlace_step[gif_ptr->img_pass_num]; | 955 s_gif_interlace_step[gif_ptr->img_pass_num]; |
| 1039 if (gif_image_ptr->image_row_num >= | 956 if (gif_image_ptr->image_row_num >= |
| 1040 (int32_t)gif_image_ptr->image_info_ptr->height) { | 957 (int32_t)gif_image_ptr->image_info_ptr->height) { |
| 1041 gif_ptr->img_pass_num++; | 958 gif_ptr->img_pass_num++; |
| 1042 gif_image_ptr->image_row_num = | 959 gif_image_ptr->image_row_num = |
| 1043 s_gif_interlace_step[gif_ptr->img_pass_num] / 2; | 960 s_gif_interlace_step[gif_ptr->img_pass_num] / 2; |
| 1044 } | 961 } |
| 1045 } else { | 962 } else { |
| 1046 gif_ptr->_gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num++, | 963 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num++, |
| 1047 gif_image_ptr->image_row_buf); | 964 gif_image_ptr->image_row_buf); |
| 1048 } | 965 } |
| 1049 gif_ptr->img_row_offset = 0; | 966 gif_ptr->img_row_offset = 0; |
| 1050 gif_ptr->img_row_avail_size = gif_img_row_bytes; | 967 gif_ptr->img_row_avail_size = gif_img_row_bytes; |
| 1051 ret = img_decoder_ptr->Decode( | 968 ret = img_decoder_ptr->Decode( |
| 1052 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 969 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
| 1053 gif_ptr->img_row_avail_size); | 970 gif_ptr->img_row_avail_size); |
| 1054 } | 971 } |
| 1055 if (ret == 0) { | 972 if (ret == 0) { |
| 1056 FX_Free(gif_image_ptr->image_row_buf); | 973 FX_Free(gif_image_ptr->image_row_buf); |
| 1057 gif_image_ptr->image_row_buf = NULL; | 974 gif_image_ptr->image_row_buf = NULL; |
| 1058 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 975 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 1059 _gif_error(gif_ptr, "Decode Image Data Error"); | 976 gif_error(gif_ptr, "Decode Image Data Error"); |
| 1060 return 0; | 977 return 0; |
| 1061 } | 978 } |
| 1062 } | 979 } |
| 1063 } | 980 } |
| 1064 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 981 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 1065 } | 982 } |
| 1066 _gif_error(gif_ptr, "Decode Image Data Error"); | 983 gif_error(gif_ptr, "Decode Image Data Error"); |
| 1067 return 0; | 984 return 0; |
| 1068 } | 985 } |
| 1069 void _gif_save_decoding_status(gif_decompress_struct_p gif_ptr, | 986 void gif_save_decoding_status(gif_decompress_struct_p gif_ptr, int32_t status) { |
| 1070 int32_t status) { | |
| 1071 gif_ptr->decode_status = status; | 987 gif_ptr->decode_status = status; |
| 1072 gif_ptr->next_in += gif_ptr->skip_size; | 988 gif_ptr->next_in += gif_ptr->skip_size; |
| 1073 gif_ptr->avail_in -= gif_ptr->skip_size; | 989 gif_ptr->avail_in -= gif_ptr->skip_size; |
| 1074 gif_ptr->skip_size = 0; | 990 gif_ptr->skip_size = 0; |
| 1075 } | 991 } |
| 1076 uint8_t* _gif_read_data(gif_decompress_struct_p gif_ptr, | 992 uint8_t* gif_read_data(gif_decompress_struct_p gif_ptr, |
| 1077 uint8_t** des_buf_pp, | 993 uint8_t** des_buf_pp, |
| 1078 FX_DWORD data_size) { | 994 FX_DWORD data_size) { |
| 1079 if (gif_ptr == NULL || gif_ptr->avail_in < gif_ptr->skip_size + data_size) { | 995 if (gif_ptr == NULL || gif_ptr->avail_in < gif_ptr->skip_size + data_size) { |
| 1080 return NULL; | 996 return NULL; |
| 1081 } | 997 } |
| 1082 *des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size; | 998 *des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size; |
| 1083 gif_ptr->skip_size += data_size; | 999 gif_ptr->skip_size += data_size; |
| 1084 return *des_buf_pp; | 1000 return *des_buf_pp; |
| 1085 } | 1001 } |
| 1086 void _gif_input_buffer(gif_decompress_struct_p gif_ptr, | 1002 void gif_input_buffer(gif_decompress_struct_p gif_ptr, |
| 1087 uint8_t* src_buf, | 1003 uint8_t* src_buf, |
| 1088 FX_DWORD src_size) { | 1004 FX_DWORD src_size) { |
| 1089 gif_ptr->next_in = src_buf; | 1005 gif_ptr->next_in = src_buf; |
| 1090 gif_ptr->avail_in = src_size; | 1006 gif_ptr->avail_in = src_size; |
| 1091 gif_ptr->skip_size = 0; | 1007 gif_ptr->skip_size = 0; |
| 1092 } | 1008 } |
| 1093 FX_DWORD _gif_get_avail_input(gif_decompress_struct_p gif_ptr, | 1009 FX_DWORD gif_get_avail_input(gif_decompress_struct_p gif_ptr, |
| 1094 uint8_t** avial_buf_ptr) { | 1010 uint8_t** avial_buf_ptr) { |
| 1095 if (avial_buf_ptr) { | 1011 if (avial_buf_ptr) { |
| 1096 *avial_buf_ptr = NULL; | 1012 *avial_buf_ptr = NULL; |
| 1097 if (gif_ptr->avail_in > 0) { | 1013 if (gif_ptr->avail_in > 0) { |
| 1098 *avial_buf_ptr = gif_ptr->next_in; | 1014 *avial_buf_ptr = gif_ptr->next_in; |
| 1099 } | 1015 } |
| 1100 } | 1016 } |
| 1101 return gif_ptr->avail_in; | 1017 return gif_ptr->avail_in; |
| 1102 } | 1018 } |
| 1103 int32_t _gif_get_frame_num(gif_decompress_struct_p gif_ptr) { | 1019 int32_t gif_get_frame_num(gif_decompress_struct_p gif_ptr) { |
| 1104 return gif_ptr->img_ptr_arr_ptr->GetSize(); | 1020 return gif_ptr->img_ptr_arr_ptr->GetSize(); |
| 1105 } | 1021 } |
| 1106 static FX_BOOL _gif_write_header(gif_compress_struct_p gif_ptr, | 1022 static FX_BOOL gif_write_header(gif_compress_struct_p gif_ptr, |
| 1107 uint8_t*& dst_buf, | 1023 uint8_t*& dst_buf, |
| 1108 FX_DWORD& dst_len) { | 1024 FX_DWORD& dst_len) { |
| 1109 if (gif_ptr->cur_offset) { | 1025 if (gif_ptr->cur_offset) { |
| 1110 return TRUE; | 1026 return TRUE; |
| 1111 } | 1027 } |
| 1112 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF); | 1028 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF); |
| 1113 dst_buf = FX_TryAlloc(uint8_t, dst_len); | 1029 dst_buf = FX_TryAlloc(uint8_t, dst_len); |
| 1114 if (dst_buf == NULL) { | 1030 if (dst_buf == NULL) { |
| 1115 return FALSE; | 1031 return FALSE; |
| 1116 } | 1032 } |
| 1117 FXSYS_memset(dst_buf, 0, dst_len); | 1033 FXSYS_memset(dst_buf, 0, dst_len); |
| 1118 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader)); | 1034 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader)); |
| 1119 gif_ptr->cur_offset += sizeof(GifHeader); | 1035 gif_ptr->cur_offset += sizeof(GifHeader); |
| 1120 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width); | 1036 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width); |
| 1121 gif_ptr->cur_offset += 2; | 1037 gif_ptr->cur_offset += 2; |
| 1122 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height); | 1038 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height); |
| 1123 gif_ptr->cur_offset += 2; | 1039 gif_ptr->cur_offset += 2; |
| 1124 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag; | 1040 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag; |
| 1125 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index; | 1041 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index; |
| 1126 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect; | 1042 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect; |
| 1127 if (gif_ptr->global_pal) { | 1043 if (gif_ptr->global_pal) { |
| 1128 FX_WORD size = sizeof(GifPalette) * gif_ptr->gpal_num; | 1044 FX_WORD size = sizeof(GifPalette) * gif_ptr->gpal_num; |
| 1129 if (!_gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + size)) { | 1045 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + size)) { |
| 1130 return FALSE; | 1046 return FALSE; |
| 1131 } | 1047 } |
| 1132 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->global_pal, size); | 1048 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->global_pal, size); |
| 1133 gif_ptr->cur_offset += size; | 1049 gif_ptr->cur_offset += size; |
| 1134 } | 1050 } |
| 1135 return TRUE; | 1051 return TRUE; |
| 1136 } | 1052 } |
| 1137 void interlace_buf(const uint8_t* buf, FX_DWORD pitch, FX_DWORD height) { | 1053 void interlace_buf(const uint8_t* buf, FX_DWORD pitch, FX_DWORD height) { |
| 1138 CFX_ArrayTemplate<uint8_t*> pass[4]; | 1054 CFX_ArrayTemplate<uint8_t*> pass[4]; |
| 1139 int i, j; | 1055 int i, j; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1158 pass[j].Add(temp); | 1074 pass[j].Add(temp); |
| 1159 row++; | 1075 row++; |
| 1160 } | 1076 } |
| 1161 for (i = 0, row = 0; i < 4; i++) { | 1077 for (i = 0, row = 0; i < 4; i++) { |
| 1162 for (j = 0; j < pass[i].GetSize(); j++, row++) { | 1078 for (j = 0; j < pass[i].GetSize(); j++, row++) { |
| 1163 FXSYS_memcpy((uint8_t*)&buf[pitch * row], pass[i].GetAt(j), pitch); | 1079 FXSYS_memcpy((uint8_t*)&buf[pitch * row], pass[i].GetAt(j), pitch); |
| 1164 FX_Free(pass[i].GetAt(j)); | 1080 FX_Free(pass[i].GetAt(j)); |
| 1165 } | 1081 } |
| 1166 } | 1082 } |
| 1167 } | 1083 } |
| 1168 static void _gif_write_block_data(const uint8_t* src_buf, | 1084 static void gif_write_block_data(const uint8_t* src_buf, |
| 1169 FX_DWORD src_len, | 1085 FX_DWORD src_len, |
| 1170 uint8_t*& dst_buf, | 1086 uint8_t*& dst_buf, |
| 1171 FX_DWORD& dst_len, | 1087 FX_DWORD& dst_len, |
| 1172 FX_DWORD& dst_offset) { | 1088 FX_DWORD& dst_offset) { |
| 1173 FX_DWORD src_offset = 0; | 1089 FX_DWORD src_offset = 0; |
| 1174 while (src_len > GIF_DATA_BLOCK) { | 1090 while (src_len > GIF_DATA_BLOCK) { |
| 1175 dst_buf[dst_offset++] = GIF_DATA_BLOCK; | 1091 dst_buf[dst_offset++] = GIF_DATA_BLOCK; |
| 1176 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], GIF_DATA_BLOCK); | 1092 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], GIF_DATA_BLOCK); |
| 1177 dst_offset += GIF_DATA_BLOCK; | 1093 dst_offset += GIF_DATA_BLOCK; |
| 1178 src_offset += GIF_DATA_BLOCK; | 1094 src_offset += GIF_DATA_BLOCK; |
| 1179 src_len -= GIF_DATA_BLOCK; | 1095 src_len -= GIF_DATA_BLOCK; |
| 1180 } | 1096 } |
| 1181 dst_buf[dst_offset++] = (uint8_t)src_len; | 1097 dst_buf[dst_offset++] = (uint8_t)src_len; |
| 1182 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], src_len); | 1098 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], src_len); |
| 1183 dst_offset += src_len; | 1099 dst_offset += src_len; |
| 1184 } | 1100 } |
| 1185 static FX_BOOL _gif_write_data(gif_compress_struct_p gif_ptr, | 1101 static FX_BOOL gif_write_data(gif_compress_struct_p gif_ptr, |
| 1186 uint8_t*& dst_buf, | 1102 uint8_t*& dst_buf, |
| 1187 FX_DWORD& dst_len) { | 1103 FX_DWORD& dst_len) { |
| 1188 if (!_gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + GIF_DATA_BLOCK)) { | 1104 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + GIF_DATA_BLOCK)) { |
| 1189 return FALSE; | 1105 return FALSE; |
| 1190 } | 1106 } |
| 1191 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION | |
| 1192 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0) { | 1107 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0) { |
| 1193 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; | 1108 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; |
| 1194 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_GCE; | 1109 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_GCE; |
| 1195 gif_ptr->gce_ptr->block_size = 4; | 1110 gif_ptr->gce_ptr->block_size = 4; |
| 1196 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->block_size; | 1111 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->block_size; |
| 1197 gif_ptr->gce_ptr->gce_flag = 0; | 1112 gif_ptr->gce_ptr->gce_flag = 0; |
| 1198 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->gce_flag; | 1113 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->gce_flag; |
| 1199 gif_ptr->gce_ptr->delay_time = 10; | 1114 gif_ptr->gce_ptr->delay_time = 10; |
| 1200 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1115 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1201 gif_ptr->gce_ptr->delay_time); | 1116 gif_ptr->gce_ptr->delay_time); |
| 1202 gif_ptr->cur_offset += 2; | 1117 gif_ptr->cur_offset += 2; |
| 1203 gif_ptr->gce_ptr->trans_index = 0; | 1118 gif_ptr->gce_ptr->trans_index = 0; |
| 1204 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->trans_index; | 1119 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->trans_index; |
| 1205 dst_buf[gif_ptr->cur_offset++] = 0; | 1120 dst_buf[gif_ptr->cur_offset++] = 0; |
| 1206 } | 1121 } |
| 1207 #endif | |
| 1208 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_IMAGE; | 1122 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_IMAGE; |
| 1209 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1123 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1210 gif_ptr->image_info_ptr->left); | 1124 gif_ptr->image_info_ptr->left); |
| 1211 gif_ptr->cur_offset += 2; | 1125 gif_ptr->cur_offset += 2; |
| 1212 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1126 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->image_info_ptr->top); |
| 1213 gif_ptr->image_info_ptr->top); | |
| 1214 gif_ptr->cur_offset += 2; | 1127 gif_ptr->cur_offset += 2; |
| 1215 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1128 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1216 gif_ptr->image_info_ptr->width); | 1129 gif_ptr->image_info_ptr->width); |
| 1217 gif_ptr->cur_offset += 2; | 1130 gif_ptr->cur_offset += 2; |
| 1218 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1131 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1219 gif_ptr->image_info_ptr->height); | 1132 gif_ptr->image_info_ptr->height); |
| 1220 gif_ptr->cur_offset += 2; | 1133 gif_ptr->cur_offset += 2; |
| 1221 GifLF& lf = (GifLF&)gif_ptr->image_info_ptr->local_flag; | 1134 GifLF& lf = (GifLF&)gif_ptr->image_info_ptr->local_flag; |
| 1222 dst_buf[gif_ptr->cur_offset++] = gif_ptr->image_info_ptr->local_flag; | 1135 dst_buf[gif_ptr->cur_offset++] = gif_ptr->image_info_ptr->local_flag; |
| 1223 if (gif_ptr->local_pal) { | 1136 if (gif_ptr->local_pal) { |
| 1224 FX_DWORD pal_size = sizeof(GifPalette) * gif_ptr->lpal_num; | 1137 FX_DWORD pal_size = sizeof(GifPalette) * gif_ptr->lpal_num; |
| 1225 if (!_gif_grow_buf(dst_buf, dst_len, pal_size + gif_ptr->cur_offset)) { | 1138 if (!gif_grow_buf(dst_buf, dst_len, pal_size + gif_ptr->cur_offset)) { |
| 1226 return FALSE; | 1139 return FALSE; |
| 1227 } | 1140 } |
| 1228 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->local_pal, pal_size); | 1141 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->local_pal, pal_size); |
| 1229 gif_ptr->cur_offset += pal_size; | 1142 gif_ptr->cur_offset += pal_size; |
| 1230 } | 1143 } |
| 1231 if (lf.interlace) { | 1144 if (lf.interlace) { |
| 1232 interlace_buf(gif_ptr->src_buf, gif_ptr->src_pitch, | 1145 interlace_buf(gif_ptr->src_buf, gif_ptr->src_pitch, |
| 1233 gif_ptr->image_info_ptr->height); | 1146 gif_ptr->image_info_ptr->height); |
| 1234 } | 1147 } |
| 1235 uint8_t code_bit = lf.pal_bits; | 1148 uint8_t code_bit = lf.pal_bits; |
| 1236 if (lf.local_pal == 0) { | 1149 if (lf.local_pal == 0) { |
| 1237 GifGF& gf = (GifGF&)gif_ptr->lsd_ptr->global_flag; | 1150 GifGF& gf = (GifGF&)gif_ptr->lsd_ptr->global_flag; |
| 1238 code_bit = gf.pal_bits; | 1151 code_bit = gf.pal_bits; |
| 1239 } | 1152 } |
| 1240 gif_ptr->img_encoder_ptr->Start(code_bit, gif_ptr->src_buf, dst_buf, | 1153 gif_ptr->img_encoder_ptr->Start(code_bit, gif_ptr->src_buf, dst_buf, |
| 1241 gif_ptr->cur_offset); | 1154 gif_ptr->cur_offset); |
| 1242 FX_DWORD i; | 1155 FX_DWORD i; |
| 1243 for (i = 0; i < gif_ptr->src_row; i++) { | 1156 for (i = 0; i < gif_ptr->src_row; i++) { |
| 1244 if (!gif_ptr->img_encoder_ptr->Encode( | 1157 if (!gif_ptr->img_encoder_ptr->Encode( |
| 1245 &gif_ptr->src_buf[i * gif_ptr->src_pitch], | 1158 &gif_ptr->src_buf[i * gif_ptr->src_pitch], |
| 1246 gif_ptr->src_width * (code_bit + 1), dst_buf, dst_len, | 1159 gif_ptr->src_width * (code_bit + 1), dst_buf, dst_len, |
| 1247 gif_ptr->cur_offset)) { | 1160 gif_ptr->cur_offset)) { |
| 1248 return FALSE; | 1161 return FALSE; |
| 1249 } | 1162 } |
| 1250 } | 1163 } |
| 1251 gif_ptr->img_encoder_ptr->Finish(dst_buf, dst_len, gif_ptr->cur_offset); | 1164 gif_ptr->img_encoder_ptr->Finish(dst_buf, dst_len, gif_ptr->cur_offset); |
| 1252 dst_buf[gif_ptr->cur_offset++] = 0; | 1165 dst_buf[gif_ptr->cur_offset++] = 0; |
| 1253 #ifdef GIF_SUPPORT_COMMENT_EXTENSION | |
| 1254 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && | 1166 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && |
| 1255 gif_ptr->cmt_data_ptr) { | 1167 gif_ptr->cmt_data_ptr) { |
| 1256 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; | 1168 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; |
| 1257 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_CE; | 1169 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_CE; |
| 1258 _gif_write_block_data(gif_ptr->cmt_data_ptr, gif_ptr->cmt_data_len, dst_buf, | 1170 gif_write_block_data(gif_ptr->cmt_data_ptr, gif_ptr->cmt_data_len, dst_buf, |
| 1259 dst_len, gif_ptr->cur_offset); | 1171 dst_len, gif_ptr->cur_offset); |
| 1260 dst_buf[gif_ptr->cur_offset++] = 0; | 1172 dst_buf[gif_ptr->cur_offset++] = 0; |
| 1261 } | 1173 } |
| 1262 #endif | |
| 1263 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION | |
| 1264 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && | 1174 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && |
| 1265 gif_ptr->pte_data_ptr) { | 1175 gif_ptr->pte_data_ptr) { |
| 1266 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; | 1176 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; |
| 1267 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_PTE; | 1177 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_PTE; |
| 1268 dst_buf[gif_ptr->cur_offset++] = gif_ptr->pte_ptr->block_size; | 1178 dst_buf[gif_ptr->cur_offset++] = gif_ptr->pte_ptr->block_size; |
| 1269 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1179 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1270 gif_ptr->pte_ptr->grid_left); | 1180 gif_ptr->pte_ptr->grid_left); |
| 1271 gif_ptr->cur_offset += 2; | 1181 gif_ptr->cur_offset += 2; |
| 1272 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1182 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->grid_top); |
| 1273 gif_ptr->pte_ptr->grid_top); | |
| 1274 gif_ptr->cur_offset += 2; | 1183 gif_ptr->cur_offset += 2; |
| 1275 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1184 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1276 gif_ptr->pte_ptr->grid_width); | 1185 gif_ptr->pte_ptr->grid_width); |
| 1277 gif_ptr->cur_offset += 2; | 1186 gif_ptr->cur_offset += 2; |
| 1278 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1187 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1279 gif_ptr->pte_ptr->grid_height); | 1188 gif_ptr->pte_ptr->grid_height); |
| 1280 gif_ptr->cur_offset += 2; | 1189 gif_ptr->cur_offset += 2; |
| 1281 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1190 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1282 gif_ptr->pte_ptr->char_width); | 1191 gif_ptr->pte_ptr->char_width); |
| 1283 gif_ptr->cur_offset += 2; | 1192 gif_ptr->cur_offset += 2; |
| 1284 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1193 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, |
| 1285 gif_ptr->pte_ptr->char_height); | 1194 gif_ptr->pte_ptr->char_height); |
| 1286 gif_ptr->cur_offset += 2; | 1195 gif_ptr->cur_offset += 2; |
| 1287 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1196 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->fc_index); |
| 1288 gif_ptr->pte_ptr->fc_index); | |
| 1289 gif_ptr->cur_offset += 2; | 1197 gif_ptr->cur_offset += 2; |
| 1290 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, | 1198 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->bc_index); |
| 1291 gif_ptr->pte_ptr->bc_index); | |
| 1292 gif_ptr->cur_offset += 2; | 1199 gif_ptr->cur_offset += 2; |
| 1293 _gif_write_block_data(gif_ptr->pte_data_ptr, gif_ptr->pte_data_len, dst_buf, | 1200 gif_write_block_data(gif_ptr->pte_data_ptr, gif_ptr->pte_data_len, dst_buf, |
| 1294 dst_len, gif_ptr->cur_offset); | 1201 dst_len, gif_ptr->cur_offset); |
| 1295 gif_ptr->cur_offset += gif_ptr->pte_data_len; | 1202 gif_ptr->cur_offset += gif_ptr->pte_data_len; |
| 1296 dst_buf[gif_ptr->cur_offset++] = 0; | 1203 dst_buf[gif_ptr->cur_offset++] = 0; |
| 1297 } | 1204 } |
| 1298 #endif | |
| 1299 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION | |
| 1300 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && | |
| 1301 gif_ptr->app_data) { | |
| 1302 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; | |
| 1303 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_AE; | |
| 1304 dst_buf[gif_ptr->cur_offset++] = 11; | |
| 1305 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_identify, 8); | |
| 1306 gif_ptr->cur_offset += 8; | |
| 1307 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_authentication, 8); | |
| 1308 gif_ptr->cur_offset += 3; | |
| 1309 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_data, | |
| 1310 gif_ptr->app_data_size); | |
| 1311 gif_ptr->cur_offset += gif_ptr->app_data_size; | |
| 1312 dst_buf[gif_ptr->cur_offset++] = 0; | |
| 1313 } | |
| 1314 #endif | |
| 1315 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_TRAILER; | 1205 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_TRAILER; |
| 1316 return TRUE; | 1206 return TRUE; |
| 1317 } | 1207 } |
| 1318 FX_BOOL _gif_encode(gif_compress_struct_p gif_ptr, | 1208 FX_BOOL gif_encode(gif_compress_struct_p gif_ptr, |
| 1319 uint8_t*& dst_buf, | 1209 uint8_t*& dst_buf, |
| 1320 FX_DWORD& dst_len) { | 1210 FX_DWORD& dst_len) { |
| 1321 if (!_gif_write_header(gif_ptr, dst_buf, dst_len)) { | 1211 if (!gif_write_header(gif_ptr, dst_buf, dst_len)) { |
| 1322 return FALSE; | 1212 return FALSE; |
| 1323 } | 1213 } |
| 1324 FX_DWORD cur_offset = gif_ptr->cur_offset; | 1214 FX_DWORD cur_offset = gif_ptr->cur_offset; |
| 1325 FX_BOOL res = TRUE; | 1215 FX_BOOL res = TRUE; |
| 1326 if (gif_ptr->frames) { | 1216 if (gif_ptr->frames) { |
| 1327 gif_ptr->cur_offset--; | 1217 gif_ptr->cur_offset--; |
| 1328 } | 1218 } |
| 1329 if (!_gif_write_data(gif_ptr, dst_buf, dst_len)) { | 1219 if (!gif_write_data(gif_ptr, dst_buf, dst_len)) { |
| 1330 gif_ptr->cur_offset = cur_offset; | 1220 gif_ptr->cur_offset = cur_offset; |
| 1331 res = FALSE; | 1221 res = FALSE; |
| 1332 } | 1222 } |
| 1333 dst_len = gif_ptr->cur_offset; | 1223 dst_len = gif_ptr->cur_offset; |
| 1334 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; | 1224 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; |
| 1335 if (res) { | 1225 if (res) { |
| 1336 gif_ptr->frames++; | 1226 gif_ptr->frames++; |
| 1337 } | 1227 } |
| 1338 return res; | 1228 return res; |
| 1339 } | 1229 } |
| OLD | NEW |