Index: core/fxcodec/lgif/fx_gif.cpp |
diff --git a/core/fxcodec/lgif/fx_gif.cpp b/core/fxcodec/lgif/fx_gif.cpp |
index 53298c831a7c74742204c49208832538b81030e3..866b12e891d8fc6fc64e2233a6ed1f14e88ceb5a 100644 |
--- a/core/fxcodec/lgif/fx_gif.cpp |
+++ b/core/fxcodec/lgif/fx_gif.cpp |
@@ -153,15 +153,12 @@ static FX_BOOL gif_grow_buf(uint8_t*& dst_buf, |
dst_len <<= 1; |
dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); |
Tom Sepez
2016/06/02 20:09:48
followup: Probably should be a try-realloc here.
Lei Zhang
2016/06/07 07:33:23
Added TODO
|
} |
- if (dst_buf == NULL) { |
+ if (!dst_buf) { |
dst_len = size; |
dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); |
- if (dst_buf == NULL) { |
- return FALSE; |
- } |
} |
FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org); |
- return dst_buf != NULL; |
+ return !!dst_buf; |
} |
return TRUE; |
} |
@@ -359,9 +356,9 @@ void CGifLZWEncoder::Finish(uint8_t*& dst_buf, |
gif_decompress_struct_p gif_create_decompress() { |
gif_decompress_struct_p gif_ptr = |
(gif_decompress_struct*)FX_Alloc(uint8_t, sizeof(gif_decompress_struct)); |
- if (gif_ptr == NULL) { |
+ if (!gif_ptr) |
return NULL; |
- } |
+ |
FXSYS_memset(gif_ptr, 0, sizeof(gif_decompress_struct)); |
gif_ptr->decode_status = GIF_D_STATUS_SIG; |
gif_ptr->img_ptr_arr_ptr = new CFX_ArrayTemplate<GifImage*>; |
@@ -370,9 +367,9 @@ gif_decompress_struct_p gif_create_decompress() { |
return gif_ptr; |
} |
void gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) { |
- if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { |
+ if (!gif_ptr_ptr || !*gif_ptr_ptr) |
return; |
- } |
+ |
gif_decompress_struct_p gif_ptr = *gif_ptr_ptr; |
*gif_ptr_ptr = NULL; |
FX_Free(gif_ptr->global_pal_ptr); |
@@ -410,13 +407,13 @@ void gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) { |
gif_compress_struct_p gif_create_compress() { |
gif_compress_struct_p gif_ptr = |
(gif_compress_struct*)FX_Alloc(uint8_t, sizeof(gif_compress_struct)); |
- if (gif_ptr == NULL) { |
+ if (!gif_ptr) |
return NULL; |
- } |
+ |
FXSYS_memset(gif_ptr, 0, sizeof(gif_compress_struct)); |
gif_ptr->img_encoder_ptr = new CGifLZWEncoder; |
gif_ptr->header_ptr = (GifHeader*)FX_Alloc(uint8_t, sizeof(GifHeader)); |
- if (gif_ptr->header_ptr == NULL) { |
+ if (!gif_ptr->header_ptr) { |
delete (gif_ptr->img_encoder_ptr); |
FX_Free(gif_ptr); |
return NULL; |
@@ -424,7 +421,7 @@ gif_compress_struct_p gif_create_compress() { |
FXSYS_memcpy(gif_ptr->header_ptr->signature, GIF_SIGNATURE, 3); |
FXSYS_memcpy(gif_ptr->header_ptr->version, "89a", 3); |
gif_ptr->lsd_ptr = (GifLSD*)FX_Alloc(uint8_t, sizeof(GifLSD)); |
- if (gif_ptr->lsd_ptr == NULL) { |
+ if (!gif_ptr->lsd_ptr) { |
FX_Free(gif_ptr->header_ptr); |
delete (gif_ptr->img_encoder_ptr); |
FX_Free(gif_ptr); |
@@ -433,7 +430,7 @@ gif_compress_struct_p gif_create_compress() { |
FXSYS_memset(gif_ptr->lsd_ptr, 0, sizeof(GifLSD)); |
gif_ptr->image_info_ptr = |
(GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); |
- if (gif_ptr->image_info_ptr == NULL) { |
+ if (!gif_ptr->image_info_ptr) { |
FX_Free(gif_ptr->lsd_ptr); |
FX_Free(gif_ptr->header_ptr); |
delete (gif_ptr->img_encoder_ptr); |
@@ -442,7 +439,7 @@ gif_compress_struct_p gif_create_compress() { |
} |
FXSYS_memset(gif_ptr->image_info_ptr, 0, sizeof(GifImageInfo)); |
gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); |
- if (gif_ptr->gce_ptr == NULL) { |
+ if (!gif_ptr->gce_ptr) { |
FX_Free(gif_ptr->image_info_ptr); |
FX_Free(gif_ptr->lsd_ptr); |
FX_Free(gif_ptr->header_ptr); |
@@ -451,7 +448,7 @@ gif_compress_struct_p gif_create_compress() { |
return NULL; |
} |
gif_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); |
- if (gif_ptr->pte_ptr == NULL) { |
+ if (!gif_ptr->pte_ptr) { |
FX_Free(gif_ptr->gce_ptr); |
FX_Free(gif_ptr->image_info_ptr); |
FX_Free(gif_ptr->lsd_ptr); |
@@ -465,9 +462,9 @@ gif_compress_struct_p gif_create_compress() { |
return gif_ptr; |
} |
void gif_destroy_compress(gif_compress_struct_pp gif_ptr_ptr) { |
- if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { |
+ if (!gif_ptr_ptr || !*gif_ptr_ptr) |
return; |
- } |
+ |
gif_compress_struct_p gif_ptr = *gif_ptr_ptr; |
*gif_ptr_ptr = NULL; |
FX_Free(gif_ptr->header_ptr); |
@@ -488,15 +485,15 @@ void gif_error(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) { |
} |
void gif_warn(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {} |
int32_t gif_read_header(gif_decompress_struct_p gif_ptr) { |
- if (gif_ptr == NULL) { |
+ if (!gif_ptr) |
return 0; |
- } |
+ |
uint32_t skip_size_org = gif_ptr->skip_size; |
ASSERT(sizeof(GifHeader) == 6); |
GifHeader* gif_header_ptr = NULL; |
- if (gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6) == NULL) { |
+ if (!gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6)) |
return 2; |
- } |
+ |
if (FXSYS_strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 || |
gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') { |
gif_error(gif_ptr, "Not A Gif Image"); |
@@ -504,7 +501,7 @@ int32_t gif_read_header(gif_decompress_struct_p gif_ptr) { |
} |
ASSERT(sizeof(GifLSD) == 7); |
GifLSD* gif_lsd_ptr = NULL; |
- if (gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7) == NULL) { |
+ if (!gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
@@ -514,7 +511,7 @@ int32_t gif_read_header(gif_decompress_struct_p gif_ptr) { |
ASSERT(sizeof(GifPalette) == 3); |
int32_t global_pal_size = gif_ptr->global_pal_num * 3; |
uint8_t* global_pal_ptr = NULL; |
- if (gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size) == NULL) { |
+ if (!gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
@@ -532,9 +529,9 @@ int32_t gif_read_header(gif_decompress_struct_p gif_ptr) { |
return 1; |
} |
int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { |
- if (gif_ptr == NULL) { |
+ if (!gif_ptr) |
return 0; |
- } |
+ |
int32_t ret = 1; |
while (TRUE) { |
switch (gif_ptr->decode_status) { |
@@ -542,9 +539,9 @@ int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { |
return 1; |
case GIF_D_STATUS_SIG: { |
uint8_t* sig_ptr = NULL; |
- if (gif_read_data(gif_ptr, &sig_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &sig_ptr, 1)) |
return 2; |
- } |
+ |
switch (*sig_ptr) { |
case GIF_SIG_EXTENSION: |
gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT); |
@@ -567,9 +564,9 @@ int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { |
} |
case GIF_D_STATUS_EXT: { |
uint8_t* ext_ptr = NULL; |
- if (gif_read_data(gif_ptr, &ext_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &ext_ptr, 1)) |
return 2; |
- } |
+ |
switch (*ext_ptr) { |
case GIF_BLOCK_CE: |
gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE); |
@@ -601,19 +598,18 @@ int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { |
uint8_t* data_size_ptr = NULL; |
uint8_t* data_ptr = NULL; |
uint32_t skip_size_org = gif_ptr->skip_size; |
- if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
return 2; |
- } |
+ |
while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
- if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); |
skip_size_org = gif_ptr->skip_size; |
- if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
return 2; |
- } |
} |
gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); |
continue; |
@@ -643,15 +639,15 @@ int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
uint32_t skip_size_org = gif_ptr->skip_size; |
switch (gif_ptr->decode_status) { |
case GIF_D_STATUS_EXT_CE: { |
- if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
gif_ptr->cmt_data_ptr->clear(); |
while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
uint8_t data_size = *data_size_ptr; |
- if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || |
- gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) || |
+ !gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
@@ -662,7 +658,7 @@ int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
case GIF_D_STATUS_EXT_PTE: { |
ASSERT(sizeof(GifPTE) == 13); |
GifPTE* gif_pte_ptr = NULL; |
- if (gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13) == NULL) { |
+ if (!gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13)) { |
return 2; |
} |
GifPlainText* gif_pt_ptr = FX_Alloc(GifPlainText, 1); |
@@ -683,7 +679,7 @@ int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
gif_pt_ptr->pte_ptr->char_height = gif_pte_ptr->char_height; |
gif_pt_ptr->pte_ptr->fc_index = gif_pte_ptr->fc_index; |
gif_pt_ptr->pte_ptr->bc_index = gif_pte_ptr->bc_index; |
- if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
gif_ptr->skip_size = skip_size_org; |
if (gif_pt_ptr) { |
FX_Free(gif_pt_ptr->gce_ptr); |
@@ -695,8 +691,8 @@ int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
} |
while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
uint8_t data_size = *data_size_ptr; |
- if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || |
- gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) || |
+ !gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
gif_ptr->skip_size = skip_size_org; |
if (gif_pt_ptr) { |
FX_Free(gif_pt_ptr->gce_ptr); |
@@ -714,12 +710,11 @@ int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
case GIF_D_STATUS_EXT_GCE: { |
ASSERT(sizeof(GifGCE) == 5); |
GifGCE* gif_gce_ptr = NULL; |
- if (gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6) == NULL) { |
+ if (!gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6)) |
return 2; |
- } |
- if (gif_ptr->gce_ptr == NULL) { |
+ |
+ if (!gif_ptr->gce_ptr) |
gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); |
- } |
gif_ptr->gce_ptr->block_size = gif_gce_ptr->block_size; |
gif_ptr->gce_ptr->gce_flag = gif_gce_ptr->gce_flag; |
gif_ptr->gce_ptr->delay_time = |
@@ -731,12 +726,12 @@ int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) { |
FX_Free(gif_ptr->gce_ptr); |
gif_ptr->gce_ptr = NULL; |
} |
- if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
return 2; |
- } |
+ |
while (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
- if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || |
- gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) || |
+ !gif_read_data(gif_ptr, &data_size_ptr, 1)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
@@ -754,9 +749,9 @@ int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) { |
uint32_t skip_size_org = gif_ptr->skip_size; |
ASSERT(sizeof(GifImageInfo) == 9); |
GifImageInfo* gif_img_info_ptr = NULL; |
- if (gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9) == NULL) { |
+ if (!gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9)) |
return 2; |
- } |
+ |
GifImage* gif_image_ptr = (GifImage*)FX_Alloc(uint8_t, sizeof(GifImage)); |
FXSYS_memset(gif_image_ptr, 0, sizeof(GifImage)); |
gif_image_ptr->image_info_ptr = |
@@ -787,7 +782,7 @@ int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) { |
ASSERT(sizeof(GifPalette) == 3); |
int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3; |
uint8_t* loc_pal_ptr = NULL; |
- if (gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size) == NULL) { |
+ if (!gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size)) { |
gif_ptr->skip_size = skip_size_org; |
FX_Free(gif_image_ptr->image_info_ptr); |
FX_Free(gif_image_ptr->image_row_buf); |
@@ -802,7 +797,7 @@ int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) { |
} |
} |
uint8_t* code_size_ptr = NULL; |
- if (gif_read_data(gif_ptr, &code_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &code_size_ptr, 1)) { |
gif_ptr->skip_size = skip_size_org; |
FX_Free(gif_image_ptr->image_info_ptr); |
FX_Free(gif_image_ptr->local_pal_ptr); |
@@ -820,7 +815,7 @@ int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) { |
return 1; |
} |
int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { |
- if (gif_ptr == NULL || frame_num < 0 || |
+ if (!gif_ptr || frame_num < 0 || |
frame_num >= gif_ptr->img_ptr_arr_ptr->GetSize()) { |
return 0; |
} |
@@ -842,7 +837,7 @@ int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { |
->pal_bits) |
: 0; |
gif_ptr->avail_in = 0; |
- if (gif_img_gce_ptr == NULL) { |
+ if (!gif_img_gce_ptr) { |
FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( |
gif_ptr, gif_image_ptr->image_data_pos, |
gif_image_ptr->image_info_ptr->left, |
@@ -883,9 +878,8 @@ int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { |
return 0; |
} |
} |
- if (gif_ptr->img_decoder_ptr == NULL) { |
+ if (!gif_ptr->img_decoder_ptr) |
gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr); |
- } |
gif_ptr->img_decoder_ptr->InitTable(gif_image_ptr->image_code_size); |
gif_ptr->img_row_offset = 0; |
gif_ptr->img_row_avail_size = 0; |
@@ -895,11 +889,11 @@ int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { |
} |
CGifLZWDecoder* img_decoder_ptr = gif_ptr->img_decoder_ptr; |
if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) { |
- if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
return 2; |
- } |
+ |
if (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
- if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
@@ -929,11 +923,11 @@ int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { |
if (ret == 2) { |
ASSERT(img_decoder_ptr->GetAvailInput() == 0); |
skip_size_org = gif_ptr->skip_size; |
- if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) |
return 2; |
- } |
+ |
if (*data_size_ptr != GIF_BLOCK_TERMINAL) { |
- if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { |
+ if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) { |
gif_ptr->skip_size = skip_size_org; |
return 2; |
} |
@@ -992,9 +986,9 @@ void gif_save_decoding_status(gif_decompress_struct_p gif_ptr, int32_t status) { |
uint8_t* gif_read_data(gif_decompress_struct_p gif_ptr, |
uint8_t** des_buf_pp, |
uint32_t data_size) { |
- if (gif_ptr == NULL || gif_ptr->avail_in < gif_ptr->skip_size + data_size) { |
+ if (!gif_ptr || gif_ptr->avail_in < gif_ptr->skip_size + data_size) |
return NULL; |
- } |
+ |
*des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size; |
gif_ptr->skip_size += data_size; |
return *des_buf_pp; |
@@ -1027,9 +1021,9 @@ static FX_BOOL gif_write_header(gif_compress_struct_p gif_ptr, |
} |
dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF); |
dst_buf = FX_TryAlloc(uint8_t, dst_len); |
- if (dst_buf == NULL) { |
+ if (!dst_buf) |
return FALSE; |
- } |
+ |
FXSYS_memset(dst_buf, 0, dst_len); |
FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader)); |
gif_ptr->cur_offset += sizeof(GifHeader); |
@@ -1067,9 +1061,6 @@ void interlace_buf(const uint8_t* buf, uint32_t pitch, uint32_t height) { |
j = 3; |
} |
temp = FX_Alloc(uint8_t, pitch); |
- if (temp == NULL) { |
- return; |
- } |
FXSYS_memcpy(temp, &buf[pitch * row], pitch); |
pass[j].Add(temp); |
row++; |