]>
Commit | Line | Data |
---|---|---|
31c89272 AM |
1 | From 5b7ac4f5eb2b80802cfbd975cd37abcd6895fd16 Mon Sep 17 00:00:00 2001 |
2 | From: Paul Flo Williams <paul@frixxon.co.uk> | |
3 | Date: Wed, 7 Dec 2011 09:36:51 +0000 | |
4 | Subject: [PATCH] Support libpng 1.5 by only using accessor functions to png | |
5 | structures | |
6 | ||
7 | --- | |
8 | gutils/gimagewritepng.c | 100 +++++++++++++++++++++++----------------------- | |
9 | 1 files changed, 50 insertions(+), 50 deletions(-) | |
10 | ||
11 | diff --git a/gutils/gimagewritepng.c b/gutils/gimagewritepng.c | |
12 | index 43fa097..6ed4b04 100644 | |
13 | --- a/gutils/gimagewritepng.c | |
14 | +++ b/gutils/gimagewritepng.c | |
15 | @@ -236,6 +236,7 @@ return(false); | |
16 | } | |
17 | } else { | |
18 | if ( base->trans!=-1 ) { | |
19 | + trans_color = galloc(sizeof(png_color16)); | |
20 | trans_color->red = COLOR_RED(base->trans); | |
21 | trans_color->green = COLOR_GREEN(base->trans); | |
22 | trans_color->blue = COLOR_BLUE(base->trans); | |
23 | @@ -258,6 +259,7 @@ return(false); | |
24 | _png_write_end(png_ptr, info_ptr); | |
25 | ||
26 | if ( trans_alpha!=NULL ) gfree(trans_alpha); | |
27 | + if ( trans_color!=NULL ) gfree(trans_color); | |
28 | if ( palette!=NULL ) gfree(palette); | |
29 | _png_destroy_write_struct(&png_ptr, &info_ptr); | |
30 | gfree(rows); | |
31 | @@ -296,7 +298,7 @@ static void user_error_fn(png_structp png_ptr, png_const_charp error_msg) { | |
32 | #if (PNG_LIBPNG_VER < 10500) | |
33 | longjmp(png_ptr->jmpbuf,1); | |
34 | #else | |
35 | - _png_longjmp (png_ptr, 1); | |
36 | + png_longjmp (png_ptr, 1); | |
37 | #endif | |
38 | } | |
39 | ||
40 | @@ -310,6 +312,12 @@ int GImageWrite_Png(GImage *gi, FILE *fp, int progressive) { | |
41 | png_infop info_ptr; | |
42 | png_byte **rows; | |
43 | int i; | |
44 | + int bit_depth; | |
45 | + int color_type; | |
46 | + int num_palette; | |
47 | + png_bytep trans_alpha = NULL; | |
48 | + png_color_16p trans_color = NULL; | |
49 | + png_colorp palette = NULL; | |
50 | ||
51 | png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, | |
52 | (void *)NULL, user_error_fn, user_warning_fn); | |
53 | @@ -336,65 +344,60 @@ return(false); | |
54 | ||
55 | png_init_io(png_ptr, fp); | |
56 | ||
57 | - info_ptr->width = base->width; | |
58 | - info_ptr->height = base->height; | |
59 | - info_ptr->bit_depth = 8; | |
60 | - info_ptr->valid = 0; | |
61 | - info_ptr->interlace_type = progressive; | |
62 | - if ( base->trans!=-1 ) { | |
63 | - info_ptr->num_trans = 1; | |
64 | - info_ptr->valid |= PNG_INFO_tRNS; | |
65 | + bit_depth = 8; | |
66 | + num_palette = base->clut==NULL?2:base->clut->clut_len; | |
67 | + if ( base->image_type==it_index || base->image_type==it_bitmap ) { | |
68 | + color_type = PNG_COLOR_TYPE_PALETTE; | |
69 | + if ( num_palette<=2 ) | |
70 | + bit_depth=1; | |
71 | + else if ( num_palette<=4 ) | |
72 | + bit_depth=2; | |
73 | + else if ( num_palette<=16 ) | |
74 | + bit_depth=4; | |
75 | + } else { | |
76 | + color_type = PNG_COLOR_TYPE_RGB; | |
77 | + if ( base->image_type == it_rgba ) | |
78 | + color_type = PNG_COLOR_TYPE_RGB_ALPHA; | |
79 | } | |
80 | + | |
81 | + png_set_IHDR(png_ptr, info_ptr, base->width, base->height, | |
82 | + bit_depth, color_type, progressive, | |
83 | + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
84 | if ( base->image_type==it_index || base->image_type==it_bitmap ) { | |
85 | - info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; | |
86 | - info_ptr->valid |= PNG_INFO_PLTE; | |
87 | - info_ptr->num_palette = base->clut==NULL?2:base->clut->clut_len; | |
88 | - info_ptr->palette = (png_color *) galloc(info_ptr->num_palette*sizeof(png_color)); | |
89 | + palette = (png_color *) galloc(num_palette*sizeof(png_color)); | |
90 | if ( base->clut==NULL ) { | |
91 | - info_ptr->palette[0].red = info_ptr->palette[0].green = info_ptr->palette[0].blue = 0; | |
92 | - info_ptr->palette[1].red = info_ptr->palette[1].green = info_ptr->palette[1].blue = 0xff; | |
93 | + palette[0].red = palette[0].green = palette[0].blue = 0; | |
94 | + palette[1].red = palette[1].green = palette[1].blue = 0xff; | |
95 | } else { | |
96 | - for ( i=0; i<info_ptr->num_palette; ++i ) { | |
97 | + for ( i=0; i<num_palette; ++i ) { | |
98 | long col = base->clut->clut[i]; | |
99 | - info_ptr->palette[i].red = COLOR_RED(col); | |
100 | - info_ptr->palette[i].green = COLOR_GREEN(col); | |
101 | - info_ptr->palette[i].blue = COLOR_BLUE(col); | |
102 | + palette[i].red = COLOR_RED(col); | |
103 | + palette[i].green = COLOR_GREEN(col); | |
104 | + palette[i].blue = COLOR_BLUE(col); | |
105 | } | |
106 | } | |
107 | - if ( info_ptr->num_palette<=2 ) | |
108 | - info_ptr->bit_depth=1; | |
109 | - else if ( info_ptr->num_palette<=4 ) | |
110 | - info_ptr->bit_depth=2; | |
111 | - else if ( info_ptr->num_palette<=16 ) | |
112 | - info_ptr->bit_depth=4; | |
113 | - if ( info_ptr->num_palette<=16 ) | |
114 | + png_set_PLTE(png_ptr, info_ptr, palette, num_palette); | |
115 | + if ( num_palette<=16 ) | |
116 | png_set_packing(png_ptr); | |
117 | + | |
118 | if ( base->trans!=-1 ) { | |
119 | -#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 ) | |
120 | - info_ptr->trans_alpha = galloc(1); | |
121 | - info_ptr->trans_alpha[0] = base->trans; | |
122 | -#else | |
123 | - info_ptr->trans = galloc(1); | |
124 | - info_ptr->trans[0] = base->trans; | |
125 | -#endif | |
126 | + trans_alpha = galloc(1); | |
127 | + trans_alpha[0] = base->trans; | |
128 | } | |
129 | } else { | |
130 | - info_ptr->color_type = PNG_COLOR_TYPE_RGB; | |
131 | if ( base->trans!=-1 ) { | |
132 | -#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 ) | |
133 | - info_ptr->trans_color.red = COLOR_RED(base->trans); | |
134 | - info_ptr->trans_color.green = COLOR_GREEN(base->trans); | |
135 | - info_ptr->trans_color.blue = COLOR_BLUE(base->trans); | |
136 | -#else | |
137 | - info_ptr->trans_values.red = COLOR_RED(base->trans); | |
138 | - info_ptr->trans_values.green = COLOR_GREEN(base->trans); | |
139 | - info_ptr->trans_values.blue = COLOR_BLUE(base->trans); | |
140 | -#endif | |
141 | + trans_color = galloc(sizeof(png_color_16)); | |
142 | + trans_color->red = COLOR_RED(base->trans); | |
143 | + trans_color->green = COLOR_GREEN(base->trans); | |
144 | + trans_color->blue = COLOR_BLUE(base->trans); | |
145 | } | |
146 | } | |
147 | + if ( base->trans!=-1 ) { | |
148 | + png_set_tRNS(png_ptr, info_ptr, trans_alpha, 1, trans_color); | |
149 | + } | |
150 | png_write_info(png_ptr, info_ptr); | |
151 | ||
152 | - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB) | |
153 | + if (color_type == PNG_COLOR_TYPE_RGB) | |
154 | png_set_filler(png_ptr, '\0', PNG_FILLER_BEFORE); | |
155 | ||
156 | rows = galloc(base->height*sizeof(png_byte *)); | |
157 | @@ -405,12 +408,9 @@ return(false); | |
158 | ||
159 | png_write_end(png_ptr, info_ptr); | |
160 | ||
161 | -#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 ) | |
162 | - if ( info_ptr->trans_alpha!=NULL ) gfree(info_ptr->trans_alpha); | |
163 | -#else | |
164 | - if ( info_ptr->trans!=NULL ) gfree(info_ptr->trans); | |
165 | -#endif | |
166 | - if ( info_ptr->palette!=NULL ) gfree(info_ptr->palette); | |
167 | + if ( trans_alpha!=NULL ) gfree(trans_alpha); | |
168 | + if ( trans_color!=NULL ) gfree(trans_color); | |
169 | + if ( palette!=NULL ) gfree(palette); | |
170 | png_destroy_write_struct(&png_ptr, &info_ptr); | |
171 | gfree(rows); | |
172 | return( 1 ); | |
173 | -- | |
174 | 1.7.7.3 | |
175 | ||
176 | --- fontforge-20110222/configure.in~ 2012-02-11 18:18:03.000000000 +0100 | |
177 | +++ fontforge-20110222/configure.in 2012-02-11 18:25:25.604323722 +0100 | |
178 | @@ -721,6 +721,9 @@ | |
179 | if test "$ac_cv_lib_png14_png_create_read_struct" = "yes"; then | |
180 | STATIC_LIBS="$STATIC_LIBS -lpng14 -lz" | |
181 | fi | |
182 | + if test "$ac_cv_lib_png15_png_create_read_struct" = "yes"; then | |
183 | + STATIC_LIBS="$STATIC_LIBS -lpng15 -lz" | |
184 | + fi | |
185 | if test "$ac_cv_lib_tiff_TIFFOpen" = "yes"; then | |
186 | STATIC_LIBS="$STATIC_LIBS -ltiff" | |
187 | fi |