static int __gif_make_color_map(mm_image_info_s *gif_image, ColorMapObject **color_map, GifByteType **intermediate_image, unsigned long *intermediate_image_size)
{
- int ret = MM_UTIL_ERROR_NONE;
+ int ret = GIF_OK;
int colormap_size = DEFAULT_COLORMAP_SIZE;
GifByteType *red = NULL, *green = NULL, *blue = NULL;
+ unsigned long num_of_pixels = 0;
+ ColorMapObject *gif_color_map = NULL;
+ GifByteType *out_buffer = NULL;
- mm_util_retvm_if(gif_image == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
-
- unsigned long num_of_pixels = gif_image->width * gif_image->height;
+ mm_util_retvm_if(!gif_image, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid gif_image");
+ mm_util_retvm_if(!color_map, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid color_map");
+ mm_util_retvm_if(!intermediate_image, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid intermediate_image");
+ mm_util_retvm_if(!intermediate_image_size, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid intermediate_image_size");
- /* make colormap and quantization for the color table of gif */
- __gif_extract_rgb(gif_image, num_of_pixels, &red, &green, &blue);
-
- if ((*color_map = GifMakeMapObject(colormap_size, NULL)) == NULL) {
- mm_util_error("To make color map is failed");
- ret = MM_UTIL_ERROR_INVALID_OPERATION;
- goto FAIL;
- }
+ num_of_pixels = gif_image->width * gif_image->height;
- /* allocate output buffer */
- *intermediate_image = (GifByteType *) calloc(1, num_of_pixels * sizeof(GifByteType));
- if (*intermediate_image == NULL) {
- mm_util_error("Memory allocation failed");
- ret = MM_UTIL_ERROR_INVALID_OPERATION;
- goto FAIL;
+ if ((gif_color_map = GifMakeMapObject(colormap_size, NULL)) == NULL) {
+ mm_util_error("failed to make color map");
+ return MM_UTIL_ERROR_INVALID_OPERATION;
}
- *intermediate_image_size = num_of_pixels * sizeof(GifByteType);
- if (GifQuantizeBuffer(gif_image->width, gif_image->height, &colormap_size, red, green, blue, *intermediate_image, (*color_map)->Colors) == GIF_ERROR) {
- mm_util_error("could not quantize buffer");
- ret = MM_UTIL_ERROR_INVALID_OPERATION;
- goto FAIL;
- }
- goto SUCCESS;
+ __gif_extract_rgb(gif_image, num_of_pixels, &red, &green, &blue);
-FAIL:
- if (*intermediate_image)
- MMUTIL_SAFE_FREE(*intermediate_image);
+ /* allocate output buffer */
+ out_buffer = g_new0(GifByteType, num_of_pixels);
- *intermediate_image_size = 0;
- COLORMAP_FREE(*color_map);
-SUCCESS:
+ ret = GifQuantizeBuffer(gif_image->width, gif_image->height, &colormap_size, red, green, blue, out_buffer, gif_color_map->Colors);
g_free(red);
g_free(green);
g_free(blue);
- return ret;
+ if (ret == GIF_ERROR) {
+ mm_util_error("failed to quantize buffer");
+ COLORMAP_FREE(gif_color_map);
+ g_free(out_buffer);
+ return MM_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ *color_map = gif_color_map;
+ *intermediate_image = out_buffer;
+ *intermediate_image_size = num_of_pixels * sizeof(GifByteType);
+
+ return MM_UTIL_ERROR_NONE;
}
static int __gif_encode_open_mem(gif_file_s *gif_file)
FALSE, color_map) == GIF_ERROR) {
mm_util_error("EGifPutImageDesc failed due to %s", GifErrorString(gif_file->GifFile->Error));
COLORMAP_FREE(color_map);
- MMUTIL_SAFE_FREE(intermediate_image);
+ g_free(intermediate_image);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
/* release color map */
}
/* release intermediate_image */
- MMUTIL_SAFE_FREE(intermediate_image);
+ g_free(intermediate_image);
return MM_UTIL_ERROR_NONE;
}