diff libvo/vo_gif89a.c @ 36271:1a889d9a4540

Support newer GIFLIB versions Work with GIFLIB version >= 4.2 Several functions have been renamed or changed in signature. GIFLIB is used by vo gif89a and demuxer gif. Note about GIFLIB Version 4.2: It does not work with vanilla GIFLIB 4.2 but it works with versions that have re-added quantize support like e.g. the package from arch linux. Note about GIFLIB Version 5: The newly added GCB functions use size_t but the necessary standard headers are not included in gif_lib.h . To workaround this: * configure: use statement_check_broken to include stdlib.h * vo gif89: include gif_lib.h after stdlib.h * demuxer gif: no workaround needed, gif_lib.h is already included after stdlib.h
author al
date Sat, 27 Jul 2013 21:16:06 +0000
parents ddb45e9443ec
children 5d3f93051de9
line wrap: on
line diff
--- a/libvo/vo_gif89a.c	Mon Jul 22 13:05:13 2013 +0000
+++ b/libvo/vo_gif89a.c	Sat Jul 27 21:16:06 2013 +0000
@@ -44,13 +44,13 @@
  * entire argument being interpretted as the filename.
  */
 
-#include <gif_lib.h>
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
+#include <gif_lib.h>
+
 #include "config.h"
 #include "subopt-helper.h"
 #include "video_out.h"
@@ -69,6 +69,12 @@
 
 const LIBVO_EXTERN(gif89a)
 
+#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5
+#define EGifOpenFileName(a, b) EGifOpenFileName(a, b, NULL)
+#define MakeMapObject GifMakeMapObject
+#define FreeMapObject GifFreeMapObject
+#define QuantizeBuffer GifQuantizeBuffer
+#endif
 
 // how many frames per second we are aiming for during output.
 static float target_fps;
@@ -156,7 +162,7 @@
 		uint32_t d_height, uint32_t flags, char *title,
 		uint32_t format)
 {
-#ifdef CONFIG_GIF_4
+#if defined CONFIG_GIF_4 || GIFLIB_MAJOR >= 5
 	// these are control blocks for the gif looping extension.
 	char LB1[] = "NETSCAPE2.0";
 	char LB2[] = { 1, 0, 0 };
@@ -185,23 +191,25 @@
 		return 1;
 	}
 
+	new_gif = EGifOpenFileName(gif_filename, 0);
+	if (new_gif == NULL) {
+		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: error opening file \"%s\" for output.\n", gif_filename);
+		return 1;
+	}
+
+#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5
+	EGifSetGifVersion(new_gif, 1);
+#elif defined CONFIG_GIF_4
 	// the EGifSetGifVersion line causes segfaults in certain
 	// earlier versions of libungif.  i don't know exactly which,
 	// but certainly in all those before v4.  if you have problems,
 	// you need to upgrade your gif library.
-#ifdef CONFIG_GIF_4
 	EGifSetGifVersion("89a");
 #else
 	mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Your version of libungif needs to be upgraded.\n");
 	mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Some functionality has been disabled.\n");
 #endif
 
-	new_gif = EGifOpenFileName(gif_filename, 0);
-	if (new_gif == NULL) {
-		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: error opening file \"%s\" for output.\n", gif_filename);
-		return 1;
-	}
-
 	slice_data = malloc(img_width * img_height * 3);
 	if (slice_data == NULL) {
 		mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n");
@@ -231,7 +239,12 @@
 
 	// set the initial width and height info.
 	EGifPutScreenDesc(new_gif, s_width, s_height, 256, 0, reduce_cmap);
-#ifdef CONFIG_GIF_4
+#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5
+	EGifPutExtensionLeader(new_gif, 0xFF);
+	EGifPutExtensionBlock(new_gif, 11, LB1);
+	EGifPutExtensionBlock(new_gif, 3, LB2);
+	EGifPutExtensionTrailer(new_gif);
+#elif defined CONFIG_GIF_4
 	// version 3 of libungif does not support multiple control blocks.
 	// looping requires multiple control blocks.
 	// therefore, looping is only enabled for v4 and up.