Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 354675
Collapse All | Expand All

(-)file_not_specified_in_diff (-11 / +56 lines)
Line  Link Here
0
-- IMG_png.c
0
++ IMG_png.c
Lines 71-76 Link Here
71
#endif
71
#endif
72
#include <png.h>
72
#include <png.h>
73
73
74
/* Check for the older version of libpng */
75
#if (PNG_LIBPNG_VER_MAJOR == 1) && (PNG_LIBPNG_VER_MINOR < 4)
76
#define LIBPNG_VERSION_12
77
#endif
74
78
75
static struct {
79
static struct {
76
	int loaded;
80
	int loaded;
Lines 80-85 Link Here
80
	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
84
	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
81
	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);
85
	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);
82
	png_voidp (*png_get_io_ptr) (png_structp png_ptr);
86
	png_voidp (*png_get_io_ptr) (png_structp png_ptr);
87
	png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
88
	png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
83
	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);
89
	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);
84
	png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
90
	png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
85
	void (*png_read_image) (png_structp png_ptr, png_bytepp image);
91
	void (*png_read_image) (png_structp png_ptr, png_bytepp image);
Lines 91-96 Link Here
91
	void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
97
	void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
92
	void (*png_set_strip_16) (png_structp png_ptr);
98
	void (*png_set_strip_16) (png_structp png_ptr);
93
	int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
99
	int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
100
#ifndef LIBPNG_VERSION_12
101
	jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
102
#endif
94
} lib;
103
} lib;
95
104
96
#ifdef LOAD_PNG_DYNAMIC
105
#ifdef LOAD_PNG_DYNAMIC
Lines 129-134 Link Here
129
			SDL_UnloadObject(lib.handle);
138
			SDL_UnloadObject(lib.handle);
130
			return -1;
139
			return -1;
131
		}
140
		}
141
		lib.png_get_channels =
142
			(png_byte (*) (png_structp, png_infop))
143
			SDL_LoadFunction(lib.handle, "png_get_channels");
144
		if ( lib.png_get_channels == NULL ) {
145
			SDL_UnloadObject(lib.handle);
146
			return -1;
147
		}
132
		lib.png_get_io_ptr =
148
		lib.png_get_io_ptr =
133
			(png_voidp (*) (png_structp))
149
			(png_voidp (*) (png_structp))
134
			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
150
			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
Lines 136-141 Link Here
136
			SDL_UnloadObject(lib.handle);
152
			SDL_UnloadObject(lib.handle);
137
			return -1;
153
			return -1;
138
		}
154
		}
155
		lib.png_get_PLTE =
156
			(png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
157
			SDL_LoadFunction(lib.handle, "png_get_PLTE");
158
		if ( lib.png_get_PLTE == NULL ) {
159
			SDL_UnloadObject(lib.handle);
160
			return -1;
161
		}
139
		lib.png_get_tRNS =
162
		lib.png_get_tRNS =
140
			(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
163
			(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
141
			SDL_LoadFunction(lib.handle, "png_get_tRNS");
164
			SDL_LoadFunction(lib.handle, "png_get_tRNS");
Lines 213-218 Link Here
213
			SDL_UnloadObject(lib.handle);
236
			SDL_UnloadObject(lib.handle);
214
			return -1;
237
			return -1;
215
		}
238
		}
239
#ifndef LIBPNG_VERSION_12
240
		lib.png_set_longjmp_fn =
241
			(jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
242
			SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
243
		if ( lib.png_set_longjmp_fn == NULL ) {
244
			SDL_UnloadObject(lib.handle);
245
			return -1;
246
		}
247
#endif
216
	}
248
	}
217
	++lib.loaded;
249
	++lib.loaded;
218
250
Lines 236-242 Link Here
236
		lib.png_create_read_struct = png_create_read_struct;
268
		lib.png_create_read_struct = png_create_read_struct;
237
		lib.png_destroy_read_struct = png_destroy_read_struct;
269
		lib.png_destroy_read_struct = png_destroy_read_struct;
238
		lib.png_get_IHDR = png_get_IHDR;
270
		lib.png_get_IHDR = png_get_IHDR;
271
		lib.png_get_channels = png_get_channels;
239
		lib.png_get_io_ptr = png_get_io_ptr;
272
		lib.png_get_io_ptr = png_get_io_ptr;
273
		lib.png_get_PLTE = png_get_PLTE;
240
		lib.png_get_tRNS = png_get_tRNS;
274
		lib.png_get_tRNS = png_get_tRNS;
241
		lib.png_get_valid = png_get_valid;
275
		lib.png_get_valid = png_get_valid;
242
		lib.png_read_image = png_read_image;
276
		lib.png_read_image = png_read_image;
Lines 248-253 Link Here
248
		lib.png_set_read_fn = png_set_read_fn;
282
		lib.png_set_read_fn = png_set_read_fn;
249
		lib.png_set_strip_16 = png_set_strip_16;
283
		lib.png_set_strip_16 = png_set_strip_16;
250
		lib.png_sig_cmp = png_sig_cmp;
284
		lib.png_sig_cmp = png_sig_cmp;
285
#ifndef LIBPNG_VERSION_12
286
		lib.png_set_longjmp_fn = png_set_longjmp_fn;
287
#endif
251
	}
288
	}
252
	++lib.loaded;
289
	++lib.loaded;
253
290
Lines 347-353 Link Here
347
	 * the normal method of doing things with libpng).  REQUIRED unless you
384
	 * the normal method of doing things with libpng).  REQUIRED unless you
348
	 * set up your own error handlers in png_create_read_struct() earlier.
385
	 * set up your own error handlers in png_create_read_struct() earlier.
349
	 */
386
	 */
350
	if ( setjmp(png_ptr->jmpbuf) ) {
387
#ifndef LIBPNG_VERSION_12
388
	if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
389
#else
390
	if ( setjmp(png_ptr->jmpbuf) )
391
#endif
392
	{
351
		error = "Error reading the PNG file.";
393
		error = "Error reading the PNG file.";
352
		goto done;
394
		goto done;
353
	}
395
	}
Lines 416-424 Link Here
416
			Rmask = 0x000000FF;
458
			Rmask = 0x000000FF;
417
			Gmask = 0x0000FF00;
459
			Gmask = 0x0000FF00;
418
			Bmask = 0x00FF0000;
460
			Bmask = 0x00FF0000;
419
			Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
461
			Amask = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0;
420
		} else {
462
		} else {
421
		        int s = (info_ptr->channels == 4) ? 0 : 8;
463
		        int s = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8;
422
			Rmask = 0xFF000000 >> s;
464
			Rmask = 0xFF000000 >> s;
423
			Gmask = 0x00FF0000 >> s;
465
			Gmask = 0x00FF0000 >> s;
424
			Bmask = 0x0000FF00 >> s;
466
			Bmask = 0x0000FF00 >> s;
Lines 426-432 Link Here
426
		}
468
		}
427
	}
469
	}
428
	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
470
	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
429
			bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
471
			bit_depth*lib.png_get_channels(png_ptr, info_ptr), Rmask,Gmask,Bmask,Amask);
430
	if ( surface == NULL ) {
472
	if ( surface == NULL ) {
431
		error = "Out of memory";
473
		error = "Out of memory";
432
		goto done;
474
		goto done;
Lines 467-472 Link Here
467
	/* Load the palette, if any */
509
	/* Load the palette, if any */
468
	palette = surface->format->palette;
510
	palette = surface->format->palette;
469
	if ( palette ) {
511
	if ( palette ) {
512
	    int png_num_palette;
513
	    png_colorp png_palette;
514
	    lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
470
	    if(color_type == PNG_COLOR_TYPE_GRAY) {
515
	    if(color_type == PNG_COLOR_TYPE_GRAY) {
471
		palette->ncolors = 256;
516
		palette->ncolors = 256;
472
		for(i = 0; i < 256; i++) {
517
		for(i = 0; i < 256; i++) {
Lines 474-485 Link Here
474
		    palette->colors[i].g = i;
519
		    palette->colors[i].g = i;
475
		    palette->colors[i].b = i;
520
		    palette->colors[i].b = i;
476
		}
521
		}
477
	    } else if (info_ptr->num_palette > 0 ) {
522
	    } else if (png_num_palette > 0 ) {
478
		palette->ncolors = info_ptr->num_palette; 
523
		palette->ncolors = png_num_palette; 
479
		for( i=0; i<info_ptr->num_palette; ++i ) {
524
		for( i=0; i<png_num_palette; ++i ) {
480
		    palette->colors[i].b = info_ptr->palette[i].blue;
525
		    palette->colors[i].b = png_palette[i].blue;
481
		    palette->colors[i].g = info_ptr->palette[i].green;
526
		    palette->colors[i].g = png_palette[i].green;
482
		    palette->colors[i].r = info_ptr->palette[i].red;
527
		    palette->colors[i].r = png_palette[i].red;
483
		}
528
		}
484
	    }
529
	    }
485
	}
530
	}

Return to bug 354675