/[packages]/cauldron/SDL_image/current/SOURCES/SDL_image-1.2.10-libpng15.patch
ViewVC logotype

Contents of /cauldron/SDL_image/current/SOURCES/SDL_image-1.2.10-libpng15.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 142278 - (show annotations) (download)
Sun Sep 11 01:11:52 2011 UTC (12 years, 7 months ago) by fwang
File size: 5664 byte(s)
fix build with libpng15
1 --- sdl-image1.2-1.2.10.orig/IMG_png.c
2 +++ sdl-image1.2-1.2.10/IMG_png.c
3 @@ -71,6 +71,10 @@
4 #endif
5 #include <png.h>
6
7 +/* Check for the older version of libpng */
8 +#if (PNG_LIBPNG_VER_MAJOR == 1) && (PNG_LIBPNG_VER_MINOR < 4)
9 +#define LIBPNG_VERSION_12
10 +#endif
11
12 static struct {
13 int loaded;
14 @@ -80,6 +84,8 @@
15 void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
16 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);
17 png_voidp (*png_get_io_ptr) (png_structp png_ptr);
18 + png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
19 + png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
20 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);
21 png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
22 void (*png_read_image) (png_structp png_ptr, png_bytepp image);
23 @@ -91,6 +97,9 @@
24 void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
25 void (*png_set_strip_16) (png_structp png_ptr);
26 int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
27 +#ifndef LIBPNG_VERSION_12
28 + jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
29 +#endif
30 } lib;
31
32 #ifdef LOAD_PNG_DYNAMIC
33 @@ -129,6 +138,13 @@
34 SDL_UnloadObject(lib.handle);
35 return -1;
36 }
37 + lib.png_get_channels =
38 + (png_byte (*) (png_structp, png_infop))
39 + SDL_LoadFunction(lib.handle, "png_get_channels");
40 + if ( lib.png_get_channels == NULL ) {
41 + SDL_UnloadObject(lib.handle);
42 + return -1;
43 + }
44 lib.png_get_io_ptr =
45 (png_voidp (*) (png_structp))
46 SDL_LoadFunction(lib.handle, "png_get_io_ptr");
47 @@ -136,6 +152,13 @@
48 SDL_UnloadObject(lib.handle);
49 return -1;
50 }
51 + lib.png_get_PLTE =
52 + (png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
53 + SDL_LoadFunction(lib.handle, "png_get_PLTE");
54 + if ( lib.png_get_PLTE == NULL ) {
55 + SDL_UnloadObject(lib.handle);
56 + return -1;
57 + }
58 lib.png_get_tRNS =
59 (png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
60 SDL_LoadFunction(lib.handle, "png_get_tRNS");
61 @@ -213,6 +236,15 @@
62 SDL_UnloadObject(lib.handle);
63 return -1;
64 }
65 +#ifndef LIBPNG_VERSION_12
66 + lib.png_set_longjmp_fn =
67 + (jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
68 + SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
69 + if ( lib.png_set_longjmp_fn == NULL ) {
70 + SDL_UnloadObject(lib.handle);
71 + return -1;
72 + }
73 +#endif
74 }
75 ++lib.loaded;
76
77 @@ -236,7 +268,9 @@
78 lib.png_create_read_struct = png_create_read_struct;
79 lib.png_destroy_read_struct = png_destroy_read_struct;
80 lib.png_get_IHDR = png_get_IHDR;
81 + lib.png_get_channels = png_get_channels;
82 lib.png_get_io_ptr = png_get_io_ptr;
83 + lib.png_get_PLTE = png_get_PLTE;
84 lib.png_get_tRNS = png_get_tRNS;
85 lib.png_get_valid = png_get_valid;
86 lib.png_read_image = png_read_image;
87 @@ -248,6 +282,9 @@
88 lib.png_set_read_fn = png_set_read_fn;
89 lib.png_set_strip_16 = png_set_strip_16;
90 lib.png_sig_cmp = png_sig_cmp;
91 +#ifndef LIBPNG_VERSION_12
92 + lib.png_set_longjmp_fn = png_set_longjmp_fn;
93 +#endif
94 }
95 ++lib.loaded;
96
97 @@ -347,7 +384,12 @@
98 * the normal method of doing things with libpng). REQUIRED unless you
99 * set up your own error handlers in png_create_read_struct() earlier.
100 */
101 - if ( setjmp(png_ptr->jmpbuf) ) {
102 +#ifndef LIBPNG_VERSION_12
103 + if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) )
104 +#else
105 + if ( setjmp(png_ptr->jmpbuf) )
106 +#endif
107 + {
108 error = "Error reading the PNG file.";
109 goto done;
110 }
111 @@ -416,9 +458,9 @@
112 Rmask = 0x000000FF;
113 Gmask = 0x0000FF00;
114 Bmask = 0x00FF0000;
115 - Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
116 + Amask = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0;
117 } else {
118 - int s = (info_ptr->channels == 4) ? 0 : 8;
119 + int s = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8;
120 Rmask = 0xFF000000 >> s;
121 Gmask = 0x00FF0000 >> s;
122 Bmask = 0x0000FF00 >> s;
123 @@ -426,7 +468,7 @@
124 }
125 }
126 surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
127 - bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
128 + bit_depth*lib.png_get_channels(png_ptr, info_ptr), Rmask,Gmask,Bmask,Amask);
129 if ( surface == NULL ) {
130 error = "Out of memory";
131 goto done;
132 @@ -467,6 +509,9 @@
133 /* Load the palette, if any */
134 palette = surface->format->palette;
135 if ( palette ) {
136 + int png_num_palette;
137 + png_colorp png_palette;
138 + lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
139 if(color_type == PNG_COLOR_TYPE_GRAY) {
140 palette->ncolors = 256;
141 for(i = 0; i < 256; i++) {
142 @@ -474,12 +519,12 @@
143 palette->colors[i].g = i;
144 palette->colors[i].b = i;
145 }
146 - } else if (info_ptr->num_palette > 0 ) {
147 - palette->ncolors = info_ptr->num_palette;
148 - for( i=0; i<info_ptr->num_palette; ++i ) {
149 - palette->colors[i].b = info_ptr->palette[i].blue;
150 - palette->colors[i].g = info_ptr->palette[i].green;
151 - palette->colors[i].r = info_ptr->palette[i].red;
152 + } else if (png_num_palette > 0 ) {
153 + palette->ncolors = png_num_palette;
154 + for( i=0; i<png_num_palette; ++i ) {
155 + palette->colors[i].b = png_palette[i].blue;
156 + palette->colors[i].g = png_palette[i].green;
157 + palette->colors[i].r = png_palette[i].red;
158 }
159 }
160 }

  ViewVC Help
Powered by ViewVC 1.1.30