From d55d20b766701063152bf02c99f9e4db07aab213 Mon Sep 17 00:00:00 2001 From: Isaac Dunham Date: Tue, 25 Nov 2014 09:23:42 -0800 Subject: Port gif reader to giflib 5. -define and use compatability macros that will make giflib 4 look like giflib 5 -provide our own PrintGifError() if it's missing -since we don't check the error for DGifCloseFile, use NULL The documented behavior of giflib5 is if (&error) error =...; so this isn't supposed to break. Signed-off-by: Gerd Hoffmann --- rd/read-gif.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'rd') diff --git a/rd/read-gif.c b/rd/read-gif.c index b841dc7..2ea2947 100644 --- a/rd/read-gif.c +++ b/rd/read-gif.c @@ -5,6 +5,19 @@ #include "readers.h" +#if defined(GIFLIB_MAJOR) && (GIFLIB_MAJOR >= 5) +#define GIF5DATA(e) e +static void PrintGifError(int err) +{ + fprintf(stderr, "GIF library error: %s\n", GifErrorString(err)); +} +#else +#define GIF5DATA(x) +#define PrintGifError(e) PrintGifError() +#define DGifOpenFileHandle(x,e) DGifOpenFileHandle(x) +#define DGifCloseFile(x,e) DGifCloseFile(x) +#endif + struct gif_state { FILE *infile; GifFileType *gif; @@ -25,7 +38,7 @@ gif_fileread(struct gif_state *h) if (GIF_ERROR == DGifGetRecordType(h->gif,&RecordType)) { if (debug) fprintf(stderr,"gif: DGifGetRecordType failed\n"); - PrintGifError(); + PrintGifError(h->gif->Error); return -1; } switch (RecordType) { @@ -42,7 +55,7 @@ gif_fileread(struct gif_state *h) if (rc == GIF_ERROR) { if (debug) fprintf(stderr,"gif: DGifGetExtension failed\n"); - PrintGifError(); + PrintGifError(h->gif->Error); return -1; } if (debug) { @@ -93,12 +106,13 @@ gif_init(FILE *fp, char *filename, unsigned int page, struct gif_state *h; GifRecordType RecordType; int i, image = 0; + GIF5DATA(int giferror = 0;) h = malloc(sizeof(*h)); memset(h,0,sizeof(*h)); h->infile = fp; - h->gif = DGifOpenFileHandle(fileno(fp)); + h->gif = DGifOpenFileHandle(fileno(fp), &giferror); h->row = malloc(h->gif->SWidth * sizeof(GifPixelType)); while (0 == image) { @@ -108,7 +122,7 @@ gif_init(FILE *fp, char *filename, unsigned int page, if (GIF_ERROR == DGifGetImageDesc(h->gif)) { if (debug) fprintf(stderr,"gif: DGifGetImageDesc failed\n"); - PrintGifError(); + PrintGifError(giferror); } if (NULL == h->gif->SColorMap && NULL == h->gif->Image.ColorMap) { @@ -156,7 +170,7 @@ gif_init(FILE *fp, char *filename, unsigned int page, oops: if (debug) fprintf(stderr,"gif: fatal error, aborting\n"); - DGifCloseFile(h->gif); + DGifCloseFile(h->gif, NULL); fclose(h->infile); free(h->row); free(h); @@ -196,7 +210,7 @@ gif_done(void *data) if (debug) fprintf(stderr,"gif: done, cleaning up\n"); - DGifCloseFile(h->gif); + DGifCloseFile(h->gif, NULL); fclose(h->infile); if (h->il) free(h->il); @@ -208,7 +222,7 @@ static struct ida_loader gif_loader = { magic: "GIF", moff: 0, mlen: 3, - name: "libungif", + name: "giflib", init: gif_init, read: gif_read, done: gif_done, -- cgit