From 207845f3e64298c2fc7078db70f047d19b094ede Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 13 Feb 2018 00:22:06 +0100 Subject: [PATCH] Images: Cope with API changes in recent versions of libgif --- images/io-libungif.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/images/io-libungif.c b/images/io-libungif.c index bf97f743..f444fc5e 100644 --- a/images/io-libungif.c +++ b/images/io-libungif.c @@ -19,6 +19,19 @@ #include +// API of gif_lib has changed recenly +#ifndef GIFLIB_MAJOR +#define GIFLIB_MAJOR 0 +#endif +#if GIFLIB_MAJOR > 5 || GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1 +static int dgif_error_code; // Scratch pad only, no locking needed +#define DGIF_OPEN(_userptr, _readfunc) DGifOpen(_userptr, _readfunc, &dgif_error_code) +#define DGIF_CLOSE_FILE(_gif) DGifCloseFile(_gif, &dgif_error_code) +#else +#define DGIF_OPEN(_userptr, _readfunc) DGifOpen(_userptr, _readfunc) +#define DGIF_CLOSE_FILE(_gif) DGifCloseFile(_gif) +#endif + struct libungif_read_data { GifFileType *gif; int transparent_index; @@ -37,7 +50,7 @@ libungif_read_cancel(struct image_io *io) DBG("libungif_read_cancel()"); struct libungif_read_data *rd = io->read_data; - DGifCloseFile(rd->gif); + DGIF_CLOSE_FILE(rd->gif); } int @@ -47,7 +60,7 @@ libungif_read_header(struct image_io *io) /* Create libungif structure */ GifFileType *gif; - if (unlikely(!(gif = DGifOpen(io->fastbuf, libungif_read_func)))) + if (unlikely(!(gif = DGIF_OPEN(io->fastbuf, libungif_read_func)))) { IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Cannot create libungif structure."); return 0; @@ -60,7 +73,7 @@ libungif_read_header(struct image_io *io) if (unlikely(DGifSlurp(gif) != GIF_OK)) { IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Gif read failed."); - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } @@ -68,7 +81,7 @@ libungif_read_header(struct image_io *io) if (unlikely(!gif->ImageCount)) { IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "There are no images in gif file."); - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } @@ -78,14 +91,14 @@ libungif_read_header(struct image_io *io) image->ImageDesc.Width > (int)image_max_dim || image->ImageDesc.Height > (int)image_max_dim)) { IMAGE_ERROR(io->context, IMAGE_ERROR_INVALID_DIMENSIONS, "Invalid gif dimensions."); - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } ColorMapObject *color_map = image->ImageDesc.ColorMap ? : gif->SColorMap; if (unlikely(!color_map)) { IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Missing palette."); - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } io->cols = image->ImageDesc.Width; @@ -93,7 +106,7 @@ libungif_read_header(struct image_io *io) if (unlikely((io->number_of_colors = color_map->ColorCount) > 256)) { IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Too many gif colors."); - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } io->flags = COLOR_SPACE_RGB | IMAGE_IO_HAS_PALETTE; @@ -109,7 +122,7 @@ libungif_read_header(struct image_io *io) if (unlikely(e->ByteCount != 4)) { IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Invalid graphics control extension."); - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } byte *b = e->Bytes; @@ -153,7 +166,7 @@ libungif_read_data(struct image_io *io) read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_RGB; if (unlikely(!image_io_read_data_prepare(&rdi, io, image->ImageDesc.Width, image->ImageDesc.Height, read_flags))) { - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } @@ -186,7 +199,7 @@ libungif_read_data(struct image_io *io) if (rd->transparent_index >= 0 && (io->flags & IMAGE_IO_USE_BACKGROUND)) if (!color_put(io->context, &io->background_color, pal + rd->transparent_index, COLOR_SPACE_GRAYSCALE)) { - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } # define DO_ROW_END do{ \ @@ -242,7 +255,7 @@ libungif_read_data(struct image_io *io) if (rd->transparent_index >= 0 && (io->flags & IMAGE_IO_USE_BACKGROUND)) if (!color_put(io->context, &io->background_color, pal + 4 * rd->transparent_index, COLOR_SPACE_RGB)) { - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); return 0; } # define IMAGE_WALK_PREFIX(x) walk_##x @@ -286,7 +299,7 @@ libungif_read_data(struct image_io *io) } /* Destroy libungif structure */ - DGifCloseFile(gif); + DGIF_CLOSE_FILE(gif); /* Finish image */ return image_io_read_data_finish(&rdi, io); -- 2.39.2