| 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 |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 return 2; | 918 return 2; |
| 919 } | 919 } |
| 920 img_decoder_ptr->Input(data_ptr, *data_size_ptr); | 920 img_decoder_ptr->Input(data_ptr, *data_size_ptr); |
| 921 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); | 921 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
| 922 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; | 922 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; |
| 923 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset; | 923 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset; |
| 924 int32_t ret = img_decoder_ptr->Decode( | 924 int32_t ret = img_decoder_ptr->Decode( |
| 925 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 925 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
| 926 gif_ptr->img_row_avail_size); | 926 gif_ptr->img_row_avail_size); |
| 927 if (ret == 0) { | 927 if (ret == 0) { |
| 928 FX_Free(gif_image_ptr->image_row_buf); | 928 gif_decoding_failure_at_tail_cleanup(gif_ptr, gif_image_ptr); |
| 929 gif_image_ptr->image_row_buf = nullptr; | |
| 930 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | |
| 931 gif_error(gif_ptr, "Decode Image Data Error"); | |
| 932 return 0; | 929 return 0; |
| 933 } | 930 } |
| 934 while (ret != 0) { | 931 while (ret != 0) { |
| 935 if (ret == 1) { | 932 if (ret == 1) { |
| 936 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, | 933 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, |
| 937 gif_image_ptr->image_row_buf); | 934 gif_image_ptr->image_row_buf); |
| 938 FX_Free(gif_image_ptr->image_row_buf); | 935 FX_Free(gif_image_ptr->image_row_buf); |
| 939 gif_image_ptr->image_row_buf = nullptr; | 936 gif_image_ptr->image_row_buf = nullptr; |
| 940 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 937 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 941 return 1; | 938 return 1; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 963 } | 960 } |
| 964 if (ret == 3) { | 961 if (ret == 3) { |
| 965 if (((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->interlace) { | 962 if (((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->interlace) { |
| 966 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, |
| 967 gif_image_ptr->image_row_buf); | 964 gif_image_ptr->image_row_buf); |
| 968 gif_image_ptr->image_row_num += | 965 gif_image_ptr->image_row_num += |
| 969 s_gif_interlace_step[gif_ptr->img_pass_num]; | 966 s_gif_interlace_step[gif_ptr->img_pass_num]; |
| 970 if (gif_image_ptr->image_row_num >= | 967 if (gif_image_ptr->image_row_num >= |
| 971 (int32_t)gif_image_ptr->image_info_ptr->height) { | 968 (int32_t)gif_image_ptr->image_info_ptr->height) { |
| 972 gif_ptr->img_pass_num++; | 969 gif_ptr->img_pass_num++; |
| 970 if (gif_ptr->img_pass_num == FX_ArraySize(s_gif_interlace_step)) { |
| 971 gif_decoding_failure_at_tail_cleanup(gif_ptr, gif_image_ptr); |
| 972 return 0; |
| 973 } |
| 973 gif_image_ptr->image_row_num = | 974 gif_image_ptr->image_row_num = |
| 974 s_gif_interlace_step[gif_ptr->img_pass_num] / 2; | 975 s_gif_interlace_step[gif_ptr->img_pass_num] / 2; |
| 975 } | 976 } |
| 976 } else { | 977 } else { |
| 977 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num++, | 978 gif_ptr->gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num++, |
| 978 gif_image_ptr->image_row_buf); | 979 gif_image_ptr->image_row_buf); |
| 979 } | 980 } |
| 980 gif_ptr->img_row_offset = 0; | 981 gif_ptr->img_row_offset = 0; |
| 981 gif_ptr->img_row_avail_size = gif_img_row_bytes; | 982 gif_ptr->img_row_avail_size = gif_img_row_bytes; |
| 982 ret = img_decoder_ptr->Decode( | 983 ret = img_decoder_ptr->Decode( |
| 983 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, | 984 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, |
| 984 gif_ptr->img_row_avail_size); | 985 gif_ptr->img_row_avail_size); |
| 985 } | 986 } |
| 986 if (ret == 0) { | 987 if (ret == 0) { |
| 987 FX_Free(gif_image_ptr->image_row_buf); | 988 gif_decoding_failure_at_tail_cleanup(gif_ptr, gif_image_ptr); |
| 988 gif_image_ptr->image_row_buf = nullptr; | |
| 989 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | |
| 990 gif_error(gif_ptr, "Decode Image Data Error"); | |
| 991 return 0; | 989 return 0; |
| 992 } | 990 } |
| 993 } | 991 } |
| 994 } | 992 } |
| 995 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); | 993 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 996 } | 994 } |
| 997 gif_error(gif_ptr, "Decode Image Data Error"); | 995 gif_error(gif_ptr, "Decode Image Data Error"); |
| 998 return 0; | 996 return 0; |
| 999 } | 997 } |
| 998 void gif_decoding_failure_at_tail_cleanup(gif_decompress_struct_p gif_ptr, |
| 999 GifImage* gif_image_ptr) { |
| 1000 FX_Free(gif_image_ptr->image_row_buf); |
| 1001 gif_image_ptr->image_row_buf = nullptr; |
| 1002 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); |
| 1003 gif_error(gif_ptr, "Decode Image Data Error"); |
| 1004 } |
| 1000 void gif_save_decoding_status(gif_decompress_struct_p gif_ptr, int32_t status) { | 1005 void gif_save_decoding_status(gif_decompress_struct_p gif_ptr, int32_t status) { |
| 1001 gif_ptr->decode_status = status; | 1006 gif_ptr->decode_status = status; |
| 1002 gif_ptr->next_in += gif_ptr->skip_size; | 1007 gif_ptr->next_in += gif_ptr->skip_size; |
| 1003 gif_ptr->avail_in -= gif_ptr->skip_size; | 1008 gif_ptr->avail_in -= gif_ptr->skip_size; |
| 1004 gif_ptr->skip_size = 0; | 1009 gif_ptr->skip_size = 0; |
| 1005 } | 1010 } |
| 1006 uint8_t* gif_read_data(gif_decompress_struct_p gif_ptr, | 1011 uint8_t* gif_read_data(gif_decompress_struct_p gif_ptr, |
| 1007 uint8_t** des_buf_pp, | 1012 uint8_t** des_buf_pp, |
| 1008 uint32_t data_size) { | 1013 uint32_t data_size) { |
| 1009 if (!gif_ptr || gif_ptr->avail_in < gif_ptr->skip_size + data_size) | 1014 if (!gif_ptr || gif_ptr->avail_in < gif_ptr->skip_size + data_size) |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 gif_ptr->cur_offset = cur_offset; | 1236 gif_ptr->cur_offset = cur_offset; |
| 1232 res = FALSE; | 1237 res = FALSE; |
| 1233 } | 1238 } |
| 1234 dst_len = gif_ptr->cur_offset; | 1239 dst_len = gif_ptr->cur_offset; |
| 1235 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; | 1240 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; |
| 1236 if (res) { | 1241 if (res) { |
| 1237 gif_ptr->frames++; | 1242 gif_ptr->frames++; |
| 1238 } | 1243 } |
| 1239 return res; | 1244 return res; |
| 1240 } | 1245 } |
| OLD | NEW |