1 --- cinepaint/plug-ins/png/png.c.orig 2006-11-24 21:52:55.000000000 +0100
2 +++ cinepaint/plug-ins/png/png.c 2023-08-30 18:58:13.093905639 +0200
3 @@ -390,7 +390,16 @@ load_image (gchar *filename) /* I - File
4 gchar *progress; /* Title for progress display... */
5 guchar alpha[256], /* Index -> Alpha */
6 *alpha_ptr; /* Temporary pointer */
12 + png_charpp iccp_name;
13 + int compression_type;
14 + png_bytepp iccp_profile;
15 + png_uint_32 iccp_proflen;
16 + png_uint_32 width, height;
19 * PNG 0.89 and newer have a sane, forwards compatible constructor.
20 * Some SGI IRIX users will not have a new enough version though
21 @@ -405,7 +414,7 @@ load_image (gchar *filename) /* I - File
22 info = (png_infop)calloc(sizeof(png_info), 1);
23 #endif /* PNG_LIBPNG_VER > 88 */
25 - if (setjmp (pp->jmpbuf))
26 + if (setjmp (png_jmpbuf(pp)))
28 g_message ("%s\nPNG error. File corrupted?", filename);
30 @@ -442,21 +451,23 @@ load_image (gchar *filename) /* I - File
33 png_read_info(pp, info);
35 + color_type = png_get_color_type(pp, info);
36 + width=png_get_image_width(pp, info);
37 + height=png_get_image_height(pp, info);
39 * Latest attempt, this should be my best yet :)
42 + bit_depth = png_get_bit_depth(pp, info);
43 #ifndef WORDS_BIGENDIAN
44 - if(info->bit_depth == 16)
50 - if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8) {
51 + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
55 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) {
56 + if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8) {
60 @@ -464,8 +475,8 @@ load_image (gchar *filename) /* I - File
61 * Expand G+tRNS to GA, RGB+tRNS to RGBA
64 - if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
65 - (info->valid & PNG_INFO_tRNS)) {
66 + if (color_type != PNG_COLOR_TYPE_PALETTE &&
67 + (png_get_valid(pp, info, PNG_INFO_tRNS))) {
71 @@ -482,7 +493,7 @@ load_image (gchar *filename) /* I - File
73 #if PNG_LIBPNG_VER > 99
74 if (png_get_valid(pp, info, PNG_INFO_tRNS) &&
75 - info->color_type == PNG_COLOR_TYPE_PALETTE)
76 + color_type == PNG_COLOR_TYPE_PALETTE)
78 png_get_tRNS(pp, info, &alpha_ptr, &num, NULL);
79 /* Copy the existing alpha values from the tRNS chunk */
80 @@ -505,12 +516,12 @@ load_image (gchar *filename) /* I - File
82 png_read_update_info(pp, info);
84 - if(info->bit_depth==16)
87 - switch (info->color_type)
90 case PNG_COLOR_TYPE_RGB : /* RGB */
94 layer_type = U16_RGB_IMAGE;
96 @@ -545,10 +556,10 @@ load_image (gchar *filename) /* I - File
100 - switch (info->color_type)
101 + switch (color_type)
103 case PNG_COLOR_TYPE_RGB : /* RGB */
107 layer_type = RGB_IMAGE;
109 @@ -582,7 +593,7 @@ load_image (gchar *filename) /* I - File
113 - image = gimp_image_new(info->width, info->height, image_type);
114 + image = gimp_image_new(width, height, image_type);
117 g_message("Can't allocate new image\n%s", filename);
118 @@ -595,7 +606,7 @@ load_image (gchar *filename) /* I - File
119 * Create the "background" layer to hold the image...
122 - layer = gimp_layer_new(image, _("Background"), info->width, info->height,
123 + layer = gimp_layer_new(image, _("Background"), width, height,
124 layer_type, 100, NORMAL_MODE);
125 gimp_image_add_layer(image, layer, 0);
127 @@ -627,20 +638,21 @@ load_image (gchar *filename) /* I - File
129 empty= 0; /* by default assume no full transparent palette entries */
131 - if (info->color_type & PNG_COLOR_MASK_PALETTE) {
132 + if (color_type & PNG_COLOR_MASK_PALETTE) {
134 #if PNG_LIBPNG_VER > 99
135 + png_get_PLTE(pp, info, &palette, &num_palette);
136 if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
137 for (empty= 0; empty < 256 && alpha[empty] == 0; ++empty);
138 /* Calculates number of fully transparent "empty" entries */
140 - gimp_image_set_cmap(image, (guchar *) (info->palette + empty),
141 - info->num_palette - empty);
142 + gimp_image_set_cmap(image, (guchar *) (palette + empty),
143 + num_palette - empty);
145 - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
146 + gimp_image_set_cmap(image, (guchar *)palette, num_palette);
149 - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
150 + gimp_image_set_cmap(image, (guchar *)palette, num_palette);
151 #endif /* PNG_LIBPNG_VER > 99 */
154 @@ -659,18 +671,19 @@ load_image (gchar *filename) /* I - File
157 tile_height = gimp_tile_height ();
158 - pixel = g_new(guchar, tile_height * info->width * bpp);
159 + pixel = g_new(guchar, tile_height * width * bpp);
160 pixels = g_new(guchar *, tile_height);
161 + channels=png_get_channels(pp, info);
163 - if(info->bit_depth==16)
166 for (i = 0; i < tile_height; i ++)
167 - pixels[i] = pixel + info->width * info->channels * i * 2;
168 + pixels[i] = pixel + width * channels * i * 2;
172 for (i = 0; i < tile_height; i ++)
173 - pixels[i] = pixel + info->width * info->channels * i;
174 + pixels[i] = pixel + width * channels * i;
177 for (pass = 0; pass < num_passes; pass ++)
178 @@ -680,11 +693,11 @@ load_image (gchar *filename) /* I - File
181 for (begin = 0, end = tile_height;
182 - begin < info->height;
184 begin += tile_height, end += tile_height)
186 - if (end > info->height)
187 - end = info->height;
193 @@ -697,20 +710,21 @@ load_image (gchar *filename) /* I - File
194 gimp_pixel_rgn_set_rect(&pixel_rgn, pixel, 0, begin,
195 drawable->width, num);
197 - gimp_progress_update(((double)pass + (double)end / (double)info->height) /
198 + gimp_progress_update(((double)pass + (double)end / (double)height) /
203 #if defined(PNG_iCCP_SUPPORTED)
204 /* set icc profile */
205 - if (info->iccp_proflen > 0) {
206 - gimp_image_set_icc_profile_by_mem (image, info->iccp_proflen,
207 - info->iccp_profile,
208 - ICC_IMAGE_PROFILE);
209 + png_get_iCCP(pp, info, (png_charpp)iccp_name, &compression_type, iccp_profile, &iccp_proflen);
210 + if (iccp_proflen > 0) {
211 + gimp_image_set_icc_profile_by_mem (image, iccp_proflen,
212 + (gchar *)iccp_profile,
213 + ICC_IMAGE_PROFILE);
214 printf ("%s:%d %s() set embedded profile \"%s\"\n",
215 __FILE__,__LINE__,__func__,
217 + (char *)iccp_name);
221 @@ -809,6 +823,15 @@ save_image (gchar *filename, /*
222 time_t cutime; /* Time since epoch */
223 struct tm *gmt; /* GMT broken down */
225 + png_byte color_type;
226 + png_byte bit_depth;
227 + int filter_method=0;
228 + png_colorp palette;
230 + png_charpp iccp_name;
231 + png_uint_32 height;
232 + int compression_type;
235 * PNG 0.89 and newer have a sane, forwards compatible constructor.
236 * Some SGI IRIX users will not have a new enough version though
237 @@ -824,7 +847,7 @@ save_image (gchar *filename, /*
238 info = (png_infop)calloc(sizeof(png_info), 1);
239 #endif /* PNG_LIBPNG_VER > 88 */
241 - if (setjmp (pp->jmpbuf))
242 + if (setjmp (png_jmpbuf(pp)))
244 g_message ("%s\nPNG error. Couldn't save image", filename);
246 @@ -858,87 +881,75 @@ save_image (gchar *filename, /*
247 type = gimp_drawable_type (drawable_ID);
250 - * Set the image dimensions, bit depth, interlacing and compression
253 - png_set_compression_level (pp, pngvals.compression_level);
255 - info->width = drawable->width;
256 - info->height = drawable->height;
257 - info->interlace_type = pngvals.interlaced;
260 * Set color type and remember bytes per pixel count
266 - info->color_type = PNG_COLOR_TYPE_RGB;
267 - info->bit_depth = 8;
268 + color_type = PNG_COLOR_TYPE_RGB;
273 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
274 - info->bit_depth = 8;
275 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
280 - info->color_type = PNG_COLOR_TYPE_GRAY;
281 - info->bit_depth = 8;
282 + color_type = PNG_COLOR_TYPE_GRAY;
287 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
288 - info->bit_depth = 8;
289 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
295 - info->bit_depth = 8;
296 - info->color_type = PNG_COLOR_TYPE_PALETTE;
297 - info->valid |= PNG_INFO_PLTE;
298 - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
299 - info->num_palette= num_colors;
301 + color_type = PNG_COLOR_TYPE_PALETTE;
302 + png_get_valid(pp, info, PNG_INFO_PLTE);
303 + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors);
305 case INDEXEDA_IMAGE :
307 - info->bit_depth = 8;
308 - info->color_type = PNG_COLOR_TYPE_PALETTE;
310 + color_type = PNG_COLOR_TYPE_PALETTE;
311 respin_cmap (pp, info, image_ID); /* fix up transparency */
314 - info->color_type = PNG_COLOR_TYPE_RGB;
315 - info->bit_depth = 16;
316 + color_type = PNG_COLOR_TYPE_RGB;
320 case U16_RGBA_IMAGE :
321 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
322 - info->bit_depth = 16;
323 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
327 case U16_GRAY_IMAGE :
328 - info->color_type = PNG_COLOR_TYPE_GRAY;
329 - info->bit_depth = 16;
330 + color_type = PNG_COLOR_TYPE_GRAY;
334 case U16_GRAYA_IMAGE :
335 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
336 - info->bit_depth = 16;
337 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
341 case U16_INDEXED_IMAGE :
343 - info->bit_depth = 16;
344 - info->color_type = PNG_COLOR_TYPE_PALETTE;
345 - info->valid |= PNG_INFO_PLTE;
346 - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
347 - info->num_palette= num_colors;
349 + color_type = PNG_COLOR_TYPE_PALETTE;
350 + png_get_valid(pp, info, PNG_INFO_PLTE);
351 + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors);
353 case U16_INDEXEDA_IMAGE :
355 - info->bit_depth = 16;
356 - info->color_type = PNG_COLOR_TYPE_PALETTE;
358 + color_type = PNG_COLOR_TYPE_PALETTE;
359 respin_cmap (pp, info, image_ID); /* fix up transparency */
362 @@ -950,16 +961,21 @@ save_image (gchar *filename, /*
363 * Fix bit depths for (possibly) smaller colormap images
366 - if (info->valid & PNG_INFO_PLTE) {
367 - if (info->num_palette <= 2)
368 - info->bit_depth= 1;
369 - else if (info->num_palette <= 4)
370 - info->bit_depth= 2;
371 - else if (info->num_palette <= 16)
372 - info->bit_depth= 4;
373 + if (png_get_valid(pp, info, PNG_INFO_PLTE)) {
374 + png_get_PLTE(pp, info, &palette, &num_palette);
375 + if (num_palette <= 2)
377 + else if (num_palette <= 4)
379 + else if (num_palette <= 16)
381 /* otherwise the default is fine */
384 + png_set_compression_level (pp, pngvals.compression_level);
385 + png_set_IHDR(pp, info, drawable->width, drawable->height,
386 + bit_depth, color_type, pngvals.interlaced, compression_type, filter_method);
389 #if defined(PNG_iCCP_SUPPORTED)
390 if (gimp_image_has_icc_profile (image_ID, ICC_IMAGE_PROFILE)) {
391 @@ -970,10 +986,10 @@ save_image (gchar *filename, /*
393 png_set_iCCP (pp, info,
394 gimp_image_get_icc_profile_description (image_ID, ICC_IMAGE_PROFILE),
396 + 0, (png_const_bytep)buffer, size);
397 printf ("%s:%d %s() embedd icc profile \"%s\"\n",
398 __FILE__,__LINE__,__func__,
400 + (char *)iccp_name);
404 @@ -1039,13 +1055,13 @@ save_image (gchar *filename, /*
405 * Convert unpacked pixels to packed if necessary
408 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
409 + if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8)
412 /* Set swapping for 16 bit per sample images */
414 #ifndef WORDS_BIGENDIAN
415 - if (info->bit_depth == 16)
416 + if (bit_depth == 16)
420 @@ -1063,6 +1079,7 @@ save_image (gchar *filename, /*
422 gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, drawable->width,
423 drawable->height, FALSE, FALSE);
424 + height=png_get_image_height(pp, info);
426 for (pass = 0; pass < num_passes; pass ++)
428 @@ -1077,7 +1094,7 @@ save_image (gchar *filename, /*
431 gimp_pixel_rgn_get_rect (&pixel_rgn, pixel, 0, begin, drawable->width, num);
432 - if (info->valid & PNG_INFO_tRNS) {
433 + if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
434 for (i = 0; i < num; ++i) {
436 for (k = 0; k < drawable->width; ++k) {
437 @@ -1085,7 +1102,7 @@ save_image (gchar *filename, /*
440 /* Forgot this case before, what if there are too many colors? */
441 - } else if (info->valid & PNG_INFO_PLTE && bpp == 2) {
442 + } else if (png_get_valid(pp, info, PNG_INFO_PLTE) && bpp == 2) {
443 for (i = 0; i < num; ++i) {
445 for (k = 0; k < drawable->width; ++k) {
446 @@ -1097,7 +1114,7 @@ save_image (gchar *filename, /*
447 png_write_rows (pp, pixels, num);
449 gimp_progress_update (((double)pass + (double)end /
450 - (double)info->height) / (double)num_passes);
451 + (double)height) / (double)num_passes);