From a7663fbbcf3b9585bcd97ac71db8a9b30eb76fc7 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 3 Nov 2013 13:08:11 +0100 Subject: [PATCH] wrlib: Add support for v5 of the gif_lib API As reported by Nicolas (nhs), compilation of wrlib is broken when switching to gif_lib v5. The API of gif_lib has known little change to provide thread-safe usage, so we now detect this in configure and and use the functions as appropriate in gif.c Signed-off-by: Christophe CURIS Signed-off-by: Carlos R. Mafra --- m4/wm_imgfmt_check.m4 | 16 +++++++++++++--- wrlib/gif.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/m4/wm_imgfmt_check.m4 b/m4/wm_imgfmt_check.m4 index 1cbb212f..e5f403da 100644 --- a/m4/wm_imgfmt_check.m4 +++ b/m4/wm_imgfmt_check.m4 @@ -19,7 +19,7 @@ # WM_IMGFMT_CHECK_GIF # ------------------- # -# Check for GIF file support through 'libgif' or 'libungif' +# Check for GIF file support through 'libgif', 'libungif' or 'giflib v5' # The check depends on variable 'enable_gif' being either: # yes - detect, fail if not found # no - do not detect, disable support @@ -53,7 +53,17 @@ AS_IF([test "x$enable_gif" = "xno"], [AC_MSG_ERROR([found $wm_cv_imgfmt_gif but could not find appropriate header - are you missing libgif-dev package?])]) AS_IF([wm_fn_imgfmt_try_compile "gif_lib.h" "DGifOpenFileName(filename)" ""], [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:4"], - [AC_MSG_ERROR([found $wm_cv_imgfmt_gif and header, but cannot compile - unsupported version?])]) + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [@%:@include + +const char *filename = "dummy";], + [ int error_code; + DGifOpenFileName(filename, &error_code);] )], + [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:5"], + [AC_MSG_ERROR([found $wm_cv_imgfmt_gif and header, but cannot compile - unsupported version?])])dnl + ] + ) CFLAGS="$wm_save_CFLAGS"]) ]) AS_IF([test "x$wm_cv_imgfmt_gif" = "xno"], @@ -62,7 +72,7 @@ AS_IF([test "x$enable_gif" = "xno"], [supported_gfx="$supported_gfx GIF" GFXLIBS="$GFXLIBS `echo "$wm_cv_imgfmt_gif" | sed -e 's, *version:.*,,' `" AC_DEFINE_UNQUOTED([USE_GIF], - [1], + [`echo "$wm_cv_imgfmt_gif" | sed -e 's,.*version:,,' `], [defined when valid GIF library with header was found])]) ]) AM_CONDITIONAL([USE_GIF], [test "x$enable_gif" != "xno"])dnl diff --git a/wrlib/gif.c b/wrlib/gif.c index e1b1a732..acbf7da1 100644 --- a/wrlib/gif.c +++ b/wrlib/gif.c @@ -48,6 +48,7 @@ RImage *RLoadGIF(const char *file, int index) GifRecordType recType; ColorMapObject *colormap; unsigned char rmap[256], gmap[256], bmap[256]; + int gif_error; if (index < 0) index = 0; @@ -55,10 +56,17 @@ RImage *RLoadGIF(const char *file, int index) /* default error message */ RErrorCode = RERR_BADINDEX; +#if USE_GIF == 4 gif = DGifOpenFileName(file); +#else /* USE_GIF == 5 */ + gif = DGifOpenFileName(file, &gif_error); +#endif if (!gif) { - switch (GifLastError()) { +#if USE_GIF == 4 + gif_error = GifLastError(); +#endif + switch (gif_error) { case D_GIF_ERR_OPEN_FAILED: RErrorCode = RERR_OPEN; break; @@ -182,6 +190,7 @@ RImage *RLoadGIF(const char *file, int index) /* yuck! */ goto did_not_get_any_errors; giferr: +#if USE_GIF == 4 switch (GifLastError()) { case D_GIF_ERR_OPEN_FAILED: RErrorCode = RERR_OPEN; @@ -193,6 +202,10 @@ RImage *RLoadGIF(const char *file, int index) RErrorCode = RERR_BADIMAGEFILE; break; } +#else + /* With gif_lib v5 there's no way to know what went wrong */ + RErrorCode = RERR_BADIMAGEFILE; +#endif bye: if (image) RReleaseImage(image);