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/fxcodec/lgif/fx_gif.h" | 7 #include "core/fxcodec/lgif/fx_gif.h" |
8 | 8 |
9 #include "core/fxcodec/lbmp/fx_bmp.h" | 9 #include "core/fxcodec/lbmp/fx_bmp.h" |
10 | 10 |
11 void CGifLZWDecoder::Input(uint8_t* src_buf, uint32_t src_size) { | 11 void CGifLZWDecoder::Input(uint8_t* src_buf, uint32_t src_size) { |
12 next_in = src_buf; | 12 next_in = src_buf; |
13 avail_in = src_size; | 13 avail_in = src_size; |
14 } | 14 } |
15 uint32_t CGifLZWDecoder::GetAvailInput() { | 15 uint32_t CGifLZWDecoder::GetAvailInput() { |
16 return avail_in; | 16 return avail_in; |
17 } | 17 } |
18 void CGifLZWDecoder::InitTable(uint8_t code_len) { | 18 void CGifLZWDecoder::InitTable(uint8_t code_len) { |
19 code_size = code_len; | 19 code_size = code_len; |
20 code_clear = 1 << code_size; | 20 code_clear = 1 << code_size; |
21 code_end = code_clear + 1; | 21 code_end = code_clear + 1; |
22 bits_left = 0; | 22 bits_left = 0; |
23 code_store = 0; | 23 code_store = 0; |
24 next_in = NULL; | 24 next_in = nullptr; |
25 avail_in = 0; | 25 avail_in = 0; |
26 stack_size = 0; | 26 stack_size = 0; |
27 code_first = 0; | 27 code_first = 0; |
28 ClearTable(); | 28 ClearTable(); |
29 } | 29 } |
30 void CGifLZWDecoder::ClearTable() { | 30 void CGifLZWDecoder::ClearTable() { |
31 code_size_cur = code_size + 1; | 31 code_size_cur = code_size + 1; |
32 code_next = code_end + 1; | 32 code_next = code_end + 1; |
33 code_old = (uint16_t)-1; | 33 code_old = (uint16_t)-1; |
34 FXSYS_memset(code_table, 0, sizeof(tag_Table) * GIF_MAX_LZW_CODE); | 34 FXSYS_memset(code_table, 0, sizeof(tag_Table) * GIF_MAX_LZW_CODE); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 146 } |
147 static FX_BOOL gif_grow_buf(uint8_t*& dst_buf, | 147 static FX_BOOL gif_grow_buf(uint8_t*& dst_buf, |
148 uint32_t& dst_len, | 148 uint32_t& dst_len, |
149 uint32_t size) { | 149 uint32_t size) { |
150 if (dst_len < size) { | 150 if (dst_len < size) { |
151 uint32_t len_org = dst_len; | 151 uint32_t len_org = dst_len; |
152 while (dst_buf && dst_len < size) { | 152 while (dst_buf && dst_len < size) { |
153 dst_len <<= 1; | 153 dst_len <<= 1; |
154 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); | 154 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); |
155 } | 155 } |
156 if (dst_buf == NULL) { | 156 if (!dst_buf) { |
157 dst_len = size; | 157 dst_len = size; |
158 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); | 158 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); |
159 if (dst_buf == NULL) { | |
160 return FALSE; | |
161 } | |
162 } | 159 } |
163 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org); | 160 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org); |
164 return dst_buf != NULL; | 161 return !!dst_buf; |
165 } | 162 } |
166 return TRUE; | 163 return TRUE; |
167 } | 164 } |
168 static inline void gif_cut_index(uint8_t& val, | 165 static inline void gif_cut_index(uint8_t& val, |
169 uint32_t index, | 166 uint32_t index, |
170 uint8_t index_bit, | 167 uint8_t index_bit, |
171 uint8_t index_bit_use, | 168 uint8_t index_bit_use, |
172 uint8_t bit_use) { | 169 uint8_t bit_use) { |
173 uint32_t cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use; | 170 uint32_t cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use; |
174 val |= ((index & cut) >> index_bit_use) << bit_use; | 171 val |= ((index & cut) >> index_bit_use) << bit_use; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 uint32_t& dst_len, | 349 uint32_t& dst_len, |
353 uint32_t& offset) { | 350 uint32_t& offset) { |
354 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); | 351 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); |
355 EncodeString(code_end, dst_buf, dst_len, offset); | 352 EncodeString(code_end, dst_buf, dst_len, offset); |
356 bit_offset = 0; | 353 bit_offset = 0; |
357 ClearTable(); | 354 ClearTable(); |
358 } | 355 } |
359 gif_decompress_struct_p gif_create_decompress() { | 356 gif_decompress_struct_p gif_create_decompress() { |
360 gif_decompress_struct_p gif_ptr = | 357 gif_decompress_struct_p gif_ptr = |
361 (gif_decompress_struct*)FX_Alloc(uint8_t, sizeof(gif_decompress_struct)); | 358 (gif_decompress_struct*)FX_Alloc(uint8_t, sizeof(gif_decompress_struct)); |
362 if (gif_ptr == NULL) { | 359 if (!gif_ptr) |
363 return NULL; | 360 return nullptr; |
364 } | 361 |
365 FXSYS_memset(gif_ptr, 0, sizeof(gif_decompress_struct)); | 362 FXSYS_memset(gif_ptr, 0, sizeof(gif_decompress_struct)); |
366 gif_ptr->decode_status = GIF_D_STATUS_SIG; | 363 gif_ptr->decode_status = GIF_D_STATUS_SIG; |
367 gif_ptr->img_ptr_arr_ptr = new CFX_ArrayTemplate<GifImage*>; | 364 gif_ptr->img_ptr_arr_ptr = new CFX_ArrayTemplate<GifImage*>; |
368 gif_ptr->cmt_data_ptr = new CFX_ByteString; | 365 gif_ptr->cmt_data_ptr = new CFX_ByteString; |
369 gif_ptr->pt_ptr_arr_ptr = new CFX_ArrayTemplate<GifPlainText*>; | 366 gif_ptr->pt_ptr_arr_ptr = new CFX_ArrayTemplate<GifPlainText*>; |
370 return gif_ptr; | 367 return gif_ptr; |
371 } | 368 } |
372 void gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) { | 369 void gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) { |
373 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { | 370 if (!gif_ptr_ptr || !*gif_ptr_ptr) |
374 return; | 371 return; |
375 } | 372 |
376 gif_decompress_struct_p gif_ptr = *gif_ptr_ptr; | 373 gif_decompress_struct_p gif_ptr = *gif_ptr_ptr; |
377 *gif_ptr_ptr = NULL; | 374 *gif_ptr_ptr = nullptr; |
378 FX_Free(gif_ptr->global_pal_ptr); | 375 FX_Free(gif_ptr->global_pal_ptr); |
379 delete gif_ptr->img_decoder_ptr; | 376 delete gif_ptr->img_decoder_ptr; |
380 if (gif_ptr->img_ptr_arr_ptr) { | 377 if (gif_ptr->img_ptr_arr_ptr) { |
381 int32_t size_img_arr = gif_ptr->img_ptr_arr_ptr->GetSize(); | 378 int32_t size_img_arr = gif_ptr->img_ptr_arr_ptr->GetSize(); |
382 for (int32_t i = 0; i < size_img_arr; i++) { | 379 for (int32_t i = 0; i < size_img_arr; i++) { |
383 GifImage* p = gif_ptr->img_ptr_arr_ptr->GetAt(i); | 380 GifImage* p = gif_ptr->img_ptr_arr_ptr->GetAt(i); |
384 FX_Free(p->image_info_ptr); | 381 FX_Free(p->image_info_ptr); |
385 FX_Free(p->image_gce_ptr); | 382 FX_Free(p->image_gce_ptr); |
386 FX_Free(p->image_row_buf); | 383 FX_Free(p->image_row_buf); |
387 if (p->local_pal_ptr && p->local_pal_ptr != gif_ptr->global_pal_ptr) { | 384 if (p->local_pal_ptr && p->local_pal_ptr != gif_ptr->global_pal_ptr) { |
(...skipping 15 matching lines...) Expand all Loading... | |
403 delete p->string_ptr; | 400 delete p->string_ptr; |
404 } | 401 } |
405 gif_ptr->pt_ptr_arr_ptr->RemoveAll(); | 402 gif_ptr->pt_ptr_arr_ptr->RemoveAll(); |
406 delete gif_ptr->pt_ptr_arr_ptr; | 403 delete gif_ptr->pt_ptr_arr_ptr; |
407 } | 404 } |
408 FX_Free(gif_ptr); | 405 FX_Free(gif_ptr); |
409 } | 406 } |
410 gif_compress_struct_p gif_create_compress() { | 407 gif_compress_struct_p gif_create_compress() { |
411 gif_compress_struct_p gif_ptr = | 408 gif_compress_struct_p gif_ptr = |
412 (gif_compress_struct*)FX_Alloc(uint8_t, sizeof(gif_compress_struct)); | 409 (gif_compress_struct*)FX_Alloc(uint8_t, sizeof(gif_compress_struct)); |
413 if (gif_ptr == NULL) { | 410 if (!gif_ptr) |
414 return NULL; | 411 return nullptr; |
415 } | 412 |
416 FXSYS_memset(gif_ptr, 0, sizeof(gif_compress_struct)); | 413 FXSYS_memset(gif_ptr, 0, sizeof(gif_compress_struct)); |
417 gif_ptr->img_encoder_ptr = new CGifLZWEncoder; | 414 gif_ptr->img_encoder_ptr = new CGifLZWEncoder; |
418 gif_ptr->header_ptr = (GifHeader*)FX_Alloc(uint8_t, sizeof(GifHeader)); | 415 gif_ptr->header_ptr = (GifHeader*)FX_Alloc(uint8_t, sizeof(GifHeader)); |
419 if (gif_ptr->header_ptr == NULL) { | 416 if (!gif_ptr->header_ptr) { |
420 delete (gif_ptr->img_encoder_ptr); | 417 delete (gif_ptr->img_encoder_ptr); |
421 FX_Free(gif_ptr); | 418 FX_Free(gif_ptr); |
422 return NULL; | 419 return nullptr; |
423 } | 420 } |
424 FXSYS_memcpy(gif_ptr->header_ptr->signature, GIF_SIGNATURE, 3); | 421 FXSYS_memcpy(gif_ptr->header_ptr->signature, GIF_SIGNATURE, 3); |
425 FXSYS_memcpy(gif_ptr->header_ptr->version, "89a", 3); | 422 FXSYS_memcpy(gif_ptr->header_ptr->version, "89a", 3); |
426 gif_ptr->lsd_ptr = (GifLSD*)FX_Alloc(uint8_t, sizeof(GifLSD)); | 423 gif_ptr->lsd_ptr = (GifLSD*)FX_Alloc(uint8_t, sizeof(GifLSD)); |
427 if (gif_ptr->lsd_ptr == NULL) { | 424 if (!gif_ptr->lsd_ptr) { |
428 FX_Free(gif_ptr->header_ptr); | 425 FX_Free(gif_ptr->header_ptr); |
429 delete (gif_ptr->img_encoder_ptr); | 426 delete (gif_ptr->img_encoder_ptr); |
430 FX_Free(gif_ptr); | 427 FX_Free(gif_ptr); |
431 return NULL; | 428 return nullptr; |
432 } | 429 } |
433 FXSYS_memset(gif_ptr->lsd_ptr, 0, sizeof(GifLSD)); | 430 FXSYS_memset(gif_ptr->lsd_ptr, 0, sizeof(GifLSD)); |
434 gif_ptr->image_info_ptr = | 431 gif_ptr->image_info_ptr = |
435 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); | 432 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); |
436 if (gif_ptr->image_info_ptr == NULL) { | 433 if (!gif_ptr->image_info_ptr) { |
437 FX_Free(gif_ptr->lsd_ptr); | 434 FX_Free(gif_ptr->lsd_ptr); |
438 FX_Free(gif_ptr->header_ptr); | 435 FX_Free(gif_ptr->header_ptr); |
439 delete (gif_ptr->img_encoder_ptr); | 436 delete (gif_ptr->img_encoder_ptr); |
440 FX_Free(gif_ptr); | 437 FX_Free(gif_ptr); |
441 return NULL; | 438 return nullptr; |
442 } | 439 } |
443 FXSYS_memset(gif_ptr->image_info_ptr, 0, sizeof(GifImageInfo)); | 440 FXSYS_memset(gif_ptr->image_info_ptr, 0, sizeof(GifImageInfo)); |
444 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); | 441 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); |
445 if (gif_ptr->gce_ptr == NULL) { | 442 if (!gif_ptr->gce_ptr) { |
446 FX_Free(gif_ptr->image_info_ptr); | 443 FX_Free(gif_ptr->image_info_ptr); |
447 FX_Free(gif_ptr->lsd_ptr); | 444 FX_Free(gif_ptr->lsd_ptr); |
448 FX_Free(gif_ptr->header_ptr); | 445 FX_Free(gif_ptr->header_ptr); |
449 delete (gif_ptr->img_encoder_ptr); | 446 delete (gif_ptr->img_encoder_ptr); |
450 FX_Free(gif_ptr); | 447 FX_Free(gif_ptr); |
451 return NULL; | 448 return nullptr; |
452 } | 449 } |
453 gif_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); | 450 gif_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); |
454 if (gif_ptr->pte_ptr == NULL) { | 451 if (!gif_ptr->pte_ptr) { |
455 FX_Free(gif_ptr->gce_ptr); | 452 FX_Free(gif_ptr->gce_ptr); |
456 FX_Free(gif_ptr->image_info_ptr); | 453 FX_Free(gif_ptr->image_info_ptr); |
457 FX_Free(gif_ptr->lsd_ptr); | 454 FX_Free(gif_ptr->lsd_ptr); |
458 FX_Free(gif_ptr->header_ptr); | 455 FX_Free(gif_ptr->header_ptr); |
459 delete (gif_ptr->img_encoder_ptr); | 456 delete (gif_ptr->img_encoder_ptr); |
460 FX_Free(gif_ptr); | 457 FX_Free(gif_ptr); |
461 return NULL; | 458 return nullptr; |
462 } | 459 } |
463 FXSYS_memset(gif_ptr->pte_ptr, 0, sizeof(GifPTE)); | 460 FXSYS_memset(gif_ptr->pte_ptr, 0, sizeof(GifPTE)); |
464 gif_ptr->pte_ptr->block_size = 12; | 461 gif_ptr->pte_ptr->block_size = 12; |
465 return gif_ptr; | 462 return gif_ptr; |
466 } | 463 } |
467 void gif_destroy_compress(gif_compress_struct_pp gif_ptr_ptr) { | 464 void gif_destroy_compress(gif_compress_struct_pp gif_ptr_ptr) { |
468 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { | 465 if (!gif_ptr_ptr || !*gif_ptr_ptr) |
469 return; | 466 return; |
470 } | 467 |
471 gif_compress_struct_p gif_ptr = *gif_ptr_ptr; | 468 gif_compress_struct_p gif_ptr = *gif_ptr_ptr; |
472 *gif_ptr_ptr = NULL; | 469 *gif_ptr_ptr = nullptr; |
473 FX_Free(gif_ptr->header_ptr); | 470 FX_Free(gif_ptr->header_ptr); |
474 FX_Free(gif_ptr->lsd_ptr); | 471 FX_Free(gif_ptr->lsd_ptr); |
475 FX_Free(gif_ptr->global_pal); | 472 FX_Free(gif_ptr->global_pal); |
476 FX_Free(gif_ptr->image_info_ptr); | 473 FX_Free(gif_ptr->image_info_ptr); |
477 FX_Free(gif_ptr->local_pal); | 474 FX_Free(gif_ptr->local_pal); |
478 delete gif_ptr->img_encoder_ptr; | 475 delete gif_ptr->img_encoder_ptr; |
479 FX_Free(gif_ptr->gce_ptr); | 476 FX_Free(gif_ptr->gce_ptr); |
480 FX_Free(gif_ptr->cmt_data_ptr); | 477 FX_Free(gif_ptr->cmt_data_ptr); |
481 FX_Free(gif_ptr->pte_ptr); | 478 FX_Free(gif_ptr->pte_ptr); |
482 FX_Free(gif_ptr); | 479 FX_Free(gif_ptr); |
483 } | 480 } |
484 void gif_error(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) { | 481 void gif_error(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) { |
485 if (gif_ptr && gif_ptr->gif_error_fn) { | 482 if (gif_ptr && gif_ptr->gif_error_fn) { |
486 gif_ptr->gif_error_fn(gif_ptr, err_msg); | 483 gif_ptr->gif_error_fn(gif_ptr, err_msg); |
487 } | 484 } |
488 } | 485 } |
489 void gif_warn(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {} | 486 void gif_warn(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {} |
490 int32_t gif_read_header(gif_decompress_struct_p gif_ptr) { | 487 int32_t gif_read_header(gif_decompress_struct_p gif_ptr) { |
491 if (gif_ptr == NULL) { | 488 if (!gif_ptr) |
492 return 0; | 489 return 0; |
493 } | 490 |
494 uint32_t skip_size_org = gif_ptr->skip_size; | 491 uint32_t skip_size_org = gif_ptr->skip_size; |
495 ASSERT(sizeof(GifHeader) == 6); | 492 ASSERT(sizeof(GifHeader) == 6); |
496 GifHeader* gif_header_ptr = NULL; | 493 GifHeader* gif_header_ptr = nullptr; |
497 if (gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6) == NULL) { | 494 if (!gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6)) |
498 return 2; | 495 return 2; |
499 } | 496 |
500 if (FXSYS_strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 || | 497 if (FXSYS_strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 || |
501 gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') { | 498 gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') { |
502 gif_error(gif_ptr, "Not A Gif Image"); | 499 gif_error(gif_ptr, "Not A Gif Image"); |
503 return 0; | 500 return 0; |
504 } | 501 } |
505 ASSERT(sizeof(GifLSD) == 7); | 502 ASSERT(sizeof(GifLSD) == 7); |
506 GifLSD* gif_lsd_ptr = NULL; | 503 GifLSD* gif_lsd_ptr = nullptr; |
507 if (gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7) == NULL) { | 504 if (!gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7)) { |
508 gif_ptr->skip_size = skip_size_org; | 505 gif_ptr->skip_size = skip_size_org; |
509 return 2; | 506 return 2; |
510 } | 507 } |
511 if (((GifGF*)&gif_lsd_ptr->global_flag)->global_pal) { | 508 if (((GifGF*)&gif_lsd_ptr->global_flag)->global_pal) { |
512 gif_ptr->global_pal_num = 2 | 509 gif_ptr->global_pal_num = 2 |
513 << ((GifGF*)&gif_lsd_ptr->global_flag)->pal_bits; | 510 << ((GifGF*)&gif_lsd_ptr->global_flag)->pal_bits; |
514 ASSERT(sizeof(GifPalette) == 3); | 511 ASSERT(sizeof(GifPalette) == 3); |
515 int32_t global_pal_size = gif_ptr->global_pal_num * 3; | 512 int32_t global_pal_size = gif_ptr->global_pal_num * 3; |
516 uint8_t* global_pal_ptr = NULL; | 513 uint8_t* global_pal_ptr = nullptr; |
517 if (gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size) == NULL) { | 514 if (!gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size)) { |
518 gif_ptr->skip_size = skip_size_org; | 515 gif_ptr->skip_size = skip_size_org; |
519 return 2; | 516 return 2; |
520 } | 517 } |
521 gif_ptr->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag; | 518 gif_ptr->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag; |
522 gif_ptr->global_color_resolution = | 519 gif_ptr->global_color_resolution = |
523 ((GifGF*)&gif_lsd_ptr->global_flag)->color_resolution; | 520 ((GifGF*)&gif_lsd_ptr->global_flag)->color_resolution; |
524 FX_Free(gif_ptr->global_pal_ptr); | 521 FX_Free(gif_ptr->global_pal_ptr); |
525 gif_ptr->global_pal_ptr = (GifPalette*)FX_Alloc(uint8_t, global_pal_size); | 522 gif_ptr->global_pal_ptr = (GifPalette*)FX_Alloc(uint8_t, global_pal_size); |
526 FXSYS_memcpy(gif_ptr->global_pal_ptr, global_pal_ptr, global_pal_size); | 523 FXSYS_memcpy(gif_ptr->global_pal_ptr, global_pal_ptr, global_pal_size); |
527 } | 524 } |
528 gif_ptr->width = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->width); | 525 gif_ptr->width = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->width); |
529 gif_ptr->height = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height); | 526 gif_ptr->height = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height); |
530 gif_ptr->bc_index = gif_lsd_ptr->bc_index; | 527 gif_ptr->bc_index = gif_lsd_ptr->bc_index; |
531 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect; | 528 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect; |
532 return 1; | 529 return 1; |
533 } | 530 } |
534 int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { | 531 int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { |
535 if (gif_ptr == NULL) { | 532 if (!gif_ptr) |
536 return 0; | 533 return 0; |
537 } | 534 |
538 int32_t ret = 1; | 535 int32_t ret = 1; |
539 while (TRUE) { | 536 while (TRUE) { |
540 switch (gif_ptr->decode_status) { | 537 switch (gif_ptr->decode_status) { |
541 case GIF_D_STATUS_TAIL: | 538 case GIF_D_STATUS_TAIL: |
542 return 1; | 539 return 1; |
543 case GIF_D_STATUS_SIG: { | 540 case GIF_D_STATUS_SIG: { |
544 uint8_t* sig_ptr = NULL; | 541 uint8_t* sig_ptr = nullptr; |
545 if (gif_read_data(gif_ptr, &sig_ptr, 1) == NULL) { | 542 if (!gif_read_data(gif_ptr, &sig_ptr, 1)) |
546 return 2; | 543 return 2; |
547 } | 544 |
548 switch (*sig_ptr) { | 545 switch (*sig_ptr) { |
549 case GIF_SIG_EXTENSION: | 546 case GIF_SIG_EXTENSION: |
550 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT); | 547 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT); |
551 continue; | 548 continue; |
552 case GIF_SIG_IMAGE: | 549 case GIF_SIG_IMAGE: |
553 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_INFO); | 550 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_INFO); |
554 continue; | 551 continue; |
555 case GIF_SIG_TRAILER: | 552 case GIF_SIG_TRAILER: |
556 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 553 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
557 return 1; | 554 return 1; |
558 default: | 555 default: |
559 if (gif_ptr->avail_in) { | 556 if (gif_ptr->avail_in) { |
560 gif_warn(gif_ptr, "The Gif File has non_standard Tag!"); | 557 gif_warn(gif_ptr, "The Gif File has non_standard Tag!"); |
561 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); | 558 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); |
562 continue; | 559 continue; |
563 } | 560 } |
564 gif_warn(gif_ptr, "The Gif File Doesn't have Trailer Tag!"); | 561 gif_warn(gif_ptr, "The Gif File Doesn't have Trailer Tag!"); |
565 return 1; | 562 return 1; |
566 } | 563 } |
567 } | 564 } |
568 case GIF_D_STATUS_EXT: { | 565 case GIF_D_STATUS_EXT: { |
569 uint8_t* ext_ptr = NULL; | 566 uint8_t* ext_ptr = nullptr; |
570 if (gif_read_data(gif_ptr, &ext_ptr, 1) == NULL) { | 567 if (!gif_read_data(gif_ptr, &ext_ptr, 1)) |
571 return 2; | 568 return 2; |
572 } | 569 |
573 switch (*ext_ptr) { | 570 switch (*ext_ptr) { |
574 case GIF_BLOCK_CE: | 571 case GIF_BLOCK_CE: |
575 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE); | 572 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE); |
576 continue; | 573 continue; |
577 case GIF_BLOCK_GCE: | 574 case GIF_BLOCK_GCE: |
578 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_GCE); | 575 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_GCE); |
579 continue; | 576 continue; |
580 case GIF_BLOCK_PTE: | 577 case GIF_BLOCK_PTE: |
581 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_PTE); | 578 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_PTE); |
582 continue; | 579 continue; |
583 default: { | 580 default: { |
584 int32_t status = GIF_D_STATUS_EXT_UNE; | 581 int32_t status = GIF_D_STATUS_EXT_UNE; |
585 if (*ext_ptr == GIF_BLOCK_PTE) { | 582 if (*ext_ptr == GIF_BLOCK_PTE) { |
586 status = GIF_D_STATUS_EXT_PTE; | 583 status = GIF_D_STATUS_EXT_PTE; |
587 } | 584 } |
588 gif_save_decoding_status(gif_ptr, status); | 585 gif_save_decoding_status(gif_ptr, status); |
589 continue; | 586 continue; |
590 } | 587 } |
591 } | 588 } |
592 } | 589 } |
593 case GIF_D_STATUS_IMG_INFO: { | 590 case GIF_D_STATUS_IMG_INFO: { |
594 ret = gif_decode_image_info(gif_ptr); | 591 ret = gif_decode_image_info(gif_ptr); |
595 if (ret != 1) { | 592 if (ret != 1) { |
596 return ret; | 593 return ret; |
597 } | 594 } |
598 continue; | 595 continue; |
599 } | 596 } |
600 case GIF_D_STATUS_IMG_DATA: { | 597 case GIF_D_STATUS_IMG_DATA: { |
601 uint8_t* data_size_ptr = NULL; | 598 uint8_t* data_size_ptr = nullptr; |
602 uint8_t* data_ptr = NULL; | 599 uint8_t* data_ptr = nullptr; |
603 uint32_t skip_size_org = gif_ptr->skip_size; | 600 uint32_t skip_size_org = gif_ptr->skip_size; |
604 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 601 if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
605 return 2; | 602 return 2; |
606 } | 603 |
607 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 604 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
608 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { | 605 if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) { |
609 gif_ptr->skip_size = skip_size_org; | 606 gif_ptr->skip_size = skip_size_org; |
610 return 2; | 607 return 2; |
611 } | 608 } |
612 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 609 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
613 skip_size_org = gif_ptr->skip_size; | 610 skip_size_org = gif_ptr->skip_size; |
614 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 611 if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
615 return 2; | 612 return 2; |
616 } | |
617 } | 613 } |
618 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); | 614 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); |
619 continue; | 615 continue; |
620 } | 616 } |
621 default: { | 617 default: { |
622 ret = gif_decode_extension(gif_ptr); | 618 ret = gif_decode_extension(gif_ptr); |
623 if (ret != 1) { | 619 if (ret != 1) { |
624 return ret; | 620 return ret; |
625 } | 621 } |
626 continue; | 622 continue; |
627 } | 623 } |
628 } | 624 } |
629 } | 625 } |
630 return 1; | 626 return 1; |
631 } | 627 } |
632 void gif_takeover_gce_ptr(gif_decompress_struct_p gif_ptr, | 628 void gif_takeover_gce_ptr(gif_decompress_struct_p gif_ptr, |
633 GifGCE** gce_ptr_ptr) { | 629 GifGCE** gce_ptr_ptr) { |
634 *gce_ptr_ptr = NULL; | 630 *gce_ptr_ptr = nullptr; |
635 if (gif_ptr->gce_ptr && gce_ptr_ptr) { | 631 if (gif_ptr->gce_ptr && gce_ptr_ptr) { |
636 *gce_ptr_ptr = gif_ptr->gce_ptr; | 632 *gce_ptr_ptr = gif_ptr->gce_ptr; |
637 gif_ptr->gce_ptr = NULL; | 633 gif_ptr->gce_ptr = nullptr; |
638 } | 634 } |
639 } | 635 } |
640 int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { | 636 int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
641 uint8_t* data_size_ptr = NULL; | 637 uint8_t* data_size_ptr = nullptr; |
642 uint8_t* data_ptr = NULL; | 638 uint8_t* data_ptr = nullptr; |
643 uint32_t skip_size_org = gif_ptr->skip_size; | 639 uint32_t skip_size_org = gif_ptr->skip_size; |
644 switch (gif_ptr->decode_status) { | 640 switch (gif_ptr->decode_status) { |
645 case GIF_D_STATUS_EXT_CE: { | 641 case GIF_D_STATUS_EXT_CE: { |
646 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 642 if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
647 gif_ptr->skip_size = skip_size_org; | 643 gif_ptr->skip_size = skip_size_org; |
648 return 2; | 644 return 2; |
649 } | 645 } |
650 gif_ptr->cmt_data_ptr->clear(); | 646 gif_ptr->cmt_data_ptr->clear(); |
651 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 647 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
652 uint8_t data_size = *data_size_ptr; | 648 uint8_t data_size = *data_size_ptr; |
653 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || | 649 if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) || |
654 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 650 !gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
655 gif_ptr->skip_size = skip_size_org; | 651 gif_ptr->skip_size = skip_size_org; |
656 return 2; | 652 return 2; |
657 } | 653 } |
658 *(gif_ptr->cmt_data_ptr) += | 654 *(gif_ptr->cmt_data_ptr) += |
659 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); | 655 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); |
660 } | 656 } |
661 } break; | 657 } break; |
662 case GIF_D_STATUS_EXT_PTE: { | 658 case GIF_D_STATUS_EXT_PTE: { |
663 ASSERT(sizeof(GifPTE) == 13); | 659 ASSERT(sizeof(GifPTE) == 13); |
664 GifPTE* gif_pte_ptr = NULL; | 660 GifPTE* gif_pte_ptr = nullptr; |
665 if (gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13) == NULL) { | 661 if (!gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13)) { |
666 return 2; | 662 return 2; |
667 } | 663 } |
668 GifPlainText* gif_pt_ptr = FX_Alloc(GifPlainText, 1); | 664 GifPlainText* gif_pt_ptr = FX_Alloc(GifPlainText, 1); |
669 FXSYS_memset(gif_pt_ptr, 0, sizeof(GifPlainText)); | 665 FXSYS_memset(gif_pt_ptr, 0, sizeof(GifPlainText)); |
670 gif_takeover_gce_ptr(gif_ptr, &gif_pt_ptr->gce_ptr); | 666 gif_takeover_gce_ptr(gif_ptr, &gif_pt_ptr->gce_ptr); |
671 gif_pt_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); | 667 gif_pt_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); |
672 gif_pt_ptr->string_ptr = new CFX_ByteString; | 668 gif_pt_ptr->string_ptr = new CFX_ByteString; |
673 gif_pt_ptr->pte_ptr->block_size = gif_pte_ptr->block_size; | 669 gif_pt_ptr->pte_ptr->block_size = gif_pte_ptr->block_size; |
674 gif_pt_ptr->pte_ptr->grid_left = | 670 gif_pt_ptr->pte_ptr->grid_left = |
675 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_left); | 671 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_left); |
676 gif_pt_ptr->pte_ptr->grid_top = | 672 gif_pt_ptr->pte_ptr->grid_top = |
677 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_top); | 673 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_top); |
678 gif_pt_ptr->pte_ptr->grid_width = | 674 gif_pt_ptr->pte_ptr->grid_width = |
679 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_width); | 675 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_width); |
680 gif_pt_ptr->pte_ptr->grid_height = | 676 gif_pt_ptr->pte_ptr->grid_height = |
681 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_height); | 677 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_height); |
682 gif_pt_ptr->pte_ptr->char_width = gif_pte_ptr->char_width; | 678 gif_pt_ptr->pte_ptr->char_width = gif_pte_ptr->char_width; |
683 gif_pt_ptr->pte_ptr->char_height = gif_pte_ptr->char_height; | 679 gif_pt_ptr->pte_ptr->char_height = gif_pte_ptr->char_height; |
684 gif_pt_ptr->pte_ptr->fc_index = gif_pte_ptr->fc_index; | 680 gif_pt_ptr->pte_ptr->fc_index = gif_pte_ptr->fc_index; |
685 gif_pt_ptr->pte_ptr->bc_index = gif_pte_ptr->bc_index; | 681 gif_pt_ptr->pte_ptr->bc_index = gif_pte_ptr->bc_index; |
686 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 682 if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
687 gif_ptr->skip_size = skip_size_org; | 683 gif_ptr->skip_size = skip_size_org; |
688 if (gif_pt_ptr) { | 684 if (gif_pt_ptr) { |
689 FX_Free(gif_pt_ptr->gce_ptr); | 685 FX_Free(gif_pt_ptr->gce_ptr); |
690 FX_Free(gif_pt_ptr->pte_ptr); | 686 FX_Free(gif_pt_ptr->pte_ptr); |
691 delete gif_pt_ptr->string_ptr; | 687 delete gif_pt_ptr->string_ptr; |
692 FX_Free(gif_pt_ptr); | 688 FX_Free(gif_pt_ptr); |
693 } | 689 } |
694 return 2; | 690 return 2; |
695 } | 691 } |
696 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 692 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
697 uint8_t data_size = *data_size_ptr; | 693 uint8_t data_size = *data_size_ptr; |
698 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || | 694 if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) || |
699 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 695 !gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
700 gif_ptr->skip_size = skip_size_org; | 696 gif_ptr->skip_size = skip_size_org; |
701 if (gif_pt_ptr) { | 697 if (gif_pt_ptr) { |
702 FX_Free(gif_pt_ptr->gce_ptr); | 698 FX_Free(gif_pt_ptr->gce_ptr); |
703 FX_Free(gif_pt_ptr->pte_ptr); | 699 FX_Free(gif_pt_ptr->pte_ptr); |
704 delete gif_pt_ptr->string_ptr; | 700 delete gif_pt_ptr->string_ptr; |
705 FX_Free(gif_pt_ptr); | 701 FX_Free(gif_pt_ptr); |
706 } | 702 } |
707 return 2; | 703 return 2; |
708 } | 704 } |
709 *(gif_pt_ptr->string_ptr) += | 705 *(gif_pt_ptr->string_ptr) += |
710 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); | 706 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); |
711 } | 707 } |
712 gif_ptr->pt_ptr_arr_ptr->Add(gif_pt_ptr); | 708 gif_ptr->pt_ptr_arr_ptr->Add(gif_pt_ptr); |
713 } break; | 709 } break; |
714 case GIF_D_STATUS_EXT_GCE: { | 710 case GIF_D_STATUS_EXT_GCE: { |
715 ASSERT(sizeof(GifGCE) == 5); | 711 ASSERT(sizeof(GifGCE) == 5); |
716 GifGCE* gif_gce_ptr = NULL; | 712 GifGCE* gif_gce_ptr = nullptr; |
717 if (gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6) == NULL) { | 713 if (!gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6)) |
718 return 2; | 714 return 2; |
719 } | 715 |
720 if (gif_ptr->gce_ptr == NULL) { | 716 if (!gif_ptr->gce_ptr) |
721 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); | 717 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); |
722 } | |
723 gif_ptr->gce_ptr->block_size = gif_gce_ptr->block_size; | 718 gif_ptr->gce_ptr->block_size = gif_gce_ptr->block_size; |
724 gif_ptr->gce_ptr->gce_flag = gif_gce_ptr->gce_flag; | 719 gif_ptr->gce_ptr->gce_flag = gif_gce_ptr->gce_flag; |
725 gif_ptr->gce_ptr->delay_time = | 720 gif_ptr->gce_ptr->delay_time = |
726 GetWord_LSBFirst((uint8_t*)&gif_gce_ptr->delay_time); | 721 GetWord_LSBFirst((uint8_t*)&gif_gce_ptr->delay_time); |
727 gif_ptr->gce_ptr->trans_index = gif_gce_ptr->trans_index; | 722 gif_ptr->gce_ptr->trans_index = gif_gce_ptr->trans_index; |
728 } break; | 723 } break; |
729 default: { | 724 default: { |
730 if (gif_ptr->decode_status == GIF_D_STATUS_EXT_PTE) { | 725 if (gif_ptr->decode_status == GIF_D_STATUS_EXT_PTE) { |
731 FX_Free(gif_ptr->gce_ptr); | 726 FX_Free(gif_ptr->gce_ptr); |
732 gif_ptr->gce_ptr = NULL; | 727 gif_ptr->gce_ptr = nullptr; |
733 } | 728 } |
734 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 729 if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
735 return 2; | 730 return 2; |
736 } | 731 |
737 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 732 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
738 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || | 733 if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) || |
739 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 734 !gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
740 gif_ptr->skip_size = skip_size_org; | 735 gif_ptr->skip_size = skip_size_org; |
741 return 2; | 736 return 2; |
742 } | 737 } |
743 } | 738 } |
744 } | 739 } |
745 } | 740 } |
746 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); | 741 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); |
747 return 1; | 742 return 1; |
748 } | 743 } |
749 int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) { | 744 int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) { |
750 if (gif_ptr->width == 0 || gif_ptr->height == 0) { | 745 if (gif_ptr->width == 0 || gif_ptr->height == 0) { |
751 gif_error(gif_ptr, "No Image Header Info"); | 746 gif_error(gif_ptr, "No Image Header Info"); |
752 return 0; | 747 return 0; |
753 } | 748 } |
754 uint32_t skip_size_org = gif_ptr->skip_size; | 749 uint32_t skip_size_org = gif_ptr->skip_size; |
755 ASSERT(sizeof(GifImageInfo) == 9); | 750 ASSERT(sizeof(GifImageInfo) == 9); |
756 GifImageInfo* gif_img_info_ptr = NULL; | 751 GifImageInfo* gif_img_info_ptr = nullptr; |
757 if (gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9) == NULL) { | 752 if (!gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9)) |
758 return 2; | 753 return 2; |
759 } | 754 |
760 GifImage* gif_image_ptr = (GifImage*)FX_Alloc(uint8_t, sizeof(GifImage)); | 755 GifImage* gif_image_ptr = (GifImage*)FX_Alloc(uint8_t, sizeof(GifImage)); |
761 FXSYS_memset(gif_image_ptr, 0, sizeof(GifImage)); | 756 FXSYS_memset(gif_image_ptr, 0, sizeof(GifImage)); |
762 gif_image_ptr->image_info_ptr = | 757 gif_image_ptr->image_info_ptr = |
763 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); | 758 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); |
764 gif_image_ptr->image_info_ptr->left = | 759 gif_image_ptr->image_info_ptr->left = |
765 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->left); | 760 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->left); |
766 gif_image_ptr->image_info_ptr->top = | 761 gif_image_ptr->image_info_ptr->top = |
767 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->top); | 762 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->top); |
768 gif_image_ptr->image_info_ptr->width = | 763 gif_image_ptr->image_info_ptr->width = |
769 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->width); | 764 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->width); |
770 gif_image_ptr->image_info_ptr->height = | 765 gif_image_ptr->image_info_ptr->height = |
771 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->height); | 766 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->height); |
772 gif_image_ptr->image_info_ptr->local_flag = gif_img_info_ptr->local_flag; | 767 gif_image_ptr->image_info_ptr->local_flag = gif_img_info_ptr->local_flag; |
773 if (gif_image_ptr->image_info_ptr->left + | 768 if (gif_image_ptr->image_info_ptr->left + |
774 gif_image_ptr->image_info_ptr->width > | 769 gif_image_ptr->image_info_ptr->width > |
775 gif_ptr->width || | 770 gif_ptr->width || |
776 gif_image_ptr->image_info_ptr->top + | 771 gif_image_ptr->image_info_ptr->top + |
777 gif_image_ptr->image_info_ptr->height > | 772 gif_image_ptr->image_info_ptr->height > |
778 gif_ptr->height) { | 773 gif_ptr->height) { |
779 FX_Free(gif_image_ptr->image_info_ptr); | 774 FX_Free(gif_image_ptr->image_info_ptr); |
780 FX_Free(gif_image_ptr->image_row_buf); | 775 FX_Free(gif_image_ptr->image_row_buf); |
781 FX_Free(gif_image_ptr); | 776 FX_Free(gif_image_ptr); |
782 gif_error(gif_ptr, "Image Data Out Of LSD, The File May Be Corrupt"); | 777 gif_error(gif_ptr, "Image Data Out Of LSD, The File May Be Corrupt"); |
783 return 0; | 778 return 0; |
784 } | 779 } |
785 GifLF* gif_img_info_lf_ptr = (GifLF*)&gif_img_info_ptr->local_flag; | 780 GifLF* gif_img_info_lf_ptr = (GifLF*)&gif_img_info_ptr->local_flag; |
786 if (gif_img_info_lf_ptr->local_pal) { | 781 if (gif_img_info_lf_ptr->local_pal) { |
787 ASSERT(sizeof(GifPalette) == 3); | 782 ASSERT(sizeof(GifPalette) == 3); |
788 int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3; | 783 int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3; |
789 uint8_t* loc_pal_ptr = NULL; | 784 uint8_t* loc_pal_ptr = nullptr; |
790 if (gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size) == NULL) { | 785 if (!gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size)) { |
791 gif_ptr->skip_size = skip_size_org; | 786 gif_ptr->skip_size = skip_size_org; |
792 FX_Free(gif_image_ptr->image_info_ptr); | 787 FX_Free(gif_image_ptr->image_info_ptr); |
793 FX_Free(gif_image_ptr->image_row_buf); | 788 FX_Free(gif_image_ptr->image_row_buf); |
794 FX_Free(gif_image_ptr); | 789 FX_Free(gif_image_ptr); |
795 return 2; | 790 return 2; |
796 } | 791 } |
797 gif_image_ptr->local_pal_ptr = | 792 gif_image_ptr->local_pal_ptr = |
798 (GifPalette*)gif_ptr->gif_ask_buf_for_pal_fn(gif_ptr, loc_pal_size); | 793 (GifPalette*)gif_ptr->gif_ask_buf_for_pal_fn(gif_ptr, loc_pal_size); |
799 if (gif_image_ptr->local_pal_ptr) { | 794 if (gif_image_ptr->local_pal_ptr) { |
800 FXSYS_memcpy((uint8_t*)gif_image_ptr->local_pal_ptr, loc_pal_ptr, | 795 FXSYS_memcpy((uint8_t*)gif_image_ptr->local_pal_ptr, loc_pal_ptr, |
801 loc_pal_size); | 796 loc_pal_size); |
802 } | 797 } |
803 } | 798 } |
804 uint8_t* code_size_ptr = NULL; | 799 uint8_t* code_size_ptr = nullptr; |
805 if (gif_read_data(gif_ptr, &code_size_ptr, 1) == NULL) { | 800 if (!gif_read_data(gif_ptr, &code_size_ptr, 1)) { |
806 gif_ptr->skip_size = skip_size_org; | 801 gif_ptr->skip_size = skip_size_org; |
807 FX_Free(gif_image_ptr->image_info_ptr); | 802 FX_Free(gif_image_ptr->image_info_ptr); |
808 FX_Free(gif_image_ptr->local_pal_ptr); | 803 FX_Free(gif_image_ptr->local_pal_ptr); |
809 FX_Free(gif_image_ptr->image_row_buf); | 804 FX_Free(gif_image_ptr->image_row_buf); |
810 FX_Free(gif_image_ptr); | 805 FX_Free(gif_image_ptr); |
811 return 2; | 806 return 2; |
812 } | 807 } |
813 gif_image_ptr->image_code_size = *code_size_ptr; | 808 gif_image_ptr->image_code_size = *code_size_ptr; |
814 gif_ptr->gif_record_current_position_fn(gif_ptr, | 809 gif_ptr->gif_record_current_position_fn(gif_ptr, |
815 &gif_image_ptr->image_data_pos); | 810 &gif_image_ptr->image_data_pos); |
816 gif_image_ptr->image_data_pos += gif_ptr->skip_size; | 811 gif_image_ptr->image_data_pos += gif_ptr->skip_size; |
817 gif_takeover_gce_ptr(gif_ptr, &gif_image_ptr->image_gce_ptr); | 812 gif_takeover_gce_ptr(gif_ptr, &gif_image_ptr->image_gce_ptr); |
818 gif_ptr->img_ptr_arr_ptr->Add(gif_image_ptr); | 813 gif_ptr->img_ptr_arr_ptr->Add(gif_image_ptr); |
819 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 814 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
820 return 1; | 815 return 1; |
821 } | 816 } |
822 int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { | 817 int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { |
823 if (gif_ptr == NULL || frame_num < 0 || | 818 if (!gif_ptr || frame_num < 0 || |
824 frame_num >= gif_ptr->img_ptr_arr_ptr->GetSize()) { | 819 frame_num >= gif_ptr->img_ptr_arr_ptr->GetSize()) { |
825 return 0; | 820 return 0; |
826 } | 821 } |
827 uint8_t* data_size_ptr = NULL; | 822 uint8_t* data_size_ptr = nullptr; |
828 uint8_t* data_ptr = NULL; | 823 uint8_t* data_ptr = nullptr; |
829 uint32_t skip_size_org = gif_ptr->skip_size; | 824 uint32_t skip_size_org = gif_ptr->skip_size; |
830 GifImage* gif_image_ptr = gif_ptr->img_ptr_arr_ptr->GetAt(frame_num); | 825 GifImage* gif_image_ptr = gif_ptr->img_ptr_arr_ptr->GetAt(frame_num); |
831 uint32_t gif_img_row_bytes = gif_image_ptr->image_info_ptr->width; | 826 uint32_t gif_img_row_bytes = gif_image_ptr->image_info_ptr->width; |
832 if (gif_ptr->decode_status == GIF_D_STATUS_TAIL) { | 827 if (gif_ptr->decode_status == GIF_D_STATUS_TAIL) { |
833 if (gif_image_ptr->image_row_buf) { | 828 if (gif_image_ptr->image_row_buf) { |
834 FX_Free(gif_image_ptr->image_row_buf); | 829 FX_Free(gif_image_ptr->image_row_buf); |
835 gif_image_ptr->image_row_buf = NULL; | 830 gif_image_ptr->image_row_buf = nullptr; |
836 } | 831 } |
837 gif_image_ptr->image_row_buf = FX_Alloc(uint8_t, gif_img_row_bytes); | 832 gif_image_ptr->image_row_buf = FX_Alloc(uint8_t, gif_img_row_bytes); |
838 GifGCE* gif_img_gce_ptr = gif_image_ptr->image_gce_ptr; | 833 GifGCE* gif_img_gce_ptr = gif_image_ptr->image_gce_ptr; |
839 int32_t loc_pal_num = | 834 int32_t loc_pal_num = |
840 ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->local_pal | 835 ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->local_pal |
841 ? (2 << ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) | 836 ? (2 << ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) |
842 ->pal_bits) | 837 ->pal_bits) |
843 : 0; | 838 : 0; |
844 gif_ptr->avail_in = 0; | 839 gif_ptr->avail_in = 0; |
845 if (gif_img_gce_ptr == NULL) { | 840 if (!gif_img_gce_ptr) { |
846 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( | 841 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( |
847 gif_ptr, gif_image_ptr->image_data_pos, | 842 gif_ptr, gif_image_ptr->image_data_pos, |
848 gif_image_ptr->image_info_ptr->left, | 843 gif_image_ptr->image_info_ptr->left, |
849 gif_image_ptr->image_info_ptr->top, | 844 gif_image_ptr->image_info_ptr->top, |
850 gif_image_ptr->image_info_ptr->width, | 845 gif_image_ptr->image_info_ptr->width, |
851 gif_image_ptr->image_info_ptr->height, loc_pal_num, | 846 gif_image_ptr->image_info_ptr->height, loc_pal_num, |
852 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0, | 847 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0, |
853 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) | 848 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) |
854 ->interlace); | 849 ->interlace); |
855 if (!bRes) { | 850 if (!bRes) { |
856 FX_Free(gif_image_ptr->image_row_buf); | 851 FX_Free(gif_image_ptr->image_row_buf); |
857 gif_image_ptr->image_row_buf = NULL; | 852 gif_image_ptr->image_row_buf = nullptr; |
858 gif_error(gif_ptr, "Error Read Record Position Data"); | 853 gif_error(gif_ptr, "Error Read Record Position Data"); |
859 return 0; | 854 return 0; |
860 } | 855 } |
861 } else { | 856 } else { |
862 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( | 857 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( |
863 gif_ptr, gif_image_ptr->image_data_pos, | 858 gif_ptr, gif_image_ptr->image_data_pos, |
864 gif_image_ptr->image_info_ptr->left, | 859 gif_image_ptr->image_info_ptr->left, |
865 gif_image_ptr->image_info_ptr->top, | 860 gif_image_ptr->image_info_ptr->top, |
866 gif_image_ptr->image_info_ptr->width, | 861 gif_image_ptr->image_info_ptr->width, |
867 gif_image_ptr->image_info_ptr->height, loc_pal_num, | 862 gif_image_ptr->image_info_ptr->height, loc_pal_num, |
868 gif_image_ptr->local_pal_ptr, | 863 gif_image_ptr->local_pal_ptr, |
869 (int32_t)gif_image_ptr->image_gce_ptr->delay_time, | 864 (int32_t)gif_image_ptr->image_gce_ptr->delay_time, |
870 (FX_BOOL)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) | 865 (FX_BOOL)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) |
871 ->user_input, | 866 ->user_input, |
872 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency | 867 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency |
873 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index | 868 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index |
874 : -1, | 869 : -1, |
875 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) | 870 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) |
876 ->disposal_method, | 871 ->disposal_method, |
877 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) | 872 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) |
878 ->interlace); | 873 ->interlace); |
879 if (!bRes) { | 874 if (!bRes) { |
880 FX_Free(gif_image_ptr->image_row_buf); | 875 FX_Free(gif_image_ptr->image_row_buf); |
881 gif_image_ptr->image_row_buf = NULL; | 876 gif_image_ptr->image_row_buf = nullptr; |
882 gif_error(gif_ptr, "Error Read Record Position Data"); | 877 gif_error(gif_ptr, "Error Read Record Position Data"); |
883 return 0; | 878 return 0; |
884 } | 879 } |
885 } | 880 } |
886 if (gif_ptr->img_decoder_ptr == NULL) { | 881 if (!gif_ptr->img_decoder_ptr) |
887 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr); | 882 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr); |
888 } | |
889 gif_ptr->img_decoder_ptr->InitTable(gif_image_ptr->image_code_size); | 883 gif_ptr->img_decoder_ptr->InitTable(gif_image_ptr->image_code_size); |
890 gif_ptr->img_row_offset = 0; | 884 gif_ptr->img_row_offset = 0; |
891 gif_ptr->img_row_avail_size = 0; | 885 gif_ptr->img_row_avail_size = 0; |
892 gif_ptr->img_pass_num = 0; | 886 gif_ptr->img_pass_num = 0; |
893 gif_image_ptr->image_row_num = 0; | 887 gif_image_ptr->image_row_num = 0; |
894 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 888 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
895 } | 889 } |
896 CGifLZWDecoder* img_decoder_ptr = gif_ptr->img_decoder_ptr; | 890 CGifLZWDecoder* img_decoder_ptr = gif_ptr->img_decoder_ptr; |
897 if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) { | 891 if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) { |
898 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 892 if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
899 return 2; | 893 return 2; |
900 } | 894 |
901 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 895 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
902 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { | 896 if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) { |
903 gif_ptr->skip_size = skip_size_org; | 897 gif_ptr->skip_size = skip_size_org; |
904 return 2; | 898 return 2; |
905 } | 899 } |
906 img_decoder_ptr->Input(data_ptr, *data_size_ptr); | 900 img_decoder_ptr->Input(data_ptr, *data_size_ptr); |
907 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 901 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
908 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; | 902 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; |
909 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset; | 903 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset; |
910 int32_t ret = img_decoder_ptr->Decode( | 904 int32_t ret = img_decoder_ptr->Decode( |
911 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 905 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
912 gif_ptr->img_row_avail_size); | 906 gif_ptr->img_row_avail_size); |
913 if (ret == 0) { | 907 if (ret == 0) { |
914 FX_Free(gif_image_ptr->image_row_buf); | 908 FX_Free(gif_image_ptr->image_row_buf); |
915 gif_image_ptr->image_row_buf = NULL; | 909 gif_image_ptr->image_row_buf = nullptr; |
916 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 910 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
917 gif_error(gif_ptr, "Decode Image Data Error"); | 911 gif_error(gif_ptr, "Decode Image Data Error"); |
918 return 0; | 912 return 0; |
919 } | 913 } |
920 while (ret != 0) { | 914 while (ret != 0) { |
921 if (ret == 1) { | 915 if (ret == 1) { |
922 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, | 916 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, |
923 gif_image_ptr->image_row_buf); | 917 gif_image_ptr->image_row_buf); |
924 FX_Free(gif_image_ptr->image_row_buf); | 918 FX_Free(gif_image_ptr->image_row_buf); |
925 gif_image_ptr->image_row_buf = NULL; | 919 gif_image_ptr->image_row_buf = nullptr; |
926 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 920 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
927 return 1; | 921 return 1; |
928 } | 922 } |
929 if (ret == 2) { | 923 if (ret == 2) { |
930 ASSERT(img_decoder_ptr->GetAvailInput() == 0); | 924 ASSERT(img_decoder_ptr->GetAvailInput() == 0); |
931 skip_size_org = gif_ptr->skip_size; | 925 skip_size_org = gif_ptr->skip_size; |
932 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { | 926 if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
933 return 2; | 927 return 2; |
934 } | 928 |
935 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { | 929 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
936 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { | 930 if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) { |
937 gif_ptr->skip_size = skip_size_org; | 931 gif_ptr->skip_size = skip_size_org; |
938 return 2; | 932 return 2; |
939 } | 933 } |
940 img_decoder_ptr->Input(data_ptr, *data_size_ptr); | 934 img_decoder_ptr->Input(data_ptr, *data_size_ptr); |
941 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 935 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
942 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; | 936 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; |
943 gif_ptr->img_row_avail_size = | 937 gif_ptr->img_row_avail_size = |
944 gif_img_row_bytes - gif_ptr->img_row_offset; | 938 gif_img_row_bytes - gif_ptr->img_row_offset; |
945 ret = img_decoder_ptr->Decode( | 939 ret = img_decoder_ptr->Decode( |
946 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 940 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
(...skipping 17 matching lines...) Expand all Loading... | |
964 gif_image_ptr->image_row_buf); | 958 gif_image_ptr->image_row_buf); |
965 } | 959 } |
966 gif_ptr->img_row_offset = 0; | 960 gif_ptr->img_row_offset = 0; |
967 gif_ptr->img_row_avail_size = gif_img_row_bytes; | 961 gif_ptr->img_row_avail_size = gif_img_row_bytes; |
968 ret = img_decoder_ptr->Decode( | 962 ret = img_decoder_ptr->Decode( |
969 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 963 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
970 gif_ptr->img_row_avail_size); | 964 gif_ptr->img_row_avail_size); |
971 } | 965 } |
972 if (ret == 0) { | 966 if (ret == 0) { |
973 FX_Free(gif_image_ptr->image_row_buf); | 967 FX_Free(gif_image_ptr->image_row_buf); |
974 gif_image_ptr->image_row_buf = NULL; | 968 gif_image_ptr->image_row_buf = nullptr; |
975 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 969 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
976 gif_error(gif_ptr, "Decode Image Data Error"); | 970 gif_error(gif_ptr, "Decode Image Data Error"); |
977 return 0; | 971 return 0; |
978 } | 972 } |
979 } | 973 } |
980 } | 974 } |
981 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 975 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
982 } | 976 } |
983 gif_error(gif_ptr, "Decode Image Data Error"); | 977 gif_error(gif_ptr, "Decode Image Data Error"); |
984 return 0; | 978 return 0; |
985 } | 979 } |
986 void gif_save_decoding_status(gif_decompress_struct_p gif_ptr, int32_t status) { | 980 void gif_save_decoding_status(gif_decompress_struct_p gif_ptr, int32_t status) { |
987 gif_ptr->decode_status = status; | 981 gif_ptr->decode_status = status; |
988 gif_ptr->next_in += gif_ptr->skip_size; | 982 gif_ptr->next_in += gif_ptr->skip_size; |
989 gif_ptr->avail_in -= gif_ptr->skip_size; | 983 gif_ptr->avail_in -= gif_ptr->skip_size; |
990 gif_ptr->skip_size = 0; | 984 gif_ptr->skip_size = 0; |
991 } | 985 } |
992 uint8_t* gif_read_data(gif_decompress_struct_p gif_ptr, | 986 uint8_t* gif_read_data(gif_decompress_struct_p gif_ptr, |
993 uint8_t** des_buf_pp, | 987 uint8_t** des_buf_pp, |
994 uint32_t data_size) { | 988 uint32_t data_size) { |
995 if (gif_ptr == NULL || gif_ptr->avail_in < gif_ptr->skip_size + data_size) { | 989 if (!gif_ptr || gif_ptr->avail_in < gif_ptr->skip_size + data_size) |
996 return NULL; | 990 return nullptr; |
997 } | 991 |
998 *des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size; | 992 *des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size; |
999 gif_ptr->skip_size += data_size; | 993 gif_ptr->skip_size += data_size; |
1000 return *des_buf_pp; | 994 return *des_buf_pp; |
1001 } | 995 } |
1002 void gif_input_buffer(gif_decompress_struct_p gif_ptr, | 996 void gif_input_buffer(gif_decompress_struct_p gif_ptr, |
1003 uint8_t* src_buf, | 997 uint8_t* src_buf, |
1004 uint32_t src_size) { | 998 uint32_t src_size) { |
1005 gif_ptr->next_in = src_buf; | 999 gif_ptr->next_in = src_buf; |
1006 gif_ptr->avail_in = src_size; | 1000 gif_ptr->avail_in = src_size; |
1007 gif_ptr->skip_size = 0; | 1001 gif_ptr->skip_size = 0; |
1008 } | 1002 } |
1009 uint32_t gif_get_avail_input(gif_decompress_struct_p gif_ptr, | 1003 uint32_t gif_get_avail_input(gif_decompress_struct_p gif_ptr, |
1010 uint8_t** avial_buf_ptr) { | 1004 uint8_t** avial_buf_ptr) { |
1011 if (avial_buf_ptr) { | 1005 if (avial_buf_ptr) { |
Tom Sepez
2016/06/02 20:09:49
nit: sp. avial vs avail
Lei Zhang
2016/06/07 07:33:23
Done.
| |
1012 *avial_buf_ptr = NULL; | 1006 *avial_buf_ptr = nullptr; |
1013 if (gif_ptr->avail_in > 0) { | 1007 if (gif_ptr->avail_in > 0) { |
1014 *avial_buf_ptr = gif_ptr->next_in; | 1008 *avial_buf_ptr = gif_ptr->next_in; |
1015 } | 1009 } |
1016 } | 1010 } |
1017 return gif_ptr->avail_in; | 1011 return gif_ptr->avail_in; |
1018 } | 1012 } |
1019 int32_t gif_get_frame_num(gif_decompress_struct_p gif_ptr) { | 1013 int32_t gif_get_frame_num(gif_decompress_struct_p gif_ptr) { |
1020 return gif_ptr->img_ptr_arr_ptr->GetSize(); | 1014 return gif_ptr->img_ptr_arr_ptr->GetSize(); |
1021 } | 1015 } |
1022 static FX_BOOL gif_write_header(gif_compress_struct_p gif_ptr, | 1016 static FX_BOOL gif_write_header(gif_compress_struct_p gif_ptr, |
1023 uint8_t*& dst_buf, | 1017 uint8_t*& dst_buf, |
1024 uint32_t& dst_len) { | 1018 uint32_t& dst_len) { |
1025 if (gif_ptr->cur_offset) { | 1019 if (gif_ptr->cur_offset) { |
1026 return TRUE; | 1020 return TRUE; |
1027 } | 1021 } |
1028 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF); | 1022 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF); |
1029 dst_buf = FX_TryAlloc(uint8_t, dst_len); | 1023 dst_buf = FX_TryAlloc(uint8_t, dst_len); |
1030 if (dst_buf == NULL) { | 1024 if (!dst_buf) |
1031 return FALSE; | 1025 return FALSE; |
1032 } | 1026 |
1033 FXSYS_memset(dst_buf, 0, dst_len); | 1027 FXSYS_memset(dst_buf, 0, dst_len); |
1034 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader)); | 1028 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader)); |
1035 gif_ptr->cur_offset += sizeof(GifHeader); | 1029 gif_ptr->cur_offset += sizeof(GifHeader); |
1036 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width); | 1030 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width); |
1037 gif_ptr->cur_offset += 2; | 1031 gif_ptr->cur_offset += 2; |
1038 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height); | 1032 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height); |
1039 gif_ptr->cur_offset += 2; | 1033 gif_ptr->cur_offset += 2; |
1040 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag; | 1034 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag; |
1041 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index; | 1035 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index; |
1042 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect; | 1036 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect; |
(...skipping 17 matching lines...) Expand all Loading... | |
1060 if (row % 8 == 0) { | 1054 if (row % 8 == 0) { |
1061 j = 0; | 1055 j = 0; |
1062 } else if (row % 4 == 0) { | 1056 } else if (row % 4 == 0) { |
1063 j = 1; | 1057 j = 1; |
1064 } else if (row % 2 == 0) { | 1058 } else if (row % 2 == 0) { |
1065 j = 2; | 1059 j = 2; |
1066 } else { | 1060 } else { |
1067 j = 3; | 1061 j = 3; |
1068 } | 1062 } |
1069 temp = FX_Alloc(uint8_t, pitch); | 1063 temp = FX_Alloc(uint8_t, pitch); |
1070 if (temp == NULL) { | |
1071 return; | |
1072 } | |
1073 FXSYS_memcpy(temp, &buf[pitch * row], pitch); | 1064 FXSYS_memcpy(temp, &buf[pitch * row], pitch); |
1074 pass[j].Add(temp); | 1065 pass[j].Add(temp); |
1075 row++; | 1066 row++; |
1076 } | 1067 } |
1077 for (i = 0, row = 0; i < 4; i++) { | 1068 for (i = 0, row = 0; i < 4; i++) { |
1078 for (j = 0; j < pass[i].GetSize(); j++, row++) { | 1069 for (j = 0; j < pass[i].GetSize(); j++, row++) { |
1079 FXSYS_memcpy((uint8_t*)&buf[pitch * row], pass[i].GetAt(j), pitch); | 1070 FXSYS_memcpy((uint8_t*)&buf[pitch * row], pass[i].GetAt(j), pitch); |
1080 FX_Free(pass[i].GetAt(j)); | 1071 FX_Free(pass[i].GetAt(j)); |
1081 } | 1072 } |
1082 } | 1073 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1220 gif_ptr->cur_offset = cur_offset; | 1211 gif_ptr->cur_offset = cur_offset; |
1221 res = FALSE; | 1212 res = FALSE; |
1222 } | 1213 } |
1223 dst_len = gif_ptr->cur_offset; | 1214 dst_len = gif_ptr->cur_offset; |
1224 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; | 1215 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; |
1225 if (res) { | 1216 if (res) { |
1226 gif_ptr->frames++; | 1217 gif_ptr->frames++; |
1227 } | 1218 } |
1228 return res; | 1219 return res; |
1229 } | 1220 } |
OLD | NEW |