summaryrefslogtreecommitdiff
path: root/fonts/fontforge/patches/patch-aj
blob: d312ad6a3924d5a59c0f5d77e0d5753317e25f15 (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
$NetBSD: patch-aj,v 1.3 2011/01/24 10:36:58 wiz Exp $

Fix build with png-1.5.

--- gutils/gimagereadpng.c.orig	2010-04-29 03:53:22.000000000 +0000
+++ gutils/gimagereadpng.c
@@ -60,6 +60,14 @@ static void (*_png_set_packing)(png_stru
 static void (*_png_set_filler)(png_structp,png_uint_32,int);
 static void (*_png_read_image)(png_structp,png_bytep*);
 static void (*_png_read_end)(png_structp,png_infop);
+static void (*_png_longjmp)(png_structp, int);
+static jmp_buf* (*_png_set_longjmp_fn)(png_structp,png_longjmp_ptr, size_t);
+static png_byte (*_png_get_color_type)(png_structp,png_infop);
+static png_byte (*_png_get_bit_depth)(png_structp,png_infop);
+static png_uint_32 (*_png_get_image_width)(png_structp,png_infop);
+static png_uint_32 (*_png_get_image_height)(png_structp,png_infop);
+static png_uint_32 (*_png_get_tRNS)(png_structp,png_infop,png_bytep *,int *,png_color_16p *);
+static png_uint_32 (*_png_get_valid)(png_structp,png_infop,png_uint_32);
 
 #ifndef RTLD_GLOBAL		/* OSF on Alpha doesn't define this */
 # define RTLD_GLOBAL 0
@@ -78,7 +86,7 @@ return( 0 );
     }
 
 #  if !defined(_LIBPNG12)
-    libpng = dlopen("libpng" SO_EXT,RTLD_LAZY);
+    libpng = dlopen("libpng15" SO_EXT,RTLD_LAZY);
 #    ifdef SO_2_EXT
     if ( libpng==NULL )
 	libpng = dlopen("libpng" SO_2_EXT,RTLD_LAZY);
@@ -105,6 +113,14 @@ return( 0 );
     _png_set_filler = (void (*)(png_structp,png_uint_32,int)) dlsym(libpng,"png_set_filler");
     _png_read_image = (void (*)(png_structp,png_bytep*)) dlsym(libpng,"png_read_image");
     _png_read_end = (void (*)(png_structp,png_infop)) dlsym(libpng,"png_read_end");
+    _png_longjmp = (void (*)(png_structp, int)) dlsym(libpng,"png_longjmp");
+    _png_set_longjmp_fn = (jmp_buf* (*)(png_structp,png_longjmp_ptr,size_t)) dlsym(libpng,"png_set_longjmp_fn");
+    _png_get_color_type = (png_byte (*)(png_structp,png_infop)) dlsym(libpng,"png_get_color_type");
+    _png_get_bit_depth = (png_byte (*)(png_structp,png_infop)) dlsym(libpng,"png_get_bit_depth");
+    _png_get_image_width = (png_uint_32 (*)(png_structp,png_infop)) dlsym(libpng,"png_get_image_width");
+    _png_get_image_height = (png_uint_32 (*)(png_structp,png_infop)) dlsym(libpng,"png_get_image_height");
+    _png_get_tRNS = (png_uint_32 (*)(png_structp,png_infop,png_bytep *,int *,png_color_16p *)) dlsym(libpng,"png_get_tRNS");
+    _png_get_valid = (png_uint_32 (*)(png_structp,png_infop,png_uint_32)) dlsym(libpng,"png_get_valid");
     if ( _png_create_read_struct && _png_create_info_struct && _png_destroy_read_struct &&
 	    _png_init_io && _png_read_info && _png_set_strip_16 && _png_set_packing &&
 	    _png_set_filler && _png_read_image && _png_read_end &&
@@ -126,6 +142,14 @@ return( 0 );
 #  define _png_set_filler png_set_filler
 #  define _png_read_image png_read_image
 #  define _png_read_end png_read_end
+#  define _png_longjmp png_longjmp
+#  define _png_set_longjmp_fn png_set_longjmp_fn
+#  define _png_get_color_type png_get_color_type
+#  define _png_get_bit_depth png_get_bit_depth
+#  define _png_get_image_width png_get_image_width
+#  define _png_get_image_height png_get_image_height
+#  define _png_get_tRNS png_get_tRNS
+#  define _png_get_valid png_get_valid
 static void *libpng=(void *) 1;
 
 static int loadpng() { return true; }
@@ -133,7 +157,11 @@ static int loadpng() { return true; }
  
 static void user_error_fn(png_structp png_ptr, png_const_charp error_msg) {
     fprintf(stderr,"%s\n", error_msg);
+#if (PNG_LIBPNG_VER < 10500)
     longjmp(png_ptr->jmpbuf,1);
+#else
+    _png_longjmp (png_ptr, 1);
+#endif
 }
 
 static void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg) {
@@ -146,6 +174,9 @@ GImage *GImageRead_Png(FILE *fp) {
     png_structp png_ptr;
     png_infop info_ptr;
     png_bytep *row_pointers=NULL;
+    png_bytep trans_alpha;
+    int num_trans;
+    png_color_16p trans_color;
     int i;
 
     if ( libpng==NULL )
@@ -164,7 +195,7 @@ return( NULL );
 return( NULL );
     }
 
-    if (setjmp(png_ptr->jmpbuf)) {
+    if (setjmp(*_png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf)))) {
       /* Free all of the memory associated with the png_ptr and info_ptr */
       _png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
       if ( ret!=NULL ) {
@@ -178,74 +209,63 @@ return( NULL );
     _png_init_io(png_ptr, fp);
     _png_read_info(png_ptr, info_ptr);
     _png_set_strip_16(png_ptr);
-    if ( (info_ptr->color_type==PNG_COLOR_TYPE_GRAY || info_ptr->color_type==PNG_COLOR_TYPE_PALETTE ) &&
-	    info_ptr->bit_depth == 1 )
+    if ( (_png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_GRAY || _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_PALETTE ) &&
+	    _png_get_bit_depth(png_ptr,info_ptr) == 1 )
 	/* Leave bitmaps packed */;
     else
 	_png_set_packing(png_ptr);
-    if ( info_ptr->color_type==PNG_COLOR_TYPE_GRAY_ALPHA )
+    if ( _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_GRAY_ALPHA )
 	_png_set_strip_alpha(png_ptr);
-    if (info_ptr->color_type == PNG_COLOR_TYPE_RGB)
+    if (_png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB)
 	_png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
 
-    if ( info_ptr->color_type==PNG_COLOR_TYPE_GRAY && info_ptr->bit_depth == 1 ) {
-	ret = GImageCreate(it_mono,info_ptr->width,info_ptr->height);
-    } else if ( info_ptr->color_type==PNG_COLOR_TYPE_GRAY || info_ptr->color_type==PNG_COLOR_TYPE_GRAY_ALPHA ) {
+    if ( _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_GRAY && _png_get_bit_depth(png_ptr,info_ptr) == 1 ) {
+	ret = GImageCreate(it_mono,_png_get_image_width(png_ptr,info_ptr),_png_get_image_height(png_ptr,info_ptr));
+    } else if ( _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_GRAY || _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_GRAY_ALPHA ) {
 	GClut *clut;
-	ret = GImageCreate(it_index,info_ptr->width,info_ptr->height);
+	ret = GImageCreate(it_index,_png_get_image_width(png_ptr,info_ptr),_png_get_image_height(png_ptr,info_ptr));
 	clut = ret->u.image->clut;
 	clut->is_grey = true;
 	clut->clut_len = 256;
 	for ( i=0; i<256; ++i )
 	    clut->clut[i] = COLOR_CREATE(i,i,i);
-    } else if ( info_ptr->color_type==PNG_COLOR_TYPE_RGB_ALPHA ) {
-	ret = GImageCreate(it_rgba,info_ptr->width,info_ptr->height);
-    } else if ( info_ptr->color_type==PNG_COLOR_TYPE_RGB || info_ptr->color_type==PNG_COLOR_TYPE_RGB_ALPHA )
-	ret = GImageCreate(it_true,info_ptr->width,info_ptr->height);
+    } else if ( _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_RGB_ALPHA ) {
+	ret = GImageCreate(it_rgba,_png_get_image_width(png_ptr,info_ptr),_png_get_image_height(png_ptr,info_ptr));
+    } else if ( _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_RGB || _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_RGB_ALPHA )
+	ret = GImageCreate(it_true,_png_get_image_width(png_ptr,info_ptr),_png_get_image_height(png_ptr,info_ptr));
     else {
+	png_colorp palette;
+	int num_palette;
 	GClut *clut;
-	ret = GImageCreate(info_ptr->bit_depth != 1? it_index : it_mono,
-		info_ptr->width,info_ptr->height);
+	ret = GImageCreate(_png_get_bit_depth(png_ptr,info_ptr) != 1? it_index : it_mono,
+		_png_get_image_width(png_ptr,info_ptr),_png_get_image_height(png_ptr,info_ptr));
 	clut = ret->u.image->clut;
 	if ( clut==NULL )
 	    clut = ret->u.image->clut = gcalloc(1,sizeof(GClut));
 	clut->is_grey = true;
-	clut->clut_len = info_ptr->num_palette;
-	for ( i=0; i<info_ptr->num_palette; ++i )
-	    clut->clut[i] = COLOR_CREATE(info_ptr->palette[i].red,
-			info_ptr->palette[i].green,
-			info_ptr->palette[i].blue);
+	png_get_PLTE(png_ptr,info_ptr,&palette,&num_palette);
+	clut->clut_len = num_palette;
+	for ( i=0; i<num_palette; ++i )
+	    clut->clut[i] = COLOR_CREATE(palette[i].red,
+			palette[i].green,
+			palette[i].blue);
     }
+    _png_get_tRNS(png_ptr,info_ptr,&trans_alpha,&num_trans,&trans_color);
     base = ret->u.image;
-    if ( (info_ptr->valid&PNG_INFO_tRNS) && info_ptr->num_trans>0 ) {
-	if ( info_ptr->color_type==PNG_COLOR_TYPE_RGB || info_ptr->color_type==PNG_COLOR_TYPE_RGB_ALPHA )
-#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 )
+    if ( (_png_get_valid(png_ptr,info_ptr,PNG_INFO_tRNS)) && num_trans>0 ) {
+	if ( _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_RGB || _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_RGB_ALPHA )
 	    base->trans = COLOR_CREATE(
-		    (info_ptr->trans_color.red>>8),
-		    (info_ptr->trans_color.green>>8),
-		    (info_ptr->trans_color.blue>>8));
-#else
-	    base->trans = COLOR_CREATE(
-		    (info_ptr->trans_values.red>>8),
-		    (info_ptr->trans_values.green>>8),
-		    (info_ptr->trans_values.blue>>8));
-#endif
+		    (trans_color->red>>8),
+		    (trans_color->green>>8),
+		    (trans_color->blue>>8));
         else if ( base->image_type == it_mono )
-#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 )
-	    base->trans = info_ptr->trans_alpha[0];
-#else
-	    base->trans = info_ptr->trans[0];
-#endif
+	    base->trans = trans_alpha[0];
 	else
-#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 )
-	    base->clut->trans_index = base->trans = info_ptr->trans_alpha[0];
-#else
-	    base->clut->trans_index = base->trans = info_ptr->trans[0];
-#endif
+	    base->clut->trans_index = base->trans = trans_alpha[0];
     }
 
-    row_pointers = galloc(info_ptr->height*sizeof(png_bytep));
-    for ( i=0; i<info_ptr->height; ++i )
+    row_pointers = galloc(_png_get_image_height(png_ptr,info_ptr)*sizeof(png_bytep));
+    for ( i=0; i<_png_get_image_height(png_ptr,info_ptr); ++i )
 	row_pointers[i] = (png_bytep) (base->data + i*base->bytes_per_line);
 
     /* Ignore progressive loads for now */
@@ -254,7 +274,7 @@ return( NULL );
     _png_read_image(png_ptr,row_pointers);
     _png_read_end(png_ptr, NULL);
 
-    if ( info_ptr->color_type==PNG_COLOR_TYPE_RGB || info_ptr->color_type==PNG_COLOR_TYPE_RGB_ALPHA ) {
+    if ( _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_RGB || _png_get_color_type(png_ptr, info_ptr)==PNG_COLOR_TYPE_RGB_ALPHA ) {
 	/* PNG orders its bytes as AABBGGRR instead of 00RRGGBB */
 	uint32 *ipt, *iend;
 	for ( ipt = (uint32 *) (base->data), iend=ipt+base->width*base->height; ipt<iend; ++ipt ) {