1 Support newer GIFLIB versions
3 This is an adapted upstream patch. This patch is incomplete so a new
4 patch needs to be added after this one.
8 https://github.com/pigoz/mplayer-svn/commit/a0ddaef5457e222dade386901bf448c5e3ac7b89
10 Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
12 From a0ddaef5457e222dade386901bf448c5e3ac7b89 Mon Sep 17 00:00:00 2001
13 From: al <al@b3059339-0415-0410-9bf9-f77b7e298cf2>
14 Date: Sat, 27 Jul 2013 21:16:06 +0000
15 Subject: [PATCH] Support newer GIFLIB versions
17 Work with GIFLIB version >= 4.2
19 Several functions have been renamed or changed in signature.
21 GIFLIB is used by vo gif89a and demuxer gif.
23 Note about GIFLIB Version 4.2:
24 It does not work with vanilla GIFLIB 4.2 but it works with
25 versions that have re-added quantize support like e.g. the
26 package from arch linux.
28 Note about GIFLIB Version 5:
29 The newly added GCB functions use size_t but the necessary
30 standard headers are not included in gif_lib.h . To workaround
33 * configure: use statement_check_broken to include stdlib.h
34 * vo gif89: include gif_lib.h after stdlib.h
35 * demuxer gif: no workaround needed,
36 gif_lib.h is already included after stdlib.h
40 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@36367 b3059339-0415-0410-9bf9-f77b7e298cf2
43 libmpdemux/demux_gif.c | 44 +++++++++++++++++++++++++++++++++++---------
44 libvo/vo_gif89a.c | 35 ++++++++++++++++++++++++-----------
45 3 files changed, 61 insertions(+), 21 deletions(-)
47 diff --git a/configure b/configure
48 index e9152a8..4cd378d 100755
51 @@ -4938,6 +4938,7 @@ if test "$_gif" = auto ; then
53 for ld_gif in "-lungif" "-lgif" ; do
54 statement_check gif_lib.h 'QuantizeBuffer(0, 0, 0, 0, 0, 0, 0, 0)' $ld_gif && _gif=yes && break
55 + statement_check_broken stdlib.h gif_lib.h 'GifQuantizeBuffer(0, 0, 0, 0, 0, 0, 0, 0)' $ld_gif && _gif=yes && break
60 diff --git a/libmpdemux/demux_gif.c b/libmpdemux/demux_gif.c
61 index 804ce8c..0a11322 100644
62 --- a/libmpdemux/demux_gif.c
63 +++ b/libmpdemux/demux_gif.c
64 @@ -45,6 +45,32 @@ typedef struct {
66 #define GIF_SIGNATURE (('G' << 16) | ('I' << 8) | 'F')
68 +#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5
69 +#define DGifOpen(a, b) DGifOpen(a, b, NULL)
70 +#define DGifOpenFileHandle(a) DGifOpenFileHandle(a, NULL)
71 +#define GifError() (gif ? gif->Error : 0)
72 +#define GifErrorString() GifErrorString(gif->Error)
75 +/* >= 4.2 prior GIFLIB did not have MAJOR/MINOR defines */
76 +#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 4
77 +static void print_gif_error(GifFileType *gif)
79 + int err = GifError();
80 + char *err_str = GifErrorString();
83 + mp_msg(MSGT_DEMUX, MSGL_ERR, "\n[gif] GIF-LIB error: %s.\n", err_str);
85 + mp_msg(MSGT_DEMUX, MSGL_ERR, "\n[gif] GIF-LIB undefined error %d.\n", err);
88 +static void print_gif_error(GifFileType *gif)
94 #ifndef CONFIG_GIF_TVT_HACK
95 // not supported by certain versions of the library
96 static int my_read_gif(GifFileType *gif, uint8_t *buf, int len)
97 @@ -94,14 +120,14 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
99 while (type != IMAGE_DESC_RECORD_TYPE) {
100 if (DGifGetRecordType(gif, &type) == GIF_ERROR) {
102 + print_gif_error(priv->gif);
105 if (type == TERMINATE_RECORD_TYPE)
107 if (type == SCREEN_DESC_RECORD_TYPE) {
108 if (DGifGetScreenDesc(gif) == GIF_ERROR) {
110 + print_gif_error(priv->gif);
114 @@ -109,7 +135,7 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
116 unsigned char *p = NULL;
117 if (DGifGetExtension(gif, &code, &p) == GIF_ERROR) {
119 + print_gif_error(priv->gif);
123 @@ -138,7 +164,7 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
124 comments[length] = 0;
125 printf("%s", comments);
126 if (DGifGetExtensionNext(gif, &p) == GIF_ERROR) {
128 + print_gif_error(priv->gif);
132 @@ -146,7 +172,7 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
135 if (DGifGetExtensionNext(gif, &p) == GIF_ERROR) {
137 + print_gif_error(priv->gif);
141 @@ -154,7 +180,7 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
144 if (DGifGetImageDesc(gif) == GIF_ERROR) {
146 + print_gif_error(priv->gif);
150 @@ -167,7 +193,7 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
151 memset(dp->buffer, gif->SBackGroundColor, priv->w * priv->h);
153 if (DGifGetLine(gif, buf, len) == GIF_ERROR) {
155 + print_gif_error(priv->gif);
157 free_demux_packet(dp);
159 @@ -261,7 +287,7 @@ static demuxer_t* demux_open_gif(demuxer_t* demuxer)
160 gif = DGifOpen(demuxer->stream, my_read_gif);
164 + print_gif_error(NULL);
168 @@ -303,7 +329,7 @@ static void demux_close_gif(demuxer_t* demuxer)
169 gif_priv_t *priv = demuxer->priv;
171 if (priv->gif && DGifCloseFile(priv->gif) == GIF_ERROR)
173 + print_gif_error(priv->gif);
177 diff --git a/libvo/vo_gif89a.c b/libvo/vo_gif89a.c
178 index b808f81..160291a 100644
179 --- a/libvo/vo_gif89a.c
180 +++ b/libvo/vo_gif89a.c
182 * entire argument being interpretted as the filename.
185 -#include <gif_lib.h>
192 +#include <gif_lib.h>
195 #include "subopt-helper.h"
196 #include "video_out.h"
197 @@ -69,6 +69,12 @@ static const vo_info_t info = {
199 const LIBVO_EXTERN(gif89a)
201 +#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5
202 +#define EGifOpenFileName(a, b) EGifOpenFileName(a, b, NULL)
203 +#define MakeMapObject GifMakeMapObject
204 +#define FreeMapObject GifFreeMapObject
205 +#define QuantizeBuffer GifQuantizeBuffer
208 // how many frames per second we are aiming for during output.
209 static float target_fps;
210 @@ -156,7 +162,7 @@ static int config(uint32_t s_width, uint32_t s_height, uint32_t d_width,
211 uint32_t d_height, uint32_t flags, char *title,
215 +#if defined CONFIG_GIF_4 || GIFLIB_MAJOR >= 5
216 // these are control blocks for the gif looping extension.
217 char LB1[] = "NETSCAPE2.0";
218 char LB2[] = { 1, 0, 0 };
219 @@ -185,23 +191,25 @@ static int config(uint32_t s_width, uint32_t s_height, uint32_t d_width,
223 + new_gif = EGifOpenFileName(gif_filename, 0);
224 + if (new_gif == NULL) {
225 + mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: error opening file \"%s\" for output.\n", gif_filename);
229 +#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5
230 + EGifSetGifVersion(new_gif, 1);
231 +#elif defined CONFIG_GIF_4
232 // the EGifSetGifVersion line causes segfaults in certain
233 // earlier versions of libungif. i don't know exactly which,
234 // but certainly in all those before v4. if you have problems,
235 // you need to upgrade your gif library.
237 EGifSetGifVersion("89a");
239 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Your version of libungif needs to be upgraded.\n");
240 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Some functionality has been disabled.\n");
243 - new_gif = EGifOpenFileName(gif_filename, 0);
244 - if (new_gif == NULL) {
245 - mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: error opening file \"%s\" for output.\n", gif_filename);
249 slice_data = malloc(img_width * img_height * 3);
250 if (slice_data == NULL) {
251 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n");
252 @@ -231,7 +239,12 @@ static int config(uint32_t s_width, uint32_t s_height, uint32_t d_width,
254 // set the initial width and height info.
255 EGifPutScreenDesc(new_gif, s_width, s_height, 256, 0, reduce_cmap);
257 +#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5
258 + EGifPutExtensionLeader(new_gif, 0xFF);
259 + EGifPutExtensionBlock(new_gif, 11, LB1);
260 + EGifPutExtensionBlock(new_gif, 3, LB2);
261 + EGifPutExtensionTrailer(new_gif);
262 +#elif defined CONFIG_GIF_4
263 // version 3 of libungif does not support multiple control blocks.
264 // looping requires multiple control blocks.
265 // therefore, looping is only enabled for v4 and up.