1 diff -Naur cinepaint1/plug-ins/png/png.c cinepaint/plug-ins/png/png.c
2 --- cinepaint1/plug-ins/png/png.c 2006-11-24 21:52:55.000000000 +0100
3 +++ cinepaint/plug-ins/png/png.c 2012-02-04 01:51:10.141016081 +0100
5 gchar *progress; /* Title for progress display... */
6 guchar alpha[256], /* Index -> Alpha */
7 *alpha_ptr; /* Temporary pointer */
13 + png_charpp iccp_name;
14 + int compression_type;
15 + png_bytepp iccp_profile;
16 + png_uint_32 iccp_proflen;
17 + png_uint_32 width, height;
20 * PNG 0.89 and newer have a sane, forwards compatible constructor.
21 * Some SGI IRIX users will not have a new enough version though
23 info = (png_infop)calloc(sizeof(png_info), 1);
24 #endif /* PNG_LIBPNG_VER > 88 */
26 - if (setjmp (pp->jmpbuf))
27 + if (setjmp (png_jmpbuf(pp)))
29 g_message ("%s\nPNG error. File corrupted?", filename);
34 png_read_info(pp, info);
36 + color_type = png_get_color_type(pp, info);
37 + width=png_get_image_width(pp, info);
38 + height=png_get_image_height(pp, info);
40 * Latest attempt, this should be my best yet :)
43 + bit_depth = png_get_bit_depth(pp, info);
44 #ifndef WORDS_BIGENDIAN
45 - if(info->bit_depth == 16)
51 - if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8) {
52 + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
56 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) {
57 + if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8) {
62 * Expand G+tRNS to GA, RGB+tRNS to RGBA
65 - if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
66 - (info->valid & PNG_INFO_tRNS)) {
67 + if (color_type != PNG_COLOR_TYPE_PALETTE &&
68 + (png_get_valid(pp, info, PNG_INFO_tRNS))) {
74 #if PNG_LIBPNG_VER > 99
75 if (png_get_valid(pp, info, PNG_INFO_tRNS) &&
76 - info->color_type == PNG_COLOR_TYPE_PALETTE)
77 + color_type == PNG_COLOR_TYPE_PALETTE)
79 png_get_tRNS(pp, info, &alpha_ptr, &num, NULL);
80 /* Copy the existing alpha values from the tRNS chunk */
83 png_read_update_info(pp, info);
85 - if(info->bit_depth==16)
88 - switch (info->color_type)
91 case PNG_COLOR_TYPE_RGB : /* RGB */
95 layer_type = U16_RGB_IMAGE;
101 - switch (info->color_type)
102 + switch (color_type)
104 case PNG_COLOR_TYPE_RGB : /* RGB */
108 layer_type = RGB_IMAGE;
114 - image = gimp_image_new(info->width, info->height, image_type);
115 + image = gimp_image_new(width, height, image_type);
118 g_message("Can't allocate new image\n%s", filename);
120 * Create the "background" layer to hold the image...
123 - layer = gimp_layer_new(image, _("Background"), info->width, info->height,
124 + layer = gimp_layer_new(image, _("Background"), width, height,
125 layer_type, 100, NORMAL_MODE);
126 gimp_image_add_layer(image, layer, 0);
128 @@ -627,20 +638,21 @@
130 empty= 0; /* by default assume no full transparent palette entries */
132 - if (info->color_type & PNG_COLOR_MASK_PALETTE) {
133 + if (color_type & PNG_COLOR_MASK_PALETTE) {
135 #if PNG_LIBPNG_VER > 99
136 + png_get_PLTE(pp, info, &palette, &num_palette);
137 if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
138 for (empty= 0; empty < 256 && alpha[empty] == 0; ++empty);
139 /* Calculates number of fully transparent "empty" entries */
141 - gimp_image_set_cmap(image, (guchar *) (info->palette + empty),
142 - info->num_palette - empty);
143 + gimp_image_set_cmap(image, (guchar *) (palette + empty),
144 + num_palette - empty);
146 - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
147 + gimp_image_set_cmap(image, (guchar *)palette, num_palette);
150 - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
151 + gimp_image_set_cmap(image, (guchar *)palette, num_palette);
152 #endif /* PNG_LIBPNG_VER > 99 */
155 @@ -659,18 +671,19 @@
158 tile_height = gimp_tile_height ();
159 - pixel = g_new(guchar, tile_height * info->width * bpp);
160 + pixel = g_new(guchar, tile_height * width * bpp);
161 pixels = g_new(guchar *, tile_height);
162 + channels=png_get_channels(pp, info);
164 - if(info->bit_depth==16)
167 for (i = 0; i < tile_height; i ++)
168 - pixels[i] = pixel + info->width * info->channels * i * 2;
169 + pixels[i] = pixel + width * channels * i * 2;
173 for (i = 0; i < tile_height; i ++)
174 - pixels[i] = pixel + info->width * info->channels * i;
175 + pixels[i] = pixel + width * channels * i;
178 for (pass = 0; pass < num_passes; pass ++)
179 @@ -680,11 +693,11 @@
182 for (begin = 0, end = tile_height;
183 - begin < info->height;
185 begin += tile_height, end += tile_height)
187 - if (end > info->height)
188 - end = info->height;
194 @@ -697,20 +710,21 @@
195 gimp_pixel_rgn_set_rect(&pixel_rgn, pixel, 0, begin,
196 drawable->width, num);
198 - gimp_progress_update(((double)pass + (double)end / (double)info->height) /
199 + gimp_progress_update(((double)pass + (double)end / (double)height) /
204 #if defined(PNG_iCCP_SUPPORTED)
205 /* set icc profile */
206 - if (info->iccp_proflen > 0) {
207 - gimp_image_set_icc_profile_by_mem (image, info->iccp_proflen,
208 - info->iccp_profile,
209 - ICC_IMAGE_PROFILE);
210 + png_get_iCCP(pp, info, (png_charpp)iccp_name, &compression_type, iccp_profile, &iccp_proflen);
211 + if (iccp_proflen > 0) {
212 + gimp_image_set_icc_profile_by_mem (image, iccp_proflen,
213 + (gchar *)iccp_profile,
214 + ICC_IMAGE_PROFILE);
215 printf ("%s:%d %s() set embedded profile \"%s\"\n",
216 __FILE__,__LINE__,__func__,
218 + (char *)iccp_name);
223 time_t cutime; /* Time since epoch */
224 struct tm *gmt; /* GMT broken down */
226 + png_byte color_type;
227 + png_byte bit_depth;
228 + int filter_method=0;
229 + png_colorp palette;
231 + png_charpp iccp_name;
232 + png_uint_32 height;
233 + int compression_type;
236 * PNG 0.89 and newer have a sane, forwards compatible constructor.
237 * Some SGI IRIX users will not have a new enough version though
239 info = (png_infop)calloc(sizeof(png_info), 1);
240 #endif /* PNG_LIBPNG_VER > 88 */
242 - if (setjmp (pp->jmpbuf))
243 + if (setjmp (png_jmpbuf(pp)))
245 g_message ("%s\nPNG error. Couldn't save image", filename);
247 @@ -858,87 +881,75 @@
248 type = gimp_drawable_type (drawable_ID);
251 - * Set the image dimensions, bit depth, interlacing and compression
254 - png_set_compression_level (pp, pngvals.compression_level);
256 - info->width = drawable->width;
257 - info->height = drawable->height;
258 - info->interlace_type = pngvals.interlaced;
261 * Set color type and remember bytes per pixel count
267 - info->color_type = PNG_COLOR_TYPE_RGB;
268 - info->bit_depth = 8;
269 + color_type = PNG_COLOR_TYPE_RGB;
274 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
275 - info->bit_depth = 8;
276 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
281 - info->color_type = PNG_COLOR_TYPE_GRAY;
282 - info->bit_depth = 8;
283 + color_type = PNG_COLOR_TYPE_GRAY;
288 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
289 - info->bit_depth = 8;
290 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
296 - info->bit_depth = 8;
297 - info->color_type = PNG_COLOR_TYPE_PALETTE;
298 - info->valid |= PNG_INFO_PLTE;
299 - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
300 - info->num_palette= num_colors;
302 + color_type = PNG_COLOR_TYPE_PALETTE;
303 + png_get_valid(pp, info, PNG_INFO_PLTE);
304 + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors);
306 case INDEXEDA_IMAGE :
308 - info->bit_depth = 8;
309 - info->color_type = PNG_COLOR_TYPE_PALETTE;
311 + color_type = PNG_COLOR_TYPE_PALETTE;
312 respin_cmap (pp, info, image_ID); /* fix up transparency */
315 - info->color_type = PNG_COLOR_TYPE_RGB;
316 - info->bit_depth = 16;
317 + color_type = PNG_COLOR_TYPE_RGB;
321 case U16_RGBA_IMAGE :
322 - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
323 - info->bit_depth = 16;
324 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
328 case U16_GRAY_IMAGE :
329 - info->color_type = PNG_COLOR_TYPE_GRAY;
330 - info->bit_depth = 16;
331 + color_type = PNG_COLOR_TYPE_GRAY;
335 case U16_GRAYA_IMAGE :
336 - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
337 - info->bit_depth = 16;
338 + color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
342 case U16_INDEXED_IMAGE :
344 - info->bit_depth = 16;
345 - info->color_type = PNG_COLOR_TYPE_PALETTE;
346 - info->valid |= PNG_INFO_PLTE;
347 - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
348 - info->num_palette= num_colors;
350 + color_type = PNG_COLOR_TYPE_PALETTE;
351 + png_get_valid(pp, info, PNG_INFO_PLTE);
352 + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors);
354 case U16_INDEXEDA_IMAGE :
356 - info->bit_depth = 16;
357 - info->color_type = PNG_COLOR_TYPE_PALETTE;
359 + color_type = PNG_COLOR_TYPE_PALETTE;
360 respin_cmap (pp, info, image_ID); /* fix up transparency */
363 @@ -950,16 +961,21 @@
364 * Fix bit depths for (possibly) smaller colormap images
367 - if (info->valid & PNG_INFO_PLTE) {
368 - if (info->num_palette <= 2)
369 - info->bit_depth= 1;
370 - else if (info->num_palette <= 4)
371 - info->bit_depth= 2;
372 - else if (info->num_palette <= 16)
373 - info->bit_depth= 4;
374 + if (png_get_valid(pp, info, PNG_INFO_PLTE)) {
375 + png_get_PLTE(pp, info, &palette, &num_palette);
376 + if (num_palette <= 2)
378 + else if (num_palette <= 4)
380 + else if (num_palette <= 16)
382 /* otherwise the default is fine */
385 + png_set_compression_level (pp, pngvals.compression_level);
386 + png_set_IHDR(pp, info, drawable->width, drawable->height,
387 + bit_depth, color_type, pngvals.interlaced, compression_type, filter_method);
390 #if defined(PNG_iCCP_SUPPORTED)
391 if (gimp_image_has_icc_profile (image_ID, ICC_IMAGE_PROFILE)) {
392 @@ -970,10 +986,10 @@
394 png_set_iCCP (pp, info,
395 gimp_image_get_icc_profile_description (image_ID, ICC_IMAGE_PROFILE),
397 + 0, (png_const_bytep)buffer, size);
398 printf ("%s:%d %s() embedd icc profile \"%s\"\n",
399 __FILE__,__LINE__,__func__,
401 + (char *)iccp_name);
405 @@ -1039,13 +1055,13 @@
406 * Convert unpacked pixels to packed if necessary
409 - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
410 + if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8)
413 /* Set swapping for 16 bit per sample images */
415 #ifndef WORDS_BIGENDIAN
416 - if (info->bit_depth == 16)
417 + if (bit_depth == 16)
421 @@ -1063,6 +1079,7 @@
423 gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, drawable->width,
424 drawable->height, FALSE, FALSE);
425 + height=png_get_image_height(pp, info);
427 for (pass = 0; pass < num_passes; pass ++)
429 @@ -1077,7 +1094,7 @@
432 gimp_pixel_rgn_get_rect (&pixel_rgn, pixel, 0, begin, drawable->width, num);
433 - if (info->valid & PNG_INFO_tRNS) {
434 + if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
435 for (i = 0; i < num; ++i) {
437 for (k = 0; k < drawable->width; ++k) {
438 @@ -1085,7 +1102,7 @@
441 /* Forgot this case before, what if there are too many colors? */
442 - } else if (info->valid & PNG_INFO_PLTE && bpp == 2) {
443 + } else if (png_get_valid(pp, info, PNG_INFO_PLTE) && bpp == 2) {
444 for (i = 0; i < num; ++i) {
446 for (k = 0; k < drawable->width; ++k) {
447 @@ -1097,7 +1114,7 @@
448 png_write_rows (pp, pixels, num);
450 gimp_progress_update (((double)pass + (double)end /
451 - (double)info->height) / (double)num_passes);
452 + (double)height) / (double)num_passes);