Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#21 conditionally use QuantizeBuffer, not available in giflib 4.2 #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@

#define INLINE static inline


// QuantizeBuffer has been removed from giflib 4.2
// in http://sourceforge.net/p/giflib/code/ci/ce02f85e6ed1e1455a4aea9ffa68a3e2b8f8a4b1/
#if !defined(GIFLIB_MAJOR) || (GIFLIB_MAJOR == 4 && GIFLIB_MINOR < 2)
#define GifQuantizeBuffer QuantizeBuffer
#endif

#if !defined(GIFLIB_MAJOR) || GIFLIB_MAJOR < 5
#define EGifOpen(x, y, z) EGifOpen(x, y)
#define EGifCloseFile(x, y) EGifCloseFile(x)
#define GifMakeMapObject MakeMapObject
#define GifFreeMapObject FreeMapObject
#define GifQuantizeBuffer QuantizeBuffer
#define GIF_BEGIN_APP_EXTENSION(f) EGifPutExtensionFirst(f, APPLICATION_EXT_FUNC_CODE, strlen(GIF_APP), GIF_APP)
#define GIF_END_APP_EXTENSION(f, m) EGifPutExtensionLast(f, APPLICATION_EXT_FUNC_CODE, sizeof(m), m)
#else
Expand Down Expand Up @@ -318,6 +324,8 @@ gif_encode(Image *image, int single, int *size)
ColorMapObject *palette = GifMakeMapObject(NCOLORS, NULL);
int palette_size = NCOLORS;


#if !defined(GIFLIB_MAJOR) || (GIFLIB_MAJOR == 4 && GIFLIB_MINOR < 2)
// Quantize again using giflib, since it yields a palette which produces
// better compression, reducing the file size by 20%. Note that this second
// quantization is very fast, because the image already has 256 colors, so
Expand All @@ -327,7 +335,7 @@ gif_encode(Image *image, int single, int *size)
gif_frames_free(frames, count);
return NULL;
}

# endif
frames[0].data = malloc(total);
memcpy(frames[0].data, output, total);
frames[0].width = width;
Expand Down