]> mj.ucw.cz Git - libucw.git/commitdiff
Images: Cope with API changes in recent versions of libgif
authorMartin Mares <mj@ucw.cz>
Mon, 12 Feb 2018 23:22:06 +0000 (00:22 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 12 Feb 2018 23:22:06 +0000 (00:22 +0100)
images/io-libungif.c

index bf97f743e11b5f009b1608090fa0bdcd98c8b467..f444fc5e6f7d1b5c623d0386eada3a9d95f23056 100644 (file)
 
 #include <gif_lib.h>
 
 
 #include <gif_lib.h>
 
+// 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;
 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;
   DBG("libungif_read_cancel()");
 
   struct libungif_read_data *rd = io->read_data;
-  DGifCloseFile(rd->gif);
+  DGIF_CLOSE_FILE(rd->gif);
 }
 
 int
 }
 
 int
@@ -47,7 +60,7 @@ libungif_read_header(struct image_io *io)
 
   /* Create libungif structure */
   GifFileType *gif;
 
   /* 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;
     {
       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.");
   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;
     }
 
       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.");
   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;
     }
 
       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.");
       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.");
       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;
       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.");
   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;
       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.");
          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;
               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)))
     {
     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;
     }
 
       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))
              {
          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{ \
                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))
              {
          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
                return 0;
              }
 #        define IMAGE_WALK_PREFIX(x) walk_##x
@@ -286,7 +299,7 @@ libungif_read_data(struct image_io *io)
     }
 
   /* Destroy libungif structure */
     }
 
   /* Destroy libungif structure */
-  DGifCloseFile(gif);
+  DGIF_CLOSE_FILE(gif);
 
   /* Finish image */
   return image_io_read_data_finish(&rdi, io);
 
   /* Finish image */
   return image_io_read_data_finish(&rdi, io);