summaryrefslogtreecommitdiff
blob: 32037d97546dce82ec85164ef884835b9e2f06ab (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
diff -Naurd libAfterImage-1.20.orig/export.c libAfterImage-1.20/export.c
--- libAfterImage-1.20.orig/export.c	2016-05-01 11:44:19.000000000 +0300
+++ libAfterImage-1.20/export.c	2016-05-02 10:57:59.688984491 +0300
@@ -1048,6 +1048,9 @@
 	Bool new_image = True ;
 	START_TIME(started);
 	int cmap_size = 1;
+#if (GIFLIB_MAJOR>=5)
+	int errcode;
+#endif
 #define GIF_NETSCAPE_EXT_BYTES 3
 	unsigned char netscape_ext_bytes[GIF_NETSCAPE_EXT_BYTES] = { 0x1, 0x0, 0x0};
 #define GIF_GCE_BYTES 4	
@@ -1086,10 +1089,18 @@
 
 	while( cmap_size < 256 && cmap_size < (int)cmap.count+(gce_bytes[0]&0x01) )
 		cmap_size = cmap_size<<1 ;
+#if (GIFLIB_MAJOR>=5)
+	if( (gif_cmap = GifMakeMapObject(cmap_size, NULL )) == NULL )
+#else
 	if( (gif_cmap = MakeMapObject(cmap_size, NULL )) == NULL )
+#endif
 	{
 		free( mapped_im );
+#if (GIFLIB_MAJOR>=5)
+		ASIM_PrintGifError(E_GIF_ERR_NOT_ENOUGH_MEM);
+#else
 		ASIM_PrintGifError();
+#endif
 		return False;
 	}
 	memcpy( &(gif_cmap->Colors[0]), &(cmap.entries[0]), MIN(cmap.count,(unsigned int)cmap_size)*3 );
@@ -1101,13 +1112,25 @@
 		SavedImage *images = NULL ;
 		int count = 0 ;
 		/* TODO: do something about multiimage files !!! */
+#if (GIFLIB_MAJOR>=5)
+		gif = open_gif_read(infile, &errcode);
+#else
 		gif = open_gif_read(infile);
+#endif
 		if( gif == NULL || get_gif_saved_images(gif, -1, &images, &count) == GIF_ERROR)
 		{
+#if (GIFLIB_MAJOR>=5)
+			ASIM_PrintGifError(errcode);
+#else
 			ASIM_PrintGifError();
+#endif
 			if( gif )
 			{
+#if (GIFLIB_MAJOR>=5)
+				DGifCloseFile(gif, &errcode);
+#else
 				DGifCloseFile(gif);
+#endif
 				gif = NULL ;
 			}
 			if (infile)
@@ -1123,14 +1146,22 @@
 			gif_src = *gif ;
 			gif->SColorMap = NULL ;
 			gif->Image.ColorMap = NULL ;
+#if (GIFLIB_MAJOR>=5)
+            DGifCloseFile(gif, &errcode);
+#else
 			DGifCloseFile(gif);
+#endif
 			gif = NULL;
 			fclose (infile);
 			infile = NULL;
 			outfile = open_writeable_image_file( path );
 
 			if (outfile)
+#if (GIFLIB_MAJOR>=5)
+				gif = EGifOpenFileHandle(fileno(outfile), &errcode);
+#else
 				gif = EGifOpenFileHandle(fileno(outfile));
+#endif
 				
 			if (gif)
 			{
@@ -1141,26 +1172,46 @@
 									   gif_src.SColorMap )) == GIF_OK )
 					status = write_gif_saved_images( gif, images, count );
 				if( status != GIF_OK )
+#if (GIFLIB_MAJOR>=5)
+					ASIM_PrintGifError(status);
+#else
 					ASIM_PrintGifError();
+#endif
 			}
 			if (gif_src.SColorMap)
 			{  /* we only want to save private colormap if it is any different from
 			    * screen colormap ( saves us  768 bytes per image ) */
 				if( gif_cmap->ColorCount == gif_src.SColorMap->ColorCount )
 					dont_save_cmap = ( memcmp( gif_cmap->Colors, gif_src.SColorMap->Colors, gif_cmap->ColorCount*sizeof(GifColorType)) == 0 );
+#if (GIFLIB_MAJOR>=5)
+				GifFreeMapObject(gif_src.SColorMap);
+#else
 				FreeMapObject(gif_src.SColorMap);
+#endif
 			}
 			if (gif)
 			{
 				EGifPutExtension(gif, GRAPHICS_EXT_FUNC_CODE, GIF_GCE_BYTES, &(gce_bytes[0]));
 				if( get_flags( params->gif.flags, EXPORT_ANIMATION_REPEATS ) )
 				{
+#if (GIFLIB_MAJOR>=5)
+					EGifPutExtensionLeader(gif, APPLICATION_EXT_FUNC_CODE);
+					EGifPutExtensionBlock(gif, 11, "NETSCAPE2.0");
+					EGifPutExtensionBlock(gif, GIF_NETSCAPE_EXT_BYTES, &(netscape_ext_bytes[0]));
+					EGifPutExtensionTrailer(gif);
+#else
 					EGifPutExtensionFirst(gif, APPLICATION_EXT_FUNC_CODE, 11, "NETSCAPE2.0");
 					EGifPutExtensionLast(gif, 0, GIF_NETSCAPE_EXT_BYTES, &(netscape_ext_bytes[0]));
+#endif
 				}
 				
+#if (GIFLIB_MAJOR>=5)
+				if( (errcode = EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, (dont_save_cmap)?NULL:gif_cmap )) == GIF_ERROR )
+					ASIM_PrintGifError(errcode);
+#else
 				if( EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, (dont_save_cmap)?NULL:gif_cmap ) == GIF_ERROR )
 					ASIM_PrintGifError();
+#endif
 			}
 		}
 		free_gif_saved_images( images, count );
@@ -1172,24 +1223,46 @@
 			outfile = open_writeable_image_file(path);
 			
 		if (outfile)
+        {
+#if (GIFLIB_MAJOR>=5)
+			gif = EGifOpenFileHandle(fileno(outfile), &errcode);
+			if (errcode != E_GIF_SUCCEEDED)
+				ASIM_PrintGifError(errcode);
+#else
 			if ((gif = EGifOpenFileHandle(fileno(outfile))) == NULL)
 				ASIM_PrintGifError();
+#endif
+        }
 	}
 
 	if( new_image && gif )
 	{
+#if (GIFLIB_MAJOR>=5)
+		if( (errcode = EGifPutScreenDesc(gif, im->width, im->height, cmap_size, 0, gif_cmap )) == GIF_ERROR )
+			ASIM_PrintGifError(errcode);
+#else
 		if( EGifPutScreenDesc(gif, im->width, im->height, cmap_size, 0, gif_cmap ) == GIF_ERROR )
 			ASIM_PrintGifError();
+#endif
 	
 		EGifPutExtension(gif, 0xf9, GIF_GCE_BYTES, &(gce_bytes[0]));
 	
+#if (GIFLIB_MAJOR>=5)
+		if( (errcode = EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, NULL )) == GIF_ERROR )
+			ASIM_PrintGifError(errcode);
+#else
 		if( EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, NULL ) == GIF_ERROR )
 			ASIM_PrintGifError();
+#endif
 	}
 
 	if( gif_cmap )
 	{
+#if (GIFLIB_MAJOR>=5)
+		GifFreeMapObject(gif_cmap);
+#else
 		FreeMapObject(gif_cmap);
+#endif
 		gif_cmap = NULL ;
 	}
 	if( gif )
@@ -1203,12 +1276,23 @@
 			register int *src = mapped_im + x*y;
 	  	    while( --x >= 0 )
 	  			row_pointer[x] = src[x] ;
+#if (GIFLIB_MAJOR>=5)
+			if( (errcode = EGifPutLine(gif, row_pointer, im->width))  == GIF_ERROR)
+				ASIM_PrintGifError(errcode);
+#else
 			if( EGifPutLine(gif, row_pointer, im->width)  == GIF_ERROR)
 				ASIM_PrintGifError();
+#endif
 		}
 		free( row_pointer );
+#if (GIFLIB_MAJOR>=5)
+		EGifCloseFile(gif, &errcode);
+		if (errcode != E_GIF_SUCCEEDED)
+			ASIM_PrintGifError(errcode);
+#else
 		if (EGifCloseFile(gif) == GIF_ERROR)
 			ASIM_PrintGifError();
+#endif
 		gif = NULL;
 	}
 	free( mapped_im );
diff -Naurd libAfterImage-1.20.orig/import.c libAfterImage-1.20/import.c
--- libAfterImage-1.20.orig/import.c	2016-05-01 11:44:19.000000000 +0300
+++ libAfterImage-1.20/import.c	2016-05-02 11:01:58.979496755 +0300
@@ -2178,6 +2178,9 @@
 	int  		transparent = -1 ;
 	unsigned int  		y;
 	unsigned int		width = 0, height = 0;
+#if (GIFLIB_MAJOR>=5)
+	int errcode;
+#endif
 	ColorMapObject     *cmap = NULL ;
 
 	START_TIME(started);
@@ -2186,7 +2189,11 @@
 	
 	if ((fp = open_image_file(path)) == NULL)
 		return NULL;
+#if (GIFLIB_MAJOR>=5)
+	if( (gif = open_gif_read(fp, &errcode)) != NULL )
+#else
 	if( (gif = open_gif_read(fp)) != NULL )
+#endif
 	{
 		SavedImage	*sp = NULL ;
 		int count = 0 ;
@@ -2289,13 +2296,21 @@
 			}
 			free_gif_saved_images( sp, count );
 		}else if( status != GIF_OK ) 
+#if (GIFLIB_MAJOR>=5)
+			ASIM_PrintGifError(status);
+#else
 			ASIM_PrintGifError();
+#endif
 		else if( params->subimage == -1 )
 			show_error( "Image file \"%s\" does not have any valid image information.", path );
 		else
 			show_error( "Image file \"%s\" does not have subimage %d.", path, params->subimage );
 
+#if (GIFLIB_MAJOR>=5)
+		DGifCloseFile(gif, &errcode);
+#else
 		DGifCloseFile(gif);
+#endif
 		fclose( fp );
 	}
 	SHOW_TIME("image loading",started);
diff -Naurd libAfterImage-1.20.orig/ungif.c libAfterImage-1.20/ungif.c
--- libAfterImage-1.20.orig/ungif.c	2011-01-15 08:52:22.000000000 +0300
+++ libAfterImage-1.20/ungif.c	2016-05-02 16:03:57.590148737 +0300
@@ -75,13 +75,21 @@
 	if( sp )
 	{
 		if (sp->ImageDesc.ColorMap)
+#if (GIFLIB_MAJOR>=5)
+	    	GifFreeMapObject(sp->ImageDesc.ColorMap);
+#else
 	    	FreeMapObject(sp->ImageDesc.ColorMap);
+#endif
 
 		if (sp->RasterBits)
 		    free((char *)sp->RasterBits);
 
 		if (sp->ExtensionBlocks)
+#if (GIFLIB_MAJOR>=5)
+		    GifFreeExtensions(sp->ExtensionBlockCount, sp->ExtensionBlocks);
+#else
 		    FreeExtension(sp);
+#endif
 
 		if( !reusable )
 			free( sp );
@@ -119,11 +127,19 @@
 	return ret;
 }
 
+#if (GIFLIB_MAJOR>=5)
+GifFileType*
+open_gif_read( FILE *in_stream, int *errcode )
+{
+	return DGifOpen(in_stream, fread_gif, errcode);
+}
+#else
 GifFileType*
 open_gif_read( FILE *in_stream )
 {
 	return DGifOpen(in_stream, fread_gif);
 }
+#endif
 
 int
 get_gif_image_desc( GifFileType *gif, SavedImage *im )
@@ -151,7 +167,11 @@
 		memcpy( &(im->ImageDesc), &(gif->Image), sizeof(GifImageDesc));
 		if( gif->Image.ColorMap )
 		{
+#if (GIFLIB_MAJOR>=5)
+			im->ImageDesc.ColorMap = GifMakeMapObject(gif->Image.ColorMap->ColorCount, NULL);
+#else
 			im->ImageDesc.ColorMap = MakeMapObject(gif->Image.ColorMap->ColorCount, NULL);
+#endif
 			fseek( gif->UserData, start_pos+9, SEEK_SET ); 
 			fread( im->ImageDesc.ColorMap->Colors, 1, gif->Image.ColorMap->ColorCount*3, gif->UserData);
 			fseek( gif->UserData, end_pos, SEEK_SET );
@@ -166,6 +186,9 @@
 {
     GifRecordType RecordType;
     GifByteType *ExtData;
+#if (GIFLIB_MAJOR>=5)
+    int ExtCode;
+#endif
     SavedImage temp_save;
 	int curr_image = 0, ret_count = *ret_images ;
 	int status = GIF_OK;
@@ -197,13 +220,23 @@
 				break;
 
 	    	case EXTENSION_RECORD_TYPE:
+#if (GIFLIB_MAJOR>=5)
+				status = DGifGetExtension(gif,&ExtCode,&ExtData);
+#else
 				status = DGifGetExtension(gif,&temp_save.Function,&ExtData);
+#endif
 				while (ExtData != NULL && status == GIF_OK )
 				{
             		/* Create an extension block with our data */
+#if (GIFLIB_MAJOR>=5)
+            		if ((status = GifAddExtensionBlock(&temp_save.ExtensionBlockCount, &temp_save.ExtensionBlocks,
+                            ExtCode, sizeof(ExtData), ExtData)) == GIF_OK)
+                    status = DGifGetExtension(gif,&ExtCode,&ExtData);
+#else
             		if ((status = AddExtensionBlock(&temp_save, ExtData[0], (char*)&(ExtData[1]))) == GIF_OK)
 				    	status = DGifGetExtensionNext(gif, &ExtData);
             		temp_save.Function = 0;
+#endif
 				}
 				break;
 
diff -Naurd libAfterImage-1.20.orig/ungif.h libAfterImage-1.20/ungif.h
--- libAfterImage-1.20.orig/ungif.h	2011-01-15 08:52:22.000000000 +0300
+++ libAfterImage-1.20/ungif.h	2016-05-02 10:57:59.715983533 +0300
@@ -7,11 +7,29 @@
 extern "C" {
 #endif
 
+#if ((GIFLIB_MAJOR==4) && (GIFLIB_MINOR>=2)) 
+static inline void PrintGifError(void) {
+    fprintf(stderr, "%s\n", GifErrorString());
+}
+#elif (GIFLIB_MAJOR>=5)
+static inline void PrintGifError(int code) {
+    fprintf(stderr, "%s\n", GifErrorString(code));
+}
+#endif
+
+#if (GIFLIB_MAJOR>=5)
+#ifdef __GNUC__
+#define ASIM_PrintGifError(code) do{ fprintf( stderr, "%s():%d:<%s> ",__FUNCTION__, __LINE__, path?path:"null" ); PrintGifError(code); }while(0)
+#else
+#define ASIM_PrintGifError(code) do{ PrintGifError(code); }while(0)
+#endif
+#else // (GIFLIB_MAJOR>=5)
 #ifdef __GNUC__
 #define ASIM_PrintGifError() do{ fprintf( stderr, "%s():%d:<%s> ",__FUNCTION__, __LINE__, path?path:"null" ); PrintGifError(); }while(0)
 #else
 #define ASIM_PrintGifError() do{ PrintGifError(); }while(0)
 #endif
+#endif // (GIFLIB_MAJOR>=5)
 
 #define GIF_GCE_DELAY_BYTE_LOW	1
 #define GIF_GCE_DELAY_BYTE_HIGH	2
@@ -24,7 +42,11 @@
 
 
 int fread_gif( GifFileType *gif, GifByteType* buf, int len );
+#if (GIFLIB_MAJOR>=5)
+GifFileType* open_gif_read( FILE *in_stream, int *errcode );
+#else
 GifFileType* open_gif_read( FILE *in_stream );
+#endif
 
 int get_gif_image_desc( GifFileType *gif, SavedImage *im );