support for giflib 5.x (untested)
Stefan Schuermans

Stefan Schuermans commited on 2016-12-30 21:26:42
Showing 5 changed files, with 62 additions and 24 deletions.

... ...
@@ -12,6 +12,12 @@
12 12
 #include <BlinkenLib/BlinkenMovie.h>
13 13
 #include <BlinkenLib/BlinkenGif.h>
14 14
 
15
+#ifdef BLINKENLIB_CFG_GIF5
16
+# define GIF5_err , &giferr
17
+#else
18
+# define GIF5_err
19
+#endif
20
+
15 21
 // get color from GIF color map
16 22
 static void BlinkenGifGetColor(ColorMapObject *pMap, int idx, int transparent,
17 23
                                unsigned char *r, unsigned char *g,
... ...
@@ -75,19 +81,22 @@ stBlinkenMovie *BlinkenGifLoad(const char *pFilename)
75 81
   ExtensionBlock *pEx;
76 82
   stBlinkenMovie *pMovie;
77 83
   stBlinkenFrame *pBack, *pFrame;
84
+#ifdef BLINKENLIB_CFG_GIF5
85
+  int giferr;
86
+#endif
78 87
 
79 88
   if (pFilename == NULL)
80 89
     return NULL;
81 90
 
82 91
   // open GIF file for decoding
83
-  gif = DGifOpenFileName(pFilename);
92
+  gif = DGifOpenFileName(pFilename GIF5_err);
84 93
   if (gif == NULL) {
85 94
     return NULL;
86 95
   }
87 96
 
88 97
   // read GIF file
89 98
   if (DGifSlurp(gif) != GIF_OK) {
90
-    DGifCloseFile(gif);
99
+    DGifCloseFile(gif GIF5_err);
91 100
     return NULL;
92 101
   }
93 102
   height = gif->SHeight;
... ...
@@ -99,7 +108,7 @@ stBlinkenMovie *BlinkenGifLoad(const char *pFilename)
99 108
   // create movie
100 109
   pMovie = BlinkenMovieNew(height, width, 3, 255);
101 110
   if (! pMovie) {
102
-    DGifCloseFile(gif);
111
+    DGifCloseFile(gif GIF5_err);
103 112
     return NULL;
104 113
   }
105 114
 
... ...
@@ -107,7 +116,7 @@ stBlinkenMovie *BlinkenGifLoad(const char *pFilename)
107 116
   pBack = BlinkenFrameNew(height, width, 3, 255, 1);
108 117
   if (! pBack) {
109 118
     BlinkenMovieFree(pMovie);
110
-    DGifCloseFile(gif);
119
+    DGifCloseFile(gif GIF5_err);
111 120
     return NULL;
112 121
   }
113 122
   for (y = 0; y < height; ++y) {
... ...
@@ -191,7 +200,7 @@ stBlinkenMovie *BlinkenGifLoad(const char *pFilename)
191 200
   BlinkenFrameFree(pBack);
192 201
 
193 202
   // close GIF file
194
-  DGifCloseFile(gif);
203
+  DGifCloseFile(gif GIF5_err);
195 204
 
196 205
   return pMovie;
197 206
 }
... ...
@@ -207,6 +216,9 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename)
207 216
   SavedImage *pImg;
208 217
   GifImageDesc *pDesc;
209 218
   ExtensionBlock *pEx;
219
+#ifdef BLINKENLIB_CFG_GIF5
220
+  int giferr;
221
+#endif
210 222
 
211 223
   if (pMovie == NULL || pFilename == NULL)
212 224
     return -1; // error
... ...
@@ -238,7 +250,7 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename)
238 250
   }
239 251
 
240 252
   // open GIF file for encoding
241
-  gif = EGifOpenFileName(pFilename, 0);
253
+  gif = EGifOpenFileName(pFilename, 0 GIF5_err);
242 254
   if (gif == NULL) {
243 255
     BlinkenMovieFree(pOutMovie);
244 256
     return -1; // error
... ...
@@ -260,9 +272,13 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename)
260 272
   gif->UserData = NULL;
261 273
 
262 274
   // create color map
275
+#ifdef BLINKENLIB_CFG_GIF5
276
+  gif->SColorMap = GifMakeMapObject(256, NULL);
277
+#else
263 278
   gif->SColorMap = MakeMapObject(256, NULL);
279
+#endif
264 280
   if (gif->SColorMap == NULL) {
265
-    EGifCloseFile(gif);
281
+    EGifCloseFile(gif GIF5_err);
266 282
     BlinkenMovieFree(pOutMovie);
267 283
     return -1; // error
268 284
   }
... ...
@@ -308,7 +324,7 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename)
308 324
   // create space for saved images
309 325
   gif->SavedImages = calloc(frameCnt, sizeof(SavedImage));
310 326
   if (gif->SavedImages == NULL) {
311
-    EGifCloseFile(gif);
327
+    EGifCloseFile(gif GIF5_err);
312 328
     BlinkenMovieFree(pOutMovie);
313 329
     return -1; // error
314 330
   }
... ...
@@ -368,7 +384,7 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename)
368 384
     pImg->RasterBits = calloc(pDesc->Width * pDesc->Height,
369 385
                               sizeof(unsigned char));
370 386
     if (pImg->RasterBits == NULL) {
371
-      EGifCloseFile(gif);
387
+      EGifCloseFile(gif GIF5_err);
372 388
       BlinkenMovieFree(pOutMovie);
373 389
       return -1; // error
374 390
     }
... ...
@@ -386,11 +402,13 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename)
386 402
     } // for y
387 403
 
388 404
     // allocate and fill extension block with delay and disposal mode
405
+#ifndef BLINKENLIB_CFG_GIF5
389 406
     pImg->Function = 0;
407
+#endif
390 408
     pImg->ExtensionBlockCount = 1;
391 409
     pImg->ExtensionBlocks = calloc(1, sizeof(ExtensionBlock));
392 410
     if (pImg->ExtensionBlocks == NULL) {
393
-      EGifCloseFile(gif);
411
+      EGifCloseFile(gif GIF5_err);
394 412
       BlinkenMovieFree(pOutMovie);
395 413
       return -1; // error
396 414
     }
... ...
@@ -399,7 +417,7 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename)
399 417
     pEx->ByteCount = 4;
400 418
     pEx->Bytes = calloc(pEx->ByteCount, sizeof (unsigned char));
401 419
     if (pEx->Bytes == NULL) {
402
-      EGifCloseFile(gif);
420
+      EGifCloseFile(gif GIF5_err);
403 421
       BlinkenMovieFree(pOutMovie);
404 422
       return -1; // error
405 423
     }
... ...
@@ -10,8 +10,10 @@ BIN_LFLAGS:=-L. -Wl,-rpath,'$$ORIGIN'
10 10
 AR:=ar
11 11
 RANLIB:=ranlib
12 12
 
13
+ifneq ($(MAKECMDGOALS),clean)
13 14
 include ../version.mk
14 15
 include ../config/config.mk
16
+endif
15 17
 
16 18
 ifeq ($(BLINKENLIB_CFG_OSX),1)
17 19
 SHLIBEXT:=dylib
... ...
@@ -7,37 +7,43 @@ CC:=gcc
7 7
 INCDIR:=-I/sw/include
8 8
 LIBDIR:=-L/sw/lib
9 9
 
10
+CFGS:=$(addsuffix .cfg, osx mng gif gif4 gif5)
11
+
10 12
 .phony: all clean
11 13
 
12 14
 all: config.cfg config.mk config.h
13 15
 
14 16
 osx.cfg:
15
-	echo "OSX=" | tr -d '\n' >osx.cfg
16
-	(if [ "$$(uname -s)" == "Darwin" ]; then echo "1"; else echo "0"; fi) >>osx.cfg
17
+	echo "OSX=" | tr -d '\n' >$@
18
+	(if [ "$$(uname -s)" == "Darwin" ]; then echo "1"; else echo "0"; fi) >>$@
17 19
 
18 20
 mng.cfg:
19
-	echo "MNG=" | tr -d '\n' >mng.cfg
20
-	(($(CC) $(INCDIR) $(LIBDIR) -o mng mng.c -lmng && ./mng && echo "1") || echo "0") >>mng.cfg
21
+	echo "MNG=" | tr -d '\n' >$@
22
+	(($(CC) $(INCDIR) $(LIBDIR) -o mng mng.c -lmng && ./mng && echo "1") || echo "0") >>$@
21 23
 	rm -f mng
22 24
 
23
-gif.cfg:
24
-	echo "GIF=" | tr -d '\n' >gif.cfg
25
-	(($(CC) $(INCDIR) $(LIBDIR) -o gif gif.c -lgif && ./gif && echo "1") || echo "0") >>gif.cfg
26
-	rm -f gif
25
+gif%.cfg:
26
+	echo "GIF$*=" | tr -d '\n' >$@
27
+	(($(CC) $(INCDIR) $(LIBDIR) -o gif$* gif$*.c -lgif && ./gif$* && echo "1") || echo "0") >>$@
28
+	rm -f gif$*
29
+
30
+gif.cfg: gif4.cfg gif5.cfg
31
+	echo "GIF=" | tr -d '\n' >$@
32
+	((cat $^ | grep -q 1 && echo "1") || echo "0") >>$@
27 33
 
28
-config.cfg: osx.cfg mng.cfg gif.cfg
34
+config.cfg: $(CFGS)
29 35
 	cat $+ >config.cfg
30 36
 
31 37
 config.mk: config.cfg
32
-	sed 's/^\([A-Z]*\)=\([01]\)$$/BLINKENLIB_CFG_\1:=\2/' <$< >$@
38
+	sed 's/^\([A-Z0-9]*\)=\([01]\)$$/BLINKENLIB_CFG_\1:=\2/' <$< >$@
33 39
 
34 40
 config.h: config.cfg Makefile ../version.mk
35
-	sed 's/^\([A-Z]*\)=0$$/#undef BLINKENLIB_CFG_\1/;s/^\([A-Z]*\)=1$$/#define BLINKENLIB_CFG_\1/' <$< >$@
41
+	sed 's/^\([A-Z0-9]*\)=0$$/#undef BLINKENLIB_CFG_\1/;s/^\([A-Z0-9]*\)=1$$/#define BLINKENLIB_CFG_\1/' <$< >$@
36 42
 	echo '#define BLINKENLIB_CONFIG "' | tr -d '\n' >>$@
37
-	sed 's/^\([A-Z]*\)=0$$/\1-/;s/^\([A-Z]*\)=1$$/\1+/' <$< | tr '\n' ' ' | sed 's/ *$$//' | tr -d '\n' >>$@
43
+	sed 's/^\([A-Z0-9]*\)=0$$/\1-/;s/^\([A-Z0-9]*\)=1$$/\1+/' <$< | tr '\n' ' ' | sed 's/ *$$//' | tr -d '\n' >>$@
38 44
 	echo '"' >>$@
39 45
 	grep '^VERSION_[A-Z]*:=[0-9]*' ../version.mk | sed 's/^/#define BLINKENLIB_/;s/:=/ /' >>$@
40 46
 
41 47
 clean:
42
-	rm -f *.cfg config.mk config.h
48
+	rm -f $(CFGS) config.mk config.h
43 49
 
... ...
@@ -0,0 +1,12 @@
1
+#include <gif_lib.h>
2
+
3
+int main()
4
+{
5
+  GifFileType *gif;
6
+
7
+  gif = DGifOpenFileName("x.gif", NULL);
8
+  if (gif)
9
+    DGifCloseFile(gif, NULL);
10
+
11
+  return 0;
12
+}
0 13