summaryrefslogtreecommitdiff
path: root/community/paintown/libpng15.patch
blob: 516c3ec0172323b128776e28925f26517e379323 (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
------------------------------------------------------------------------
r7015 | kazzmir | 2012-02-18 22:19:01 +0100 (Sa, 18 Feb 2012) | 1 line

patch for sdl image to work with libpng1.4+

Index: src/util/sdl/image/IMG_png.c
===================================================================
--- src/util/sdl/image/IMG_png.c	(revision 7014)
+++ src/util/sdl/image/IMG_png.c	(revision 7015)
@@ -71,6 +71,10 @@
 #endif
 #include <png.h>
 
+/* Check for the older version of libpng */
+#if (PNG_LIBPNG_VER_MAJOR == 1) && (PNG_LIBPNG_VER_MINOR < 4)
+#define LIBPNG_VERSION_12
+#endif
 
 static struct {
 	int loaded;
@@ -80,6 +84,8 @@
 	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
 	png_uint_32 (*png_get_IHDR) (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method);
 	png_voidp (*png_get_io_ptr) (png_structp png_ptr);
+	png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
+	png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
 	png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values);
 	png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
 	void (*png_read_image) (png_structp png_ptr, png_bytepp image);
@@ -91,6 +97,9 @@
 	void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
 	void (*png_set_strip_16) (png_structp png_ptr);
 	int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
+#ifndef LIBPNG_VERSION_12
+	jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
+#endif
 } lib;
 
 #ifdef LOAD_PNG_DYNAMIC
@@ -129,6 +138,13 @@
 			SDL_UnloadObject(lib.handle);
 			return -1;
 		}
+		lib.png_get_channels =
+			(png_byte (*) (png_structp, png_infop))
+			SDL_LoadFunction(lib.handle, "png_get_channels");
+		if ( lib.png_get_channels == NULL ) {
+			SDL_UnloadObject(lib.handle);
+			return -1;
+		}
 		lib.png_get_io_ptr =
 			(png_voidp (*) (png_structp))
 			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
@@ -136,6 +152,13 @@
 			SDL_UnloadObject(lib.handle);
 			return -1;
 		}
+		lib.png_get_PLTE =
+			(png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
+			SDL_LoadFunction(lib.handle, "png_get_PLTE");
+		if ( lib.png_get_PLTE == NULL ) {
+			SDL_UnloadObject(lib.handle);
+			return -1;
+		}
 		lib.png_get_tRNS =
 			(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
 			SDL_LoadFunction(lib.handle, "png_get_tRNS");
@@ -213,6 +236,15 @@
 			SDL_UnloadObject(lib.handle);
 			return -1;
 		}
+#ifndef LIBPNG_VERSION_12
+		lib.png_set_longjmp_fn =
+			(jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
+			SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
+		if ( lib.png_set_longjmp_fn == NULL ) {
+			SDL_UnloadObject(lib.handle);
+			return -1;
+		}
+#endif
 	}
 	++lib.loaded;
 
@@ -236,7 +268,9 @@
 		lib.png_create_read_struct = png_create_read_struct;
 		lib.png_destroy_read_struct = png_destroy_read_struct;
 		lib.png_get_IHDR = png_get_IHDR;
+		lib.png_get_channels = png_get_channels;
 		lib.png_get_io_ptr = png_get_io_ptr;
+		lib.png_get_PLTE = png_get_PLTE;
 		lib.png_get_tRNS = png_get_tRNS;
 		lib.png_get_valid = png_get_valid;
 		lib.png_read_image = png_read_image;
@@ -248,6 +282,9 @@
 		lib.png_set_read_fn = png_set_read_fn;
 		lib.png_set_strip_16 = png_set_strip_16;
 		lib.png_sig_cmp = png_sig_cmp;
+#ifndef LIBPNG_VERSION_12
+		lib.png_set_longjmp_fn = png_set_longjmp_fn;
+#endif
 	}
 	++lib.loaded;
 
@@ -347,7 +384,12 @@
 	 * the normal method of doing things with libpng).  REQUIRED unless you
 	 * set up your own error handlers in png_create_read_struct() earlier.
 	 */
-	if ( setjmp(png_ptr->jmpbuf) ) {
+#ifndef LIBPNG_VERSION_12
+	if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
+#else
+	if ( setjmp(png_ptr->jmpbuf) )
+#endif
+	{
 		error = "Error reading the PNG file.";
 		goto done;
 	}
@@ -416,9 +458,9 @@
 			Rmask = 0x000000FF;
 			Gmask = 0x0000FF00;
 			Bmask = 0x00FF0000;
-			Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
+			Amask = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0;
 		} else {
-		        int s = (info_ptr->channels == 4) ? 0 : 8;
+		        int s = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8;
 			Rmask = 0xFF000000 >> s;
 			Gmask = 0x00FF0000 >> s;
 			Bmask = 0x0000FF00 >> s;
@@ -426,7 +468,7 @@
 		}
 	}
 	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
-			bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
+			bit_depth*lib.png_get_channels(png_ptr, info_ptr), Rmask,Gmask,Bmask,Amask);
 	if ( surface == NULL ) {
 		error = "Out of memory";
 		goto done;
@@ -444,7 +486,7 @@
 
 	/* Create the array of pointers to image data */
 	row_pointers = (png_bytep*) malloc(sizeof(png_bytep)*height);
-	if ( (row_pointers == NULL) ) {
+	if (row_pointers == NULL) {
 		error = "Out of memory";
 		goto done;
 	}
@@ -467,6 +509,9 @@
 	/* Load the palette, if any */
 	palette = surface->format->palette;
 	if ( palette ) {
+	    int png_num_palette;
+	    png_colorp png_palette;
+	    lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
 	    if(color_type == PNG_COLOR_TYPE_GRAY) {
 		palette->ncolors = 256;
 		for(i = 0; i < 256; i++) {
@@ -474,12 +519,12 @@
 		    palette->colors[i].g = i;
 		    palette->colors[i].b = i;
 		}
-	    } else if (info_ptr->num_palette > 0 ) {
-		palette->ncolors = info_ptr->num_palette; 
-		for( i=0; i<info_ptr->num_palette; ++i ) {
-		    palette->colors[i].b = info_ptr->palette[i].blue;
-		    palette->colors[i].g = info_ptr->palette[i].green;
-		    palette->colors[i].r = info_ptr->palette[i].red;
+	    } else if (png_num_palette > 0 ) {
+		palette->ncolors = png_num_palette; 
+		for( i=0; i<png_num_palette; ++i ) {
+		    palette->colors[i].b = png_palette[i].blue;
+		    palette->colors[i].g = png_palette[i].green;
+		    palette->colors[i].r = png_palette[i].red;
 		}
 	    }
 	}
Index: src/util/sdl/image/sdl-image-1.2.10-libpng15.patch
===================================================================
--- src/util/sdl/image/sdl-image-1.2.10-libpng15.patch	(revision 0)
+++ src/util/sdl/image/sdl-image-1.2.10-libpng15.patch	(revision 7015)
@@ -0,0 +1,160 @@
+--- IMG_png.c
++++ IMG_png.c
+@@ -71,6 +71,10 @@
+ #endif
+ #include <png.h>
+ 
++/* Check for the older version of libpng */
++#if (PNG_LIBPNG_VER_MAJOR == 1) && (PNG_LIBPNG_VER_MINOR < 4)
++#define LIBPNG_VERSION_12
++#endif
+ 
+ static struct {
+ 	int loaded;
+@@ -80,6 +84,8 @@
+ 	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
+ 	png_uint_32 (*png_get_IHDR) (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method);
+ 	png_voidp (*png_get_io_ptr) (png_structp png_ptr);
++	png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
++	png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
+ 	png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values);
+ 	png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
+ 	void (*png_read_image) (png_structp png_ptr, png_bytepp image);
+@@ -91,6 +97,9 @@
+ 	void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
+ 	void (*png_set_strip_16) (png_structp png_ptr);
+ 	int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
++#ifndef LIBPNG_VERSION_12
++	jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
++#endif
+ } lib;
+ 
+ #ifdef LOAD_PNG_DYNAMIC
+@@ -129,6 +138,13 @@
+ 			SDL_UnloadObject(lib.handle);
+ 			return -1;
+ 		}
++		lib.png_get_channels =
++			(png_byte (*) (png_structp, png_infop))
++			SDL_LoadFunction(lib.handle, "png_get_channels");
++		if ( lib.png_get_channels == NULL ) {
++			SDL_UnloadObject(lib.handle);
++			return -1;
++		}
+ 		lib.png_get_io_ptr =
+ 			(png_voidp (*) (png_structp))
+ 			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
+@@ -136,6 +152,13 @@
+ 			SDL_UnloadObject(lib.handle);
+ 			return -1;
+ 		}
++		lib.png_get_PLTE =
++			(png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
++			SDL_LoadFunction(lib.handle, "png_get_PLTE");
++		if ( lib.png_get_PLTE == NULL ) {
++			SDL_UnloadObject(lib.handle);
++			return -1;
++		}
+ 		lib.png_get_tRNS =
+ 			(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
+ 			SDL_LoadFunction(lib.handle, "png_get_tRNS");
+@@ -213,6 +236,15 @@
+ 			SDL_UnloadObject(lib.handle);
+ 			return -1;
+ 		}
++#ifndef LIBPNG_VERSION_12
++		lib.png_set_longjmp_fn =
++			(jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
++			SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
++		if ( lib.png_set_longjmp_fn == NULL ) {
++			SDL_UnloadObject(lib.handle);
++			return -1;
++		}
++#endif
+ 	}
+ 	++lib.loaded;
+ 
+@@ -236,7 +268,9 @@
+ 		lib.png_create_read_struct = png_create_read_struct;
+ 		lib.png_destroy_read_struct = png_destroy_read_struct;
+ 		lib.png_get_IHDR = png_get_IHDR;
++		lib.png_get_channels = png_get_channels;
+ 		lib.png_get_io_ptr = png_get_io_ptr;
++		lib.png_get_PLTE = png_get_PLTE;
+ 		lib.png_get_tRNS = png_get_tRNS;
+ 		lib.png_get_valid = png_get_valid;
+ 		lib.png_read_image = png_read_image;
+@@ -248,6 +282,9 @@
+ 		lib.png_set_read_fn = png_set_read_fn;
+ 		lib.png_set_strip_16 = png_set_strip_16;
+ 		lib.png_sig_cmp = png_sig_cmp;
++#ifndef LIBPNG_VERSION_12
++		lib.png_set_longjmp_fn = png_set_longjmp_fn;
++#endif
+ 	}
+ 	++lib.loaded;
+ 
+@@ -347,7 +384,12 @@
+ 	 * the normal method of doing things with libpng).  REQUIRED unless you
+ 	 * set up your own error handlers in png_create_read_struct() earlier.
+ 	 */
+-	if ( setjmp(png_ptr->jmpbuf) ) {
++#ifndef LIBPNG_VERSION_12
++	if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
++#else
++	if ( setjmp(png_ptr->jmpbuf) )
++#endif
++	{
+ 		error = "Error reading the PNG file.";
+ 		goto done;
+ 	}
+@@ -416,9 +458,9 @@
+ 			Rmask = 0x000000FF;
+ 			Gmask = 0x0000FF00;
+ 			Bmask = 0x00FF0000;
+-			Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
++			Amask = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0;
+ 		} else {
+-		        int s = (info_ptr->channels == 4) ? 0 : 8;
++		        int s = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8;
+ 			Rmask = 0xFF000000 >> s;
+ 			Gmask = 0x00FF0000 >> s;
+ 			Bmask = 0x0000FF00 >> s;
+@@ -426,7 +468,7 @@
+ 		}
+ 	}
+ 	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
+-			bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
++			bit_depth*lib.png_get_channels(png_ptr, info_ptr), Rmask,Gmask,Bmask,Amask);
+ 	if ( surface == NULL ) {
+ 		error = "Out of memory";
+ 		goto done;
+@@ -467,6 +509,9 @@
+ 	/* Load the palette, if any */
+ 	palette = surface->format->palette;
+ 	if ( palette ) {
++	    int png_num_palette;
++	    png_colorp png_palette;
++	    lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
+ 	    if(color_type == PNG_COLOR_TYPE_GRAY) {
+ 		palette->ncolors = 256;
+ 		for(i = 0; i < 256; i++) {
+@@ -474,12 +519,12 @@
+ 		    palette->colors[i].g = i;
+ 		    palette->colors[i].b = i;
+ 		}
+-	    } else if (info_ptr->num_palette > 0 ) {
+-		palette->ncolors = info_ptr->num_palette; 
+-		for( i=0; i<info_ptr->num_palette; ++i ) {
+-		    palette->colors[i].b = info_ptr->palette[i].blue;
+-		    palette->colors[i].g = info_ptr->palette[i].green;
+-		    palette->colors[i].r = info_ptr->palette[i].red;
++	    } else if (png_num_palette > 0 ) {
++		palette->ncolors = png_num_palette; 
++		for( i=0; i<png_num_palette; ++i ) {
++		    palette->colors[i].b = png_palette[i].blue;
++		    palette->colors[i].g = png_palette[i].green;
++		    palette->colors[i].r = png_palette[i].red;
+ 		}
+ 	    }
+ 	}

------------------------------------------------------------------------