/[packages]/cauldron/gimp/current/SOURCES/gimp-libpng15-v2.diff
ViewVC logotype

Contents of /cauldron/gimp/current/SOURCES/gimp-libpng15-v2.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144964 - (show annotations) (download)
Sun Sep 18 12:30:33 2011 UTC (11 years ago) by fwang
File size: 18466 byte(s)
fix build with libpng 1.5
1 $NetBSD: patch-ae,v 1.13 2011/04/19 10:28:31 wiz Exp $
2
3 Fix build with png-1.5.
4 https://bugzilla.gnome.org/show_bug.cgi?id=640409
5
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;
11 int num_passes;
12 + int color_type;
13 + png_colorp palette;
14 + int num_palette;
15 + int bit_depth;
16 + png_bytep trans_alpha;
17 + int num_trans;
18 + png_color_16p trans_color;
19 int tile_height;
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,
23 goto err3;
24 }
25
26 - if (setjmp (png_ptr->jmpbuf) != 0)
27 + if (setjmp (png_jmpbuf(png_ptr)) != 0)
28 {
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);
34
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;
39 -
40 + bit_depth = 8;
41 switch (layer_drawable_type)
42 {
43 case GIMP_RGB_IMAGE:
44 - png_info_ptr->color_type = PNG_COLOR_TYPE_RGB;
45 + color_type = PNG_COLOR_TYPE_RGB;
46 break;
47 case GIMP_RGBA_IMAGE:
48 - png_info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
49 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
50 break;
51 case GIMP_GRAY_IMAGE:
52 - png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
53 + color_type = PNG_COLOR_TYPE_GRAY;
54 break;
55 case GIMP_GRAYA_IMAGE:
56 - png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
57 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
58 break;
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;
65 - break;
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)
74 + bit_depth = 1;
75 + else if (num_palette <= 4)
76 + bit_depth = 2;
77 + else if (num_palette <= 16)
78 + bit_depth = 4;
79 break;
80 default:
81 g_warning ("This can't be!\n");
82 @@ -1021,16 +1022,14 @@ mng_save_image (const gchar *filename,
83 goto err3;
84 }
85
86 - if ((png_info_ptr->valid & PNG_INFO_PLTE) == PNG_INFO_PLTE)
87 - {
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;
94 - }
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);
96
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);
104
105 if (mng_data.interlaced != 0)
106 @@ -1038,8 +1037,8 @@ mng_save_image (const gchar *filename,
107 else
108 num_passes = 1;
109
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);
115
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);
120
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)
123 {
124 for (j = 0; j < num; j++)
125 {
126 @@ -1077,7 +1076,7 @@ mng_save_image (const gchar *filename,
127 }
128 }
129 else
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)
132 && (layer_bpp == 2))
133 {
134 for (j = 0; j < num; j++)
135 $NetBSD: patch-af,v 1.8 2011/04/19 10:28:31 wiz Exp $
136
137 Fix build with png-1.5.
138 https://bugzilla.gnome.org/show_bug.cgi?id=640409
139
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);
144 }
145
146 +#if (PNG_LIBPNG_VER < 10500)
147 longjmp (png_ptr->jmpbuf, 1);
148 +#else
149 + png_longjmp (png_ptr, 1);
150 +#endif
151 }
152
153 /*
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);
157
158 - if (setjmp (pp->jmpbuf))
159 + if (setjmp (png_jmpbuf(pp)))
160 {
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 :)
165 */
166
167 - if (info->bit_depth == 16)
168 + if (png_get_bit_depth(pp, info) == 16)
169 {
170 png_set_strip_16 (pp);
171 }
172
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)
175 {
176 png_set_expand (pp);
177 }
178
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)
181 {
182 png_set_packing (pp);
183 }
184 @@ -757,8 +761,8 @@ load_image (const gchar *filename,
185 * Expand G+tRNS to GA, RGB+tRNS to RGBA
186 */
187
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)
192 {
193 png_set_expand (pp);
194 }
195 @@ -775,7 +779,7 @@ load_image (const gchar *filename,
196 */
197
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)
201 {
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,
205
206 png_read_update_info (pp, info);
207
208 - switch (info->color_type)
209 + switch (png_get_color_type(pp, info))
210 {
211 case PNG_COLOR_TYPE_RGB: /* RGB */
212 bpp = 3;
213 @@ -836,7 +840,7 @@ load_image (const gchar *filename,
214 return -1;
215 }
216
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);
219 if (image == -1)
220 {
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...
224 */
225
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);
230
231 @@ -883,7 +887,7 @@ load_image (const gchar *filename,
232
233 gimp_layer_set_offsets (layer, offset_x, offset_y);
234
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)))
237 {
238 if (interactive)
239 g_message (_("The PNG file specifies an offset that caused "
240 @@ -938,23 +942,27 @@ load_image (const gchar *filename,
241
242 empty = 0; /* by default assume no full transparent palette entries */
243
244 - if (info->color_type & PNG_COLOR_MASK_PALETTE)
245 + if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE)
246 {
247 + png_colorp palette;
248 + int num_palette;
249 + png_get_PLTE(pp, info, &palette, &num_palette);
250 +
251 if (png_get_valid (pp, info, PNG_INFO_tRNS))
252 {
253 for (empty = 0; empty < 256 && alpha[empty] == 0; ++empty)
254 /* Calculates number of fully transparent "empty" entries */;
255
256 /* keep at least one entry */
257 - empty = MIN (empty, info->num_palette - 1);
258 + empty = MIN (empty, num_palette - 1);
259
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);
264 }
265 else
266 {
267 - gimp_image_set_colormap (image, (guchar *) info->palette,
268 - info->num_palette);
269 + gimp_image_set_colormap (image, (guchar *) palette,
270 + num_palette);
271 }
272 }
273
274 @@ -972,18 +980,18 @@ load_image (const gchar *filename,
275 */
276
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);
281
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;
285
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;
296
297 @@ -996,10 +1004,10 @@ load_image (const gchar *filename,
298 */
299
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)
303 {
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);
308
309 num = end - begin;
310
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);
314
315 - memset (pixel, 0, tile_height * info->width * bpp);
316 + memset (pixel, 0, tile_height * png_get_image_width(pp, info) * bpp);
317
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);
322 }
323 }
324 @@ -1072,7 +1080,8 @@ load_image (const gchar *filename,
325
326 {
327 png_uint_32 proflen;
328 - png_charp profname, profile;
329 + png_charp profname;
330 + png_bytep profile;
331 int profcomp;
332
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 */
340
341 guchar remap[256]; /* Re-mapping for the palette */
342
343 @@ -1208,7 +1219,9 @@ save_image (const gchar *filename,
344 if (pngvals.comment)
345 {
346 GimpParasite *parasite;
347 +#ifndef PNG_iTXt_SUPPORTED
348 gsize text_length = 0;
349 +#endif
350
351 parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
352 if (parasite)
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);
356
357 - if (setjmp (pp->jmpbuf))
358 + if (setjmp (png_jmpbuf(pp)))
359 {
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,
363
364 png_set_compression_level (pp, pngvals.compression_level);
365
366 - info->width = drawable->width;
367 - info->height = drawable->height;
368 - info->bit_depth = 8;
369 - info->interlace_type = pngvals.interlaced;
370 -
371 /*
372 * Initialise remap[]
373 */
374 @@ -1304,44 +1312,48 @@ save_image (const gchar *filename,
375
376 /*
377 * Set color type and remember bytes per pixel count
378 + * Also fix bit depths for (possibly) smaller colormap images
379 */
380
381 + bit_depth = 8;
382 +
383 switch (type)
384 {
385 case GIMP_RGB_IMAGE:
386 - info->color_type = PNG_COLOR_TYPE_RGB;
387 + color_type = PNG_COLOR_TYPE_RGB;
388 bpp = 3;
389 break;
390
391 case GIMP_RGBA_IMAGE:
392 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
393 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
394 bpp = 4;
395 break;
396
397 case GIMP_GRAY_IMAGE:
398 - info->color_type = PNG_COLOR_TYPE_GRAY;
399 + color_type = PNG_COLOR_TYPE_GRAY;
400 bpp = 1;
401 break;
402
403 case GIMP_GRAYA_IMAGE:
404 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
405 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
406 bpp = 2;
407 break;
408
409 case GIMP_INDEXED_IMAGE:
410 + case GIMP_INDEXEDA_IMAGE:
411 bpp = 1;
412 - info->color_type = PNG_COLOR_TYPE_PALETTE;
413 - info->valid |= PNG_INFO_PLTE;
414 - info->palette =
415 - (png_colorp) gimp_image_get_colormap (image_ID, &num_colors);
416 - info->num_palette = num_colors;
417 - break;
418 + if (type == GIMP_INDEXEDA_IMAGE)
419 + bpp = 2;
420
421 - case GIMP_INDEXEDA_IMAGE:
422 - bpp = 2;
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)
429 + bit_depth = 1;
430 + else if (num_colors <= 4)
431 + bit_depth = 2;
432 + else if (num_colors <= 16)
433 + bit_depth = 4;
434 + /* otherwise the default is fine */
435 break;
436
437 default:
438 @@ -1349,19 +1361,14 @@ save_image (const gchar *filename,
439 return FALSE;
440 }
441
442 - /*
443 - * Fix bit depths for (possibly) smaller colormap images
444 - */
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);
446
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)
451 {
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);
461 }
462
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
466 */
467
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);
471
472 /*
473 @@ -1529,7 +1536,7 @@ save_image (const gchar *filename,
474
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))
479 {
480 guchar inverse_remap[256];
481
482 @@ -1549,7 +1556,7 @@ save_image (const gchar *filename,
483 }
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)
488 {
489 for (i = 0; i < num; ++i)
490 {
491 @@ -1564,7 +1571,7 @@ save_image (const gchar *filename,
492 png_write_rows (pp, pixels, num);
493
494 gimp_progress_update (((double) pass + (double) end /
495 - (double) info->height) /
496 + (double) png_get_image_height(pp, info)) /
497 (double) num_passes);
498 }
499 }

  ViewVC Help
Powered by ViewVC 1.1.28