1 $NetBSD: patch-ae,v 1.13 2011/04/19 10:28:31 wiz Exp $
3 Fix build with png-1.5.
4 https://bugzilla.gnome.org/show_bug.cgi?id=640409
6 --- plug-ins/common/file-mng.c.orig 2010-07-02 22:51:56.000000000 +0000
7 +++ plug-ins/common/file-mng.c
8 @@ -799,6 +799,13 @@ mng_save_image (const gchar *filename,
9 png_infop png_info_ptr;
10 FILE *infile, *outfile;
16 + png_bytep trans_alpha;
18 + png_color_16p trans_color;
20 guchar **layer_pixels, *layer_pixel;
21 int pass, j, k, begin, end, num;
22 @@ -969,7 +976,7 @@ mng_save_image (const gchar *filename,
26 - if (setjmp (png_ptr->jmpbuf) != 0)
27 + if (setjmp (png_jmpbuf(png_ptr)) != 0)
29 g_warning ("HRM saving PNG in mng_save_image()");
30 png_destroy_write_struct (&png_ptr, &png_info_ptr);
31 @@ -981,37 +988,31 @@ mng_save_image (const gchar *filename,
32 png_init_io (png_ptr, outfile);
33 png_set_compression_level (png_ptr, mng_data.compression_level);
35 - png_info_ptr->width = layer_cols;
36 - png_info_ptr->height = layer_rows;
37 - png_info_ptr->interlace_type = (mng_data.interlaced == 0 ? 0 : 1);
38 - png_info_ptr->bit_depth = 8;
41 switch (layer_drawable_type)
44 - png_info_ptr->color_type = PNG_COLOR_TYPE_RGB;
45 + color_type = PNG_COLOR_TYPE_RGB;
48 - png_info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
49 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
52 - png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
53 + color_type = PNG_COLOR_TYPE_GRAY;
55 case GIMP_GRAYA_IMAGE:
56 - png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
57 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
59 case GIMP_INDEXED_IMAGE:
60 - png_info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
61 - png_info_ptr->valid |= PNG_INFO_PLTE;
62 - png_info_ptr->palette =
63 - (png_colorp) gimp_image_get_colormap (image_id, &num_colors);
64 - png_info_ptr->num_palette = num_colors;
66 case GIMP_INDEXEDA_IMAGE:
67 - png_info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
68 - layer_has_unique_palette =
69 - respin_cmap (png_ptr, png_info_ptr, layer_remap,
70 - image_id, layer_drawable);
71 + color_type = PNG_COLOR_TYPE_PALETTE;
72 + gimp_image_get_colormap (image_id, &num_colors);
73 + if (num_palette <= 2)
75 + else if (num_palette <= 4)
77 + else if (num_palette <= 16)
81 g_warning ("This can't be!\n");
82 @@ -1021,16 +1022,14 @@ mng_save_image (const gchar *filename,
86 - if ((png_info_ptr->valid & PNG_INFO_PLTE) == PNG_INFO_PLTE)
88 - if (png_info_ptr->num_palette <= 2)
89 - png_info_ptr->bit_depth = 1;
90 - else if (png_info_ptr->num_palette <= 4)
91 - png_info_ptr->bit_depth = 2;
92 - else if (png_info_ptr->num_palette <= 16)
93 - png_info_ptr->bit_depth = 4;
95 + png_set_IHDR(png_ptr, png_info_ptr, layer_cols, layer_rows, bit_depth, color_type, (mng_data.interlaced == 0 ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7), PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
97 + if (layer_drawable_type == GIMP_INDEXED_IMAGE)
98 + png_set_PLTE(png_ptr, png_info_ptr, (png_colorp) gimp_image_get_colormap (image_id, &num_colors), num_colors);
99 + else if (layer_drawable_type == GIMP_INDEXEDA_IMAGE)
100 + layer_has_unique_palette =
101 + respin_cmap (png_ptr, png_info_ptr, layer_remap,
102 + image_id, layer_drawable);
103 png_write_info (png_ptr, png_info_ptr);
105 if (mng_data.interlaced != 0)
106 @@ -1038,8 +1037,8 @@ mng_save_image (const gchar *filename,
110 - if ((png_info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) &&
111 - (png_info_ptr->bit_depth < 8))
112 + if ((png_get_color_type(png_ptr, png_info_ptr) == PNG_COLOR_TYPE_PALETTE) &&
113 + (png_get_bit_depth(png_ptr, png_info_ptr) < 8))
114 png_set_packing (png_ptr);
116 tile_height = gimp_tile_height ();
117 @@ -1065,7 +1064,7 @@ mng_save_image (const gchar *filename,
118 gimp_pixel_rgn_get_rect (&layer_pixel_rgn, layer_pixel, 0,
119 begin, layer_cols, num);
121 - if ((png_info_ptr->valid & PNG_INFO_tRNS) == PNG_INFO_tRNS)
122 + if (png_get_tRNS(png_ptr, png_info_ptr, &trans_alpha, &num_trans, &trans_color) != 0)
124 for (j = 0; j < num; j++)
126 @@ -1077,7 +1076,7 @@ mng_save_image (const gchar *filename,
130 - if (((png_info_ptr->valid & PNG_INFO_PLTE) == PNG_INFO_PLTE)
131 + if ((png_get_PLTE(png_ptr, png_info_ptr, &palette, &num_palette) != 0)
134 for (j = 0; j < num; j++)
135 $NetBSD: patch-af,v 1.8 2011/04/19 10:28:31 wiz Exp $
137 Fix build with png-1.5.
138 https://bugzilla.gnome.org/show_bug.cgi?id=640409
140 --- plug-ins/common/file-png.c.orig 2010-07-13 20:22:27.000000000 +0000
141 +++ plug-ins/common/file-png.c
142 @@ -653,7 +653,11 @@ on_read_error (png_structp png_ptr, png_
143 error_data->drawable->width, num);
146 +#if (PNG_LIBPNG_VER < 10500)
147 longjmp (png_ptr->jmpbuf, 1);
149 + png_longjmp (png_ptr, 1);
154 @@ -697,7 +701,7 @@ load_image (const gchar *filename,
155 pp = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
156 info = png_create_info_struct (pp);
158 - if (setjmp (pp->jmpbuf))
159 + if (setjmp (png_jmpbuf(pp)))
161 g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
162 _("Error while reading '%s'. File corrupted?"),
163 @@ -738,17 +742,17 @@ load_image (const gchar *filename,
164 * Latest attempt, this should be my best yet :)
167 - if (info->bit_depth == 16)
168 + if (png_get_bit_depth(pp, info) == 16)
170 png_set_strip_16 (pp);
173 - if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8)
174 + if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(pp, info) < 8)
179 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
180 + if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp, info) < 8)
182 png_set_packing (pp);
184 @@ -757,8 +761,8 @@ load_image (const gchar *filename,
185 * Expand G+tRNS to GA, RGB+tRNS to RGBA
188 - if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
189 - (info->valid & PNG_INFO_tRNS))
190 + if (png_get_color_type(pp, info) != PNG_COLOR_TYPE_PALETTE &&
191 + png_get_valid(pp, info, PNG_INFO_tRNS) != 0)
195 @@ -775,7 +779,7 @@ load_image (const gchar *filename,
198 if (png_get_valid (pp, info, PNG_INFO_tRNS) &&
199 - info->color_type == PNG_COLOR_TYPE_PALETTE)
200 + png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE)
202 png_get_tRNS (pp, info, &alpha_ptr, &num, NULL);
203 /* Copy the existing alpha values from the tRNS chunk */
204 @@ -797,7 +801,7 @@ load_image (const gchar *filename,
206 png_read_update_info (pp, info);
208 - switch (info->color_type)
209 + switch (png_get_color_type(pp, info))
211 case PNG_COLOR_TYPE_RGB: /* RGB */
213 @@ -836,7 +840,7 @@ load_image (const gchar *filename,
217 - image = gimp_image_new (info->width, info->height, image_type);
218 + image = gimp_image_new (png_get_image_width(pp, info), png_get_image_height(pp, info), image_type);
221 g_set_error (error, 0, 0,
222 @@ -849,7 +853,7 @@ load_image (const gchar *filename,
223 * Create the "background" layer to hold the image...
226 - layer = gimp_layer_new (image, _("Background"), info->width, info->height,
227 + layer = gimp_layer_new (image, _("Background"), png_get_image_width(pp, info), png_get_image_height(pp, info),
228 layer_type, 100, GIMP_NORMAL_MODE);
229 gimp_image_add_layer (image, layer, 0);
231 @@ -883,7 +887,7 @@ load_image (const gchar *filename,
233 gimp_layer_set_offsets (layer, offset_x, offset_y);
235 - if ((abs (offset_x) > info->width) || (abs (offset_y) > info->height))
236 + if ((abs (offset_x) > png_get_image_width(pp, info)) || (abs (offset_y) > png_get_image_height(pp, info)))
239 g_message (_("The PNG file specifies an offset that caused "
240 @@ -938,23 +942,27 @@ load_image (const gchar *filename,
242 empty = 0; /* by default assume no full transparent palette entries */
244 - if (info->color_type & PNG_COLOR_MASK_PALETTE)
245 + if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE)
247 + png_colorp palette;
249 + png_get_PLTE(pp, info, &palette, &num_palette);
251 if (png_get_valid (pp, info, PNG_INFO_tRNS))
253 for (empty = 0; empty < 256 && alpha[empty] == 0; ++empty)
254 /* Calculates number of fully transparent "empty" entries */;
256 /* keep at least one entry */
257 - empty = MIN (empty, info->num_palette - 1);
258 + empty = MIN (empty, num_palette - 1);
260 - gimp_image_set_colormap (image, (guchar *) (info->palette + empty),
261 - info->num_palette - empty);
262 + gimp_image_set_colormap (image, (guchar *) (palette + empty),
263 + num_palette - empty);
267 - gimp_image_set_colormap (image, (guchar *) info->palette,
268 - info->num_palette);
269 + gimp_image_set_colormap (image, (guchar *) palette,
274 @@ -972,18 +980,18 @@ load_image (const gchar *filename,
277 tile_height = gimp_tile_height ();
278 - pixel = g_new0 (guchar, tile_height * info->width * bpp);
279 + pixel = g_new0 (guchar, tile_height * png_get_image_width(pp, info) * bpp);
280 pixels = g_new (guchar *, tile_height);
282 for (i = 0; i < tile_height; i++)
283 - pixels[i] = pixel + info->width * info->channels * i;
284 + pixels[i] = pixel + png_get_image_width(pp, info) * png_get_channels(pp, info) * i;
286 /* Install our own error handler to handle incomplete PNG files better */
287 error_data.drawable = drawable;
288 error_data.pixel = pixel;
289 error_data.tile_height = tile_height;
290 - error_data.width = info->width;
291 - error_data.height = info->height;
292 + error_data.width = png_get_image_width(pp, info);
293 + error_data.height = png_get_image_height(pp, info);
294 error_data.bpp = bpp;
295 error_data.pixel_rgn = &pixel_rgn;
297 @@ -996,10 +1004,10 @@ load_image (const gchar *filename,
300 for (begin = 0, end = tile_height;
301 - begin < info->height; begin += tile_height, end += tile_height)
302 + begin < png_get_image_height(pp, info); begin += tile_height, end += tile_height)
304 - if (end > info->height)
305 - end = info->height;
306 + if (end > png_get_image_height(pp, info))
307 + end = png_get_image_height(pp, info);
311 @@ -1016,10 +1024,10 @@ load_image (const gchar *filename,
312 gimp_pixel_rgn_set_rect (&pixel_rgn, pixel, 0, begin,
313 drawable->width, num);
315 - memset (pixel, 0, tile_height * info->width * bpp);
316 + memset (pixel, 0, tile_height * png_get_image_width(pp, info) * bpp);
318 gimp_progress_update (((gdouble) pass +
319 - (gdouble) end / (gdouble) info->height) /
320 + (gdouble) end / (gdouble) png_get_image_height(pp, info)) /
321 (gdouble) num_passes);
324 @@ -1072,7 +1080,8 @@ load_image (const gchar *filename,
328 - png_charp profname, profile;
329 + png_charp profname;
333 if (png_get_iCCP (pp, info, &profname, &profcomp, &profile, &proflen))
334 @@ -1200,6 +1209,8 @@ save_image (const gchar *filename,
335 guchar red, green, blue; /* Used for palette background */
336 time_t cutime; /* Time since epoch */
337 struct tm *gmt; /* GMT broken down */
338 + int color_type; /* type of colors in image */
339 + int bit_depth; /* width of colors in bit */
341 guchar remap[256]; /* Re-mapping for the palette */
343 @@ -1208,7 +1219,9 @@ save_image (const gchar *filename,
346 GimpParasite *parasite;
347 +#ifndef PNG_iTXt_SUPPORTED
348 gsize text_length = 0;
351 parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
353 @@ -1249,7 +1262,7 @@ save_image (const gchar *filename,
354 pp = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
355 info = png_create_info_struct (pp);
357 - if (setjmp (pp->jmpbuf))
358 + if (setjmp (png_jmpbuf(pp)))
360 g_set_error (error, 0, 0,
361 _("Error while saving '%s'. Could not save image."),
362 @@ -1291,11 +1304,6 @@ save_image (const gchar *filename,
364 png_set_compression_level (pp, pngvals.compression_level);
366 - info->width = drawable->width;
367 - info->height = drawable->height;
368 - info->bit_depth = 8;
369 - info->interlace_type = pngvals.interlaced;
374 @@ -1304,44 +1312,48 @@ save_image (const gchar *filename,
377 * Set color type and remember bytes per pixel count
378 + * Also fix bit depths for (possibly) smaller colormap images
386 - info->color_type = PNG_COLOR_TYPE_RGB;
387 + color_type = PNG_COLOR_TYPE_RGB;
391 case GIMP_RGBA_IMAGE:
392 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
393 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
397 case GIMP_GRAY_IMAGE:
398 - info->color_type = PNG_COLOR_TYPE_GRAY;
399 + color_type = PNG_COLOR_TYPE_GRAY;
403 case GIMP_GRAYA_IMAGE:
404 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
405 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
409 case GIMP_INDEXED_IMAGE:
410 + case GIMP_INDEXEDA_IMAGE:
412 - info->color_type = PNG_COLOR_TYPE_PALETTE;
413 - info->valid |= PNG_INFO_PLTE;
415 - (png_colorp) gimp_image_get_colormap (image_ID, &num_colors);
416 - info->num_palette = num_colors;
418 + if (type == GIMP_INDEXEDA_IMAGE)
421 - case GIMP_INDEXEDA_IMAGE:
423 - info->color_type = PNG_COLOR_TYPE_PALETTE;
424 - /* fix up transparency */
425 - respin_cmap (pp, info, remap, image_ID, drawable);
426 + color_type = PNG_COLOR_TYPE_PALETTE;
427 + gimp_image_get_colormap (image_ID, &num_colors);
428 + if (num_colors <= 2)
430 + else if (num_colors <= 4)
432 + else if (num_colors <= 16)
434 + /* otherwise the default is fine */
438 @@ -1349,19 +1361,14 @@ save_image (const gchar *filename,
443 - * Fix bit depths for (possibly) smaller colormap images
445 + png_set_IHDR(pp, info, drawable->width, drawable->height, bit_depth, color_type, pngvals.interlaced ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
447 - if (info->valid & PNG_INFO_PLTE)
448 + if (type == GIMP_INDEXED_IMAGE)
449 + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_colormap (image_ID, &num_colors), num_colors);
450 + else if (type == GIMP_INDEXEDA_IMAGE)
452 - if (info->num_palette <= 2)
453 - info->bit_depth = 1;
454 - else if (info->num_palette <= 4)
455 - info->bit_depth = 2;
456 - else if (info->num_palette <= 16)
457 - info->bit_depth = 4;
458 - /* otherwise the default is fine */
459 + /* fix up transparency */
460 + respin_cmap (pp, info, remap, image_ID, drawable);
463 /* All this stuff is optional extras, if the user is aiming for smallest
464 @@ -1477,7 +1484,7 @@ save_image (const gchar *filename,
465 * Convert unpacked pixels to packed if necessary
468 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
469 + if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp, info) < 8)
470 png_set_packing (pp);
473 @@ -1529,7 +1536,7 @@ save_image (const gchar *filename,
475 /* If we're dealing with a paletted image with
476 * transparency set, write out the remapped palette */
477 - if (info->valid & PNG_INFO_tRNS)
478 + if (png_get_valid(pp, info, PNG_INFO_tRNS))
480 guchar inverse_remap[256];
482 @@ -1549,7 +1556,7 @@ save_image (const gchar *filename,
484 /* Otherwise if we have a paletted image and transparency
485 * couldn't be set, we ignore the alpha channel */
486 - else if (info->valid & PNG_INFO_PLTE && bpp == 2)
487 + else if (png_get_valid(pp, info, PNG_INFO_PLTE) && bpp == 2)
489 for (i = 0; i < num; ++i)
491 @@ -1564,7 +1571,7 @@ save_image (const gchar *filename,
492 png_write_rows (pp, pixels, num);
494 gimp_progress_update (((double) pass + (double) end /
495 - (double) info->height) /
496 + (double) png_get_image_height(pp, info)) /
497 (double) num_passes);