/* Private Function: * Frees the last image in the GifFile->SavedImages array */ void FreeLastSavedImage(GifFileType *GifFile) { SavedImage *sp; if ((GifFile == NULL) || (GifFile->SavedImages == NULL)) return; /* Remove one SavedImage from the GifFile */ GifFile->ImageCount--; sp = &GifFile->SavedImages[GifFile->ImageCount]; /* Deallocate its Colormap */ if (sp->ImageDesc.ColorMap != NULL) { GifFreeMapObject(sp->ImageDesc.ColorMap); sp->ImageDesc.ColorMap = NULL; } /* Deallocate the image data */ if (sp->RasterBits != NULL) free((char *)sp->RasterBits); /* Deallocate any extensions */ GifFreeExtensions(&sp->ExtensionBlockCount, &sp->ExtensionBlocks); /*** FIXME: We could realloc the GifFile->SavedImages structure but is * there a point to it? Saves some memory but we'd have to do it every * time. If this is used in GifFreeSavedImages then it would be inefficient * (The whole array is going to be deallocated.) If we just use it when * we want to free the last Image it's convenient to do it here. */ }
/* * This function free extension data that has been saved to assist the image * decoder */ void SkGifCodec::FreeExtension(SavedImage* image) { if (NULL != image->ExtensionBlocks) { #if GIFLIB_MAJOR < 5 FreeExtension(image); #else GifFreeExtensions(&image->ExtensionBlockCount, &image->ExtensionBlocks); #endif } }
/****************************************************************************** This routine should be called last, to close the GIF file. ******************************************************************************/ int DGifCloseFile(GifFileType *GifFile) { GifFilePrivateType *Private; if (GifFile == NULL || GifFile->Private == NULL) return GIF_ERROR; if (GifFile->Image.ColorMap) { GifFreeMapObject(GifFile->Image.ColorMap); GifFile->Image.ColorMap = NULL; } if (GifFile->SColorMap) { GifFreeMapObject(GifFile->SColorMap); GifFile->SColorMap = NULL; } if (GifFile->SavedImages) { GifFreeSavedImages(GifFile); GifFile->SavedImages = NULL; } GifFreeExtensions(&GifFile->ExtensionBlockCount, &GifFile->ExtensionBlocks); Private = (GifFilePrivateType *) GifFile->Private; if (!IS_READABLE(Private)) { /* This file was NOT open for reading: */ GifFile->Error = D_GIF_ERR_NOT_READABLE; return GIF_ERROR; } if (Private->File && (fclose(Private->File) != 0)) { GifFile->Error = D_GIF_ERR_CLOSE_FAILED; return GIF_ERROR; } free((char *)GifFile->Private); /* * Without the #ifndef, we get spurious warnings because Coverity mistakenly * thinks the GIF structure is freed on an error return. */ #ifndef __COVERITY__ free(GifFile); #endif /* __COVERITY__ */ return GIF_OK; }
/****************************************************************************** This routine should be called last, to close the GIF file. ******************************************************************************/ int DGifCloseFile(GifFileType *GifFile, int *ErrorCode) { GifFilePrivateType *Private; if (GifFile == NULL || GifFile->Private == NULL) return GIF_ERROR; if (GifFile->Image.ColorMap) { GifFreeMapObject(GifFile->Image.ColorMap); GifFile->Image.ColorMap = NULL; } if (GifFile->SColorMap) { GifFreeMapObject(GifFile->SColorMap); GifFile->SColorMap = NULL; } if (GifFile->SavedImages) { GifFreeSavedImages(GifFile); GifFile->SavedImages = NULL; } GifFreeExtensions(&GifFile->ExtensionBlockCount, &GifFile->ExtensionBlocks); Private = (GifFilePrivateType *) GifFile->Private; if (!IS_READABLE(Private)) { /* This file was NOT open for reading: */ if (ErrorCode != NULL) *ErrorCode = D_GIF_ERR_NOT_READABLE; free((char *)GifFile->Private); free(GifFile); return GIF_ERROR; } if (Private->File && (fclose(Private->File) != 0)) { if (ErrorCode != NULL) *ErrorCode = D_GIF_ERR_CLOSE_FAILED; free((char *)GifFile->Private); free(GifFile); return GIF_ERROR; } free((char *)GifFile->Private); free(GifFile); if (ErrorCode != NULL) *ErrorCode = D_GIF_SUCCEEDED; return GIF_OK; }
bool compress_custom(void* input_data, InputFunc input_func, void* output_data, OutputFunc output_func, int sample_size) { GifFileType* input_gif = NULL; GifFileType* output_gif = NULL; int result = GIF_ERROR; // Check sample if (sample_size <= 0) { return false; } input_gif = DGifOpen(input_data, input_func, &error_code); if (input_gif == NULL) { LOGE(EMSG("Can't open input gif")); return false; } DGifSlurp(input_gif); if (input_gif->ImageCount == 0) { LOGE(EMSG("Gif frame count is 0")); DGifCloseFile(input_gif, &error_code); return false; } // Save gif output_gif = EGifOpen(output_data, output_func, &error_code); if (output_gif == NULL) { LOGE(EMSG("Can't open output gif")); DGifCloseFile(input_gif, &error_code); return false; } if (do_compress(input_gif, output_gif, sample_size)) { result = EGifSpew(output_gif); } // Free GifFreeExtensions(&output_gif->ExtensionBlockCount, &output_gif->ExtensionBlocks); if (output_gif->SavedImages) { GifFreeSavedImages(output_gif); output_gif->SavedImages = NULL; } // Close gif DGifCloseFile(input_gif, &error_code); return result == GIF_OK; }
void GifFreeSavedImages(GifFileType *GifFile) { SavedImage *sp; if ((GifFile == NULL) || (GifFile->SavedImages == NULL)) { return; } for (sp = GifFile->SavedImages; sp < GifFile->SavedImages + GifFile->ImageCount; sp++) { if (sp->ImageDesc.ColorMap != NULL) { GifFreeMapObject(sp->ImageDesc.ColorMap); sp->ImageDesc.ColorMap = NULL; } if (sp->RasterBits != NULL) free((char *)sp->RasterBits); GifFreeExtensions(&sp->ExtensionBlockCount, &sp->ExtensionBlocks); } free((char *)GifFile->SavedImages); GifFile->SavedImages = NULL; }
/* * This function free extension data that has been saved to assist the image * decoder */ void SkGifCodec::FreeExtension(SavedImage* image) { if (NULL != image->ExtensionBlocks) { GifFreeExtensions(&image->ExtensionBlockCount, &image->ExtensionBlocks); } }