if (EGifPutImageDesc(GifFile, frame->x, frame->y, frame->width, frame->height, false, OutputColorMap) == GIF_ERROR) {
mm_util_error("could not put image description");
- EGifCloseFile(GifFile, NULL);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
unsigned char c = Ptr[pixels++];
if (EGifPutPixel(GifFile, c) == GIF_ERROR) {
mm_util_error("could not put pixel");
- if (GifFile != NULL)
- EGifCloseFile(GifFile, NULL);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
}
int mm_util_encode_close_gif(mm_util_gif_data *encoded)
{
mm_util_debug("mm_util_encode_close_gif");
+ if (encoded->GifFile == NULL) {
+ mm_util_error("Invalid parameter");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
if (EGifCloseFile(encoded->GifFile, NULL) == GIF_ERROR) {
mm_util_error("could not close file");
return MM_UTIL_ERROR_INVALID_OPERATION;
}
+ encoded->GifFile = NULL;
return MM_UTIL_ERROR_NONE;
}
if (!encoded->screen_desc_updated) {
if (EGifPutScreenDesc(encoded->GifFile, encoded->frames[0]->width, encoded->frames[0]->height, 8, 0, NULL) == GIF_ERROR) {
mm_util_error("could not put screen description");
- EGifCloseFile(encoded->GifFile, NULL);
+ mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
encoded->screen_desc_updated = true;
for (i = encoded->current_count; i < encoded->image_count; i++) {
if ((OutputBuffer = (GifByteType *) malloc(encoded->frames[i]->width * encoded->frames[i]->height * sizeof(GifByteType))) == NULL) {
mm_util_error("Failed to allocate memory required, aborted.");
+ mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
free((char *)green);
free((char *)blue);
free(OutputBuffer);
+ mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
if (GifQuantizeBuffer(encoded->frames[i]->width, encoded->frames[i]->height, &ColorMapSize, red, green, blue, OutputBuffer, OutputColorMap->Colors) == GIF_ERROR) {
free((char *)green);
free((char *)blue);
free(OutputBuffer);
+ mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
free((char *)red);
if (__save_buffer_to_gif(encoded->GifFile, OutputBuffer, OutputColorMap, encoded->frames[i]) != MM_UTIL_ERROR_NONE) {
mm_util_error("save_buffer_to_gif is failed");
free(OutputBuffer);
+ mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
}
encoded->size = encoded->write_data_ptr.size;
+ mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_NONE;
}