summaryrefslogtreecommitdiff
path: root/x11/xplanet/patches/patch-src_libimage_gif.c
blob: a0c76d23e2fd3a651f93182b3fa0eb216991c336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
$NetBSD: patch-src_libimage_gif.c,v 1.1 2013/07/06 08:00:47 ryoon Exp $

* Fix build with giflib 5.0.

--- src/libimage/gif.c.orig	2006-03-25 22:50:51.000000000 +0000
+++ src/libimage/gif.c
@@ -21,8 +21,27 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#ifndef	TRUE
+#define	TRUE	1
+#endif
+#ifndef	FALSE
+#define	FALSE	0
+#endif
 #include <gif_lib.h>
 
+/* from util/qprintf.c of giflib 5.0.4 */
+int ErrorCode;
+void
+PrintGifError(int ErrorCode)
+{
+    char *Err = GifErrorString(ErrorCode);
+
+    if (Err != NULL)
+	fprintf(stderr, "GIF-LIB error: %s.\n", Err);
+    else
+	fprintf(stderr, "GIF-LIB undefined error %d.\n", ErrorCode);
+}
+
 /*
   A lot of this is based on the gif2rgb and rgb2gif codes in the libungif 
   distribution. 
@@ -42,11 +61,11 @@ read_gif(const char *filename, int *widt
     int color_index;
     unsigned char *ptr = NULL;
 
-    infile = DGifOpenFileName(filename);
+    infile = DGifOpenFileName(filename, &ErrorCode);
 
     if (infile == NULL)
     {
-        PrintGifError();
+        PrintGifError(ErrorCode);
         return(0);
     }
 
@@ -54,7 +73,7 @@ read_gif(const char *filename, int *widt
     {
         if (DGifGetRecordType(infile, &record_type) == GIF_ERROR) 
         {
-            PrintGifError();
+            PrintGifError(ErrorCode);
             return(0);
         }
 
@@ -63,7 +82,7 @@ read_gif(const char *filename, int *widt
         case IMAGE_DESC_RECORD_TYPE:
             if (DGifGetImageDesc(infile) == GIF_ERROR)
             {
-                PrintGifError();
+                PrintGifError(ErrorCode);
                 return(0);
             }
 
@@ -107,14 +126,14 @@ read_gif(const char *filename, int *widt
             GifByteType *ext;
             if (DGifGetExtension(infile, &ext_code, &ext) == GIF_ERROR) 
             {
-                PrintGifError();
+                PrintGifError(ErrorCode);
                 return(0);
             }
             while (ext != NULL) 
             {
                 if (DGifGetExtensionNext(infile, &ext) == GIF_ERROR) 
                 {
-                    PrintGifError();
+                    PrintGifError(ErrorCode);
                     return(0);
                 }
             }
@@ -178,7 +197,7 @@ write_gif(const char *filename, int widt
         return(0);
     }
 
-    colormap = MakeMapObject(colormap_size, NULL);
+    colormap = GifMakeMapObject(colormap_size, NULL);
 
     for (i = 0; i < width * height; i++)
     {
@@ -187,10 +206,10 @@ write_gif(const char *filename, int widt
         blue[i]  = (GifByteType) rgb[3*i+2];
     }
   
-    if (QuantizeBuffer(width, height, &colormap_size, red, green, blue,   
+    if (GifQuantizeBuffer(width, height, &colormap_size, red, green, blue,   
                        buffer, colormap->Colors) == GIF_ERROR)
     {
-        PrintGifError();
+        PrintGifError(ErrorCode);
         return(0);
     }
 
@@ -198,24 +217,24 @@ write_gif(const char *filename, int widt
     free(green);
     free(blue);
 
-    outfile = EGifOpenFileName((char *) filename, FALSE);
+    outfile = EGifOpenFileName((char *) filename, FALSE, &ErrorCode);
     if (outfile == NULL)
     {
-        PrintGifError();
+        PrintGifError(ErrorCode);
         return(0);
     }
 
     if (EGifPutScreenDesc(outfile, width, height, colormap_size, 0, colormap)
         == GIF_ERROR)
     {
-        PrintGifError();
+        PrintGifError(ErrorCode);
         return(0);
     }
 
     if (EGifPutImageDesc(outfile, 0, 0, width, height, FALSE, NULL)
         == GIF_ERROR)
     {
-        PrintGifError();
+        PrintGifError(ErrorCode);
         return(0);
     }
 
@@ -224,7 +243,7 @@ write_gif(const char *filename, int widt
     {
         if (EGifPutLine(outfile, ptr, width) == GIF_ERROR)
         {
-            PrintGifError();
+            PrintGifError(ErrorCode);
             return(0);
         }
         ptr += width;
@@ -233,7 +252,7 @@ write_gif(const char *filename, int widt
     EGifSpew(outfile);
 
     if (EGifCloseFile(outfile) == GIF_ERROR) 
-        PrintGifError();
+        PrintGifError(ErrorCode);
 
     free(buffer);