wok-next view cinepaint/stuff/patches/cinepaint-1.4-png.patch @ rev 21395

updated owfs (3.2p1 -> 3.2p3)
author Hans-G?nter Theisgen
date Fri Apr 17 17:54:29 2020 +0100 (2020-04-17)
parents
children
line source
1 diff -ur cinepaint/plug-ins/png/png.c cinepaint-png15/plug-ins/png/png.c
2 --- cinepaint/plug-ins/png/png.c 2006-11-24 15:52:55.000000000 -0500
3 +++ cinepaint-png15/plug-ins/png/png.c 2013-03-02 03:37:33.304142225 -0500
4 @@ -405,7 +405,7 @@
5 info = (png_infop)calloc(sizeof(png_info), 1);
6 #endif /* PNG_LIBPNG_VER > 88 */
8 - if (setjmp (pp->jmpbuf))
9 + if (setjmp (png_jmpbuf(pp)))
10 {
11 g_message ("%s\nPNG error. File corrupted?", filename);
12 return image;
13 @@ -448,15 +448,15 @@
14 */
16 #ifndef WORDS_BIGENDIAN
17 - if(info->bit_depth == 16)
18 + if(png_get_bit_depth(pp,info) == 16)
19 png_set_swap(pp);
20 #endif
22 - if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8) {
23 + if (png_get_color_type(pp,info) == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(pp,info) < 8) {
24 png_set_expand(pp);
25 }
27 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) {
28 + if (png_get_color_type(pp,info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp,info) < 8) {
29 png_set_packing(pp);
30 }
32 @@ -464,8 +464,8 @@
33 * Expand G+tRNS to GA, RGB+tRNS to RGBA
34 */
36 - if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
37 - (info->valid & PNG_INFO_tRNS)) {
38 + if (png_get_color_type(pp,info) != PNG_COLOR_TYPE_PALETTE &&
39 + (png_get_valid(pp,info,PNG_INFO_tRNS) & PNG_INFO_tRNS)) {
40 png_set_expand(pp);
41 }
43 @@ -482,7 +482,7 @@
45 #if PNG_LIBPNG_VER > 99
46 if (png_get_valid(pp, info, PNG_INFO_tRNS) &&
47 - info->color_type == PNG_COLOR_TYPE_PALETTE)
48 + png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE)
49 {
50 png_get_tRNS(pp, info, &alpha_ptr, &num, NULL);
51 /* Copy the existing alpha values from the tRNS chunk */
52 @@ -505,9 +505,9 @@
54 png_read_update_info(pp, info);
56 - if(info->bit_depth==16)
57 + if(png_get_bit_depth(pp,info)==16)
58 {
59 - switch (info->color_type)
60 + switch (png_get_color_type(pp, info))
61 {
62 case PNG_COLOR_TYPE_RGB : /* RGB */
63 bpp = 6;
64 @@ -545,7 +545,7 @@
65 }
66 else
67 {
68 - switch (info->color_type)
69 + switch (png_get_color_type(pp, info))
70 {
71 case PNG_COLOR_TYPE_RGB : /* RGB */
72 bpp = 3;
73 @@ -582,7 +582,7 @@
74 };
75 }
77 - image = gimp_image_new(info->width, info->height, image_type);
78 + image = gimp_image_new(png_get_image_width(pp,info), png_get_image_height(pp,info), image_type);
79 if (image == -1)
80 {
81 g_message("Can't allocate new image\n%s", filename);
82 @@ -595,7 +595,7 @@
83 * Create the "background" layer to hold the image...
84 */
86 - layer = gimp_layer_new(image, _("Background"), info->width, info->height,
87 + layer = gimp_layer_new(image, _("Background"), png_get_image_width(pp,info), png_get_image_height(pp,info),
88 layer_type, 100, NORMAL_MODE);
89 gimp_image_add_layer(image, layer, 0);
91 @@ -627,20 +627,23 @@
93 empty= 0; /* by default assume no full transparent palette entries */
95 - if (info->color_type & PNG_COLOR_MASK_PALETTE) {
96 + if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE) {
97 + png_colorp palette;
98 + int num_palette;
99 + png_get_PLTE(pp, info, &palette, &num_palette);
100 +
102 #if PNG_LIBPNG_VER > 99
103 if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
104 for (empty= 0; empty < 256 && alpha[empty] == 0; ++empty);
105 /* Calculates number of fully transparent "empty" entries */
107 - gimp_image_set_cmap(image, (guchar *) (info->palette + empty),
108 - info->num_palette - empty);
109 + gimp_image_set_cmap(image, (guchar *) &palette + empty,num_palette - empty);
110 } else {
111 - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
112 + gimp_image_set_cmap(image, (guchar *)&palette, num_palette);
113 }
114 #else
115 - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
116 + gimp_image_set_cmap(image, (guchar *)&palette, num_palette);
117 #endif /* PNG_LIBPNG_VER > 99 */
119 }
120 @@ -659,18 +662,18 @@
121 */
123 tile_height = gimp_tile_height ();
124 - pixel = g_new(guchar, tile_height * info->width * bpp);
125 + pixel = g_new(guchar, tile_height * png_get_image_width(pp,info) * bpp);
126 pixels = g_new(guchar *, tile_height);
128 - if(info->bit_depth==16)
129 + if(png_get_bit_depth(pp,info)==16)
130 {
131 for (i = 0; i < tile_height; i ++)
132 - pixels[i] = pixel + info->width * info->channels * i * 2;
133 + pixels[i] = pixel + png_get_image_width(pp,info) * png_get_channels(pp,info) * i * 2;
134 }
135 else
136 {
137 for (i = 0; i < tile_height; i ++)
138 - pixels[i] = pixel + info->width * info->channels * i;
139 + pixels[i] = pixel + png_get_image_width(pp,info) * png_get_channels(pp,info) * i;
140 }
142 for (pass = 0; pass < num_passes; pass ++)
143 @@ -680,11 +683,11 @@
144 */
146 for (begin = 0, end = tile_height;
147 - begin < info->height;
148 + begin < png_get_image_height(pp,info);
149 begin += tile_height, end += tile_height)
150 {
151 - if (end > info->height)
152 - end = info->height;
153 + if (end > png_get_image_height(pp,info))
154 + end = png_get_image_height(pp,info);
156 num = end - begin;
158 @@ -697,21 +700,24 @@
159 gimp_pixel_rgn_set_rect(&pixel_rgn, pixel, 0, begin,
160 drawable->width, num);
162 - gimp_progress_update(((double)pass + (double)end / (double)info->height) /
163 + gimp_progress_update(((double)pass + (double)end / (double)png_get_image_height(pp,info)) /
164 (double)num_passes);
165 };
166 };
168 #if defined(PNG_iCCP_SUPPORTED)
169 +{
170 /* set icc profile */
171 - if (info->iccp_proflen > 0) {
172 - gimp_image_set_icc_profile_by_mem (image, info->iccp_proflen,
173 - info->iccp_profile,
174 - ICC_IMAGE_PROFILE);
175 + png_charpp name;
176 + int ctype = PNG_COMPRESSION_TYPE_BASE;
177 + png_bytepp prof;
178 + png_uint_32 proflen;
179 + if (png_get_iCCP(pp,info,name,&ctype,prof,&proflen) > 0) {
180 + gimp_image_set_icc_profile_by_mem (image, proflen, prof, ICC_IMAGE_PROFILE);
181 printf ("%s:%d %s() set embedded profile \"%s\"\n",
182 - __FILE__,__LINE__,__func__,
183 - info->iccp_name);
184 + __FILE__,__LINE__,__func__,(const char *)name);
185 }
186 +}
187 #endif
189 /*
190 @@ -774,6 +780,8 @@
191 * 'save_image ()' - Save the specified image to a PNG file.
192 */
194 +typedef png_info *png_infop;
195 +
196 static gint
197 save_image (gchar *filename, /* I - File to save to */
198 gint32 image_ID, /* I - Image to save */
199 @@ -794,7 +802,7 @@
200 GPixelRgn pixel_rgn; /* Pixel region for layer */
201 png_structp pp; /* PNG read pointer */
202 png_infop info; /* PNG info pointer */
203 - gint num_colors; /* Number of colors in colormap */
204 + gint num_colors = 0; /* Number of colors in colormap */
205 gint offx, offy; /* Drawable offsets from origin */
206 guchar **pixels, /* Pixel rows */
207 *fixed, /* Fixed-up pixel data */
208 @@ -808,6 +816,7 @@
209 blue; /* Used for palette background */
210 time_t cutime; /* Time since epoch */
211 struct tm *gmt; /* GMT broken down */
212 + int bit_depth,color_type;
214 /*
215 * PNG 0.89 and newer have a sane, forwards compatible constructor.
216 @@ -824,7 +833,7 @@
217 info = (png_infop)calloc(sizeof(png_info), 1);
218 #endif /* PNG_LIBPNG_VER > 88 */
220 - if (setjmp (pp->jmpbuf))
221 + if (setjmp (png_jmpbuf(pp)))
222 {
223 g_message ("%s\nPNG error. Couldn't save image", filename);
224 return 0;
225 @@ -863,10 +872,6 @@
227 png_set_compression_level (pp, pngvals.compression_level);
229 - info->width = drawable->width;
230 - info->height = drawable->height;
231 - info->interlace_type = pngvals.interlaced;
232 -
233 /*
234 * Set color type and remember bytes per pixel count
235 */
236 @@ -874,71 +879,69 @@
237 switch (type)
238 {
239 case RGB_IMAGE :
240 - info->color_type = PNG_COLOR_TYPE_RGB;
241 - info->bit_depth = 8;
242 + color_type = PNG_COLOR_TYPE_RGB;
243 + bit_depth = 8;
244 bpp = 3;
245 break;
246 case RGBA_IMAGE :
247 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
248 - info->bit_depth = 8;
249 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
250 + bit_depth = 8;
251 bpp = 4;
252 break;
253 case GRAY_IMAGE :
254 - info->color_type = PNG_COLOR_TYPE_GRAY;
255 - info->bit_depth = 8;
256 + color_type = PNG_COLOR_TYPE_GRAY;
257 + bit_depth = 8;
258 bpp = 1;
259 break;
260 case GRAYA_IMAGE :
261 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
262 - info->bit_depth = 8;
263 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
264 + bit_depth = 8;
265 bpp = 2;
266 break;
267 case INDEXED_IMAGE :
268 bpp = 1;
269 - info->bit_depth = 8;
270 - info->color_type = PNG_COLOR_TYPE_PALETTE;
271 - info->valid |= PNG_INFO_PLTE;
272 - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
273 - info->num_palette= num_colors;
274 + bit_depth = 8;
275 + color_type = PNG_COLOR_TYPE_PALETTE;
276 + void *plte = gimp_image_get_cmap(image_ID, &num_colors);
277 + png_set_PLTE(pp,info,plte,num_colors);
278 break;
279 case INDEXEDA_IMAGE :
280 bpp = 2;
281 - info->bit_depth = 8;
282 - info->color_type = PNG_COLOR_TYPE_PALETTE;
283 + bit_depth = 8;
284 + color_type = PNG_COLOR_TYPE_PALETTE;
285 respin_cmap (pp, info, image_ID); /* fix up transparency */
286 break;
287 case U16_RGB_IMAGE :
288 - info->color_type = PNG_COLOR_TYPE_RGB;
289 - info->bit_depth = 16;
290 + color_type = PNG_COLOR_TYPE_RGB;
291 + bit_depth = 16;
292 bpp = 6;
293 break;
294 case U16_RGBA_IMAGE :
295 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
296 - info->bit_depth = 16;
297 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
298 + bit_depth = 16;
299 bpp = 8;
300 break;
301 case U16_GRAY_IMAGE :
302 - info->color_type = PNG_COLOR_TYPE_GRAY;
303 - info->bit_depth = 16;
304 + color_type = PNG_COLOR_TYPE_GRAY;
305 + bit_depth = 16;
306 bpp = 2;
307 break;
308 case U16_GRAYA_IMAGE :
309 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
310 - info->bit_depth = 16;
311 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
312 + bit_depth = 16;
313 bpp = 4;
314 break;
315 - case U16_INDEXED_IMAGE :
316 + case U16_INDEXED_IMAGE :{
317 bpp = 2;
318 - info->bit_depth = 16;
319 - info->color_type = PNG_COLOR_TYPE_PALETTE;
320 - info->valid |= PNG_INFO_PLTE;
321 - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
322 - info->num_palette= num_colors;
323 + bit_depth = 16;
324 + color_type = PNG_COLOR_TYPE_PALETTE;
325 + void *plte = gimp_image_get_cmap(image_ID, &num_colors);
326 + png_set_PLTE(pp,info,plte,num_colors);
327 break;
328 - case U16_INDEXEDA_IMAGE :
329 + }case U16_INDEXEDA_IMAGE :
330 bpp = 4;
331 - info->bit_depth = 16;
332 - info->color_type = PNG_COLOR_TYPE_PALETTE;
333 + bit_depth = 16;
334 + color_type = PNG_COLOR_TYPE_PALETTE;
335 respin_cmap (pp, info, image_ID); /* fix up transparency */
336 break;
337 default:
338 @@ -950,16 +953,21 @@
339 * Fix bit depths for (possibly) smaller colormap images
340 */
342 - if (info->valid & PNG_INFO_PLTE) {
343 - if (info->num_palette <= 2)
344 - info->bit_depth= 1;
345 - else if (info->num_palette <= 4)
346 - info->bit_depth= 2;
347 - else if (info->num_palette <= 16)
348 - info->bit_depth= 4;
349 + if (png_get_valid(pp,info,PNG_INFO_PLTE) & PNG_INFO_PLTE) {
350 + if (num_colors <= 2)
351 + bit_depth= 1;
352 + else if (num_colors <= 4)
353 + bit_depth= 2;
354 + else if (num_colors <= 16)
355 + bit_depth= 4;
356 /* otherwise the default is fine */
357 }
359 + png_set_IHDR(pp,info,drawable->width,drawable->height,
360 + bit_depth,color_type,pngvals.interlaced,
361 + PNG_COMPRESSION_TYPE_DEFAULT,
362 + PNG_FILTER_TYPE_DEFAULT);
363 +
364 // write icc profile
365 #if defined(PNG_iCCP_SUPPORTED)
366 if (gimp_image_has_icc_profile (image_ID, ICC_IMAGE_PROFILE)) {
367 @@ -973,7 +981,7 @@
368 0, buffer, size);
369 printf ("%s:%d %s() embedd icc profile \"%s\"\n",
370 __FILE__,__LINE__,__func__,
371 - info->iccp_name);
372 + gimp_image_get_icc_profile_description (image_ID, ICC_IMAGE_PROFILE));
373 }
374 #endif
376 @@ -1039,13 +1047,13 @@
377 * Convert unpacked pixels to packed if necessary
378 */
380 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
381 + if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp,info) < 8)
382 png_set_packing(pp);
384 /* Set swapping for 16 bit per sample images */
386 #ifndef WORDS_BIGENDIAN
387 - if (info->bit_depth == 16)
388 + if (png_get_bit_depth(pp,info) == 16)
389 png_set_swap(pp);
390 #endif
392 @@ -1077,7 +1085,7 @@
393 num = end - begin;
395 gimp_pixel_rgn_get_rect (&pixel_rgn, pixel, 0, begin, drawable->width, num);
396 - if (info->valid & PNG_INFO_tRNS) {
397 + if (png_get_valid(pp,info,PNG_INFO_tRNS) & PNG_INFO_tRNS) {
398 for (i = 0; i < num; ++i) {
399 fixed= pixels[i];
400 for (k = 0; k < drawable->width; ++k) {
401 @@ -1085,7 +1093,7 @@
402 }
403 }
404 /* Forgot this case before, what if there are too many colors? */
405 - } else if (info->valid & PNG_INFO_PLTE && bpp == 2) {
406 + } else if (png_get_valid(pp,info,PNG_INFO_PLTE) & PNG_INFO_PLTE && bpp == 2) {
407 for (i = 0; i < num; ++i) {
408 fixed= pixels[i];
409 for (k = 0; k < drawable->width; ++k) {
410 @@ -1097,7 +1105,7 @@
411 png_write_rows (pp, pixels, num);
413 gimp_progress_update (((double)pass + (double)end /
414 - (double)info->height) / (double)num_passes);
415 + (double)png_get_image_height(pp,info)) / (double)num_passes);
416 };
417 };