#include <limits.h>
#define COLORMAP_FREE(map) { if (map != NULL) { GifFreeMapObject(map); map = NULL; } }
-#define RGB_ALLOC(r, g, b, number, size) { r = calloc(1, number * size); g = calloc(1, number * size); b = calloc(1, number * size); }
-#define RGB_FREE(r, g, b) { MMUTIL_SAFE_FREE(r); MMUTIL_SAFE_FREE(g); MMUTIL_SAFE_FREE(b); }
#define GRAPHIC_EXT_BLOCK_SIZE 4
static const int DEFAULT_COLORMAP_SIZE = (1 << 8);
-static int __gif_extract_rgb(mm_image_info_s *gif_image, unsigned long num_of_pixels, GifByteType **red, GifByteType **green, GifByteType **blue)
+static void __gif_extract_rgb(mm_image_info_s *gif_image, unsigned long num_of_pixels, GifByteType **red, GifByteType **green, GifByteType **blue)
{
GifWord i, j;
- GifByteType *redP, *greenP, *blueP;
+ GifByteType *redP = NULL, *greenP = NULL, *blueP = NULL;
GifByteType *buffer = (GifByteType*)gif_image->data;
mm_util_fenter();
- RGB_ALLOC(redP, greenP, blueP, num_of_pixels, sizeof(GifByteType));
-
- *red = redP;
- *green = greenP;
- *blue = blueP;
- mm_util_retvm_if((redP == NULL || greenP == NULL || blueP == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed");
+ redP = g_new0(GifByteType, num_of_pixels);
+ greenP = g_new0(GifByteType, num_of_pixels);
+ blueP = g_new0(GifByteType, num_of_pixels);
for (i = 0; i < gif_image->height; i++) {
for (j = 0; j < gif_image->width; j++) {
}
}
- return MM_UTIL_ERROR_NONE;
+ *red = redP;
+ *green = greenP;
+ *blue = blueP;
}
static int __gif_make_color_map(mm_image_info_s *gif_image, ColorMapObject **color_map, GifByteType **intermediate_image, unsigned long *intermediate_image_size)
unsigned long num_of_pixels = gif_image->width * gif_image->height;
/* make colormap and quantization for the color table of gif */
- ret = __gif_extract_rgb(gif_image, num_of_pixels, &red, &green, &blue);
- if (ret != MM_UTIL_ERROR_NONE) {
- mm_util_error("To extract rgb from image is failed");
- goto FAIL;
- }
+ __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");
*intermediate_image_size = 0;
COLORMAP_FREE(*color_map);
SUCCESS:
- RGB_FREE(red, green, blue);
+ g_free(red);
+ g_free(green);
+ g_free(blue);
return ret;
}