Created attachment 628047 [details] diff of working and non working png.c Description of problem: Cinepaint does not support working with PNG images Version-Release number of selected component (if applicable): Cinepaint 1.3.0 How reproducible: Try opening or saving a PNG file with cinepaint Steps to Reproduce: 1. start cinepaint 2. open file, select a png image 3. Actual results: File type not supported Expected results: Open file for editing Additional info: I know it's disabled because of libpng 1.5 incompatibilities. http://sourceforge.net/tracker/index.php?func=detail&aid=3255946&group_id=75029&atid=542708 Has a patch but it's in a manky format so it might need manual application. It would be very nice if this could be applied, either for FC17 or for FC18, since PNG is quite a common file format these days. I'll add the patch as an attachment as well. Credits should go to Ryo ONODERA for creating it.
Can you provide a unified diff version of the patch that can be applied. The file you've linked is as there are lot of broken end of lines. You can checkout the cinepaint tree , fix the png.c file and provide the output of cvs diff -u Thx for your report.
Unfortunately, it's not my code, I just found this on the web. I just sent a message to the person that submitted it, they may be able to provide it. Otherwise, it may boil down to rewriting it manually.
Roman P. is the author of this patch. He was kind enough to supply this after me requesting him to do so (see previous comments in this bug). Please check this for flaws and insecure coding, since I am not capable of doing it myself. --- png_orig.c 2006-11-24 21:52:55.000000000 +0100 +++ png.c 2012-06-23 00:50:40.000000000 +0200 @@ -405,7 +405,7 @@ info = (png_infop)calloc(sizeof(png_info), 1); #endif /* PNG_LIBPNG_VER > 88 */ - if (setjmp (pp->jmpbuf)) + if (setjmp (png_jmpbuf(pp))) { g_message (\"%s\\nPNG error. File corrupted?\", filename); return image; @@ -448,15 +448,15 @@ */ #ifndef WORDS_BIGENDIAN - if(info->bit_depth == 16) + if(png_get_bit_depth(pp,info) == 16) png_set_swap(pp); #endif - if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8) { + if (png_get_color_type(pp,info) == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(pp,info) < 8) { png_set_expand(pp); } - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) { + if (png_get_color_type(pp,info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp,info) < 8) { png_set_packing(pp); } @@ -464,8 +464,8 @@ * Expand G+tRNS to GA, RGB+tRNS to RGBA */ - if (info->color_type != PNG_COLOR_TYPE_PALETTE && - (info->valid & PNG_INFO_tRNS)) { + if (png_get_color_type(pp,info) != PNG_COLOR_TYPE_PALETTE && + (png_get_valid(pp,info,PNG_INFO_tRNS))) { png_set_expand(pp); } @@ -482,7 +482,7 @@ #if PNG_LIBPNG_VER > 99 if (png_get_valid(pp, info, PNG_INFO_tRNS) && - info->color_type == PNG_COLOR_TYPE_PALETTE) + png_get_color_type(pp,info) == PNG_COLOR_TYPE_PALETTE) { png_get_tRNS(pp, info, &alpha_ptr, &num, NULL); /* Copy the existing alpha values from the tRNS chunk */ @@ -505,9 +505,9 @@ png_read_update_info(pp, info); - if(info->bit_depth==16) + if(png_get_bit_depth(pp,info)==16) { - switch (info->color_type) + switch (png_get_color_type(pp,info)) { case PNG_COLOR_TYPE_RGB : /* RGB */ bpp = 6; @@ -545,7 +545,7 @@ } else { - switch (info->color_type) + switch (png_get_color_type(pp,info)) { case PNG_COLOR_TYPE_RGB : /* RGB */ bpp = 3; @@ -582,7 +582,7 @@ }; } - image = gimp_image_new(info->width, info->height, image_type); + image = gimp_image_new(png_get_image_width(pp,info), png_get_image_height(pp, info), image_type); if (image == -1) { g_message(\"Can\'t allocate new image\\n%s\", filename); @@ -595,7 +595,7 @@ * Create the \"background\" layer to hold the image... */ - layer = gimp_layer_new(image, _(\"Background\"), info->width, info->height, + layer = gimp_layer_new(image, _(\"Background\"), png_get_image_width(pp,info), png_get_image_height(pp, info), layer_type, 100, NORMAL_MODE); gimp_image_add_layer(image, layer, 0); @@ -627,18 +627,24 @@ empty= 0; /* by default assume no full transparent palette entries */ - if (info->color_type & PNG_COLOR_MASK_PALETTE) { + if (png_get_color_type(pp,info) & PNG_COLOR_MASK_PALETTE) { #if PNG_LIBPNG_VER > 99 +{ + png_colorp *palette; + int *num_palette; + png_get_PLTE(pp, info, palette, num_palette); if (png_get_valid(pp, info, PNG_INFO_tRNS)) { for (empty= 0; empty < 256 && alpha[empty] == 0; ++empty); /* Calculates number of fully transparent \"empty\" entries */ - gimp_image_set_cmap(image, (guchar *) (info->palette + empty), - info->num_palette - empty); + + gimp_image_set_cmap(image, (guchar *) (palette + empty), + num_palette - empty); } else { - gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette); + gimp_image_set_cmap(image, (guchar *)palette, num_palette); } +} #else gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette); #endif /* PNG_LIBPNG_VER > 99 */ @@ -659,18 +665,18 @@ */ tile_height = gimp_tile_height (); - pixel = g_new(guchar, tile_height * info->width * bpp); + pixel = g_new(guchar, tile_height * png_get_image_width(pp, info) * bpp); pixels = g_new(guchar *, tile_height); - if(info->bit_depth==16) + if(png_get_bit_depth(pp,info)==16) { for (i = 0; i < tile_height; i ++) - pixels[i] = pixel + info->width * info->channels * i * 2; + pixels[i] = pixel + png_get_image_width(pp, info) * png_get_channels(pp, info) * i * 2; } else { for (i = 0; i < tile_height; i ++) - pixels[i] = pixel + info->width * info->channels * i; + pixels[i] = pixel + png_get_image_width(pp, info) * png_get_channels(pp, info) * i; } for (pass = 0; pass < num_passes; pass ++) @@ -680,11 +686,11 @@ */ for (begin = 0, end = tile_height; - begin < info->height; + begin < png_get_image_height(pp, info); begin += tile_height, end += tile_height) { - if (end > info->height) - end = info->height; + if (end > png_get_image_height(pp, info)) + end = png_get_image_height(pp, info); num = end - begin; @@ -697,21 +703,28 @@ gimp_pixel_rgn_set_rect(&pixel_rgn, pixel, 0, begin, drawable->width, num); - gimp_progress_update(((double)pass + (double)end / (double)info->height) / + gimp_progress_update(((double)pass + (double)end / (double)png_get_image_height(pp, info)) / (double)num_passes); }; }; #if defined(PNG_iCCP_SUPPORTED) +{ /* set icc profile */ - if (info->iccp_proflen > 0) { - gimp_image_set_icc_profile_by_mem (image, info->iccp_proflen, - info->iccp_profile, + png_charpp iccp_name; + int *compression_type; + png_bytepp profile; + png_uint_32 *proflen; + + png_get_iCCP(pp, info, iccp_name, compression_type, profile, proflen); + if (proflen > 0) { + gimp_image_set_icc_profile_by_mem (image, *proflen, + profile, ICC_IMAGE_PROFILE); - printf (\"%s:%d %s() set embedded profile \\\"%s\\\"\\n\", - __FILE__,__LINE__,__func__, - info->iccp_name); + printf (\"%s:%d %s() set embedded profile \\\"%s\\\"\\n\", + __FILE__,__LINE__,__func__, (char *)iccp_name); } +} #endif /* @@ -809,6 +822,15 @@ time_t cutime; /* Time since epoch */ struct tm *gmt; /* GMT broken down */ + + png_uint_32 s_width; + png_uint_32 s_height; + int s_bit_depth; + int s_color_type; + int s_interlace_method; + + + /* * PNG 0.89 and newer have a sane, forwards compatible constructor. * Some SGI IRIX users will not have a new enough version though @@ -824,7 +846,7 @@ info = (png_infop)calloc(sizeof(png_info), 1); #endif /* PNG_LIBPNG_VER > 88 */ - if (setjmp (pp->jmpbuf)) + if (setjmp (png_jmpbuf(pp))) { g_message (\"%s\\nPNG error. Couldn\'t save image\", filename); return 0; @@ -863,9 +885,9 @@ png_set_compression_level (pp, pngvals.compression_level); - info->width = drawable->width; - info->height = drawable->height; - info->interlace_type = pngvals.interlaced; + s_width = drawable->width; + s_height = drawable->height; + s_interlace_method = pngvals.interlaced; /* * Set color type and remember bytes per pixel count @@ -874,71 +896,69 @@ switch (type) { case RGB_IMAGE : - info->color_type = PNG_COLOR_TYPE_RGB; - info->bit_depth = 8; + s_color_type = PNG_COLOR_TYPE_RGB; + s_bit_depth = 8; bpp = 3; break; case RGBA_IMAGE : - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; - info->bit_depth = 8; + s_color_type = PNG_COLOR_TYPE_RGB_ALPHA; + s_bit_depth = 8; bpp = 4; break; case GRAY_IMAGE : - info->color_type = PNG_COLOR_TYPE_GRAY; - info->bit_depth = 8; + s_color_type = PNG_COLOR_TYPE_GRAY; + s_bit_depth = 8; bpp = 1; break; case GRAYA_IMAGE : - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; - info->bit_depth = 8; + s_color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + s_bit_depth = 8; bpp = 2; break; case INDEXED_IMAGE : bpp = 1; - info->bit_depth = 8; - info->color_type = PNG_COLOR_TYPE_PALETTE; - info->valid |= PNG_INFO_PLTE; - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors); - info->num_palette= num_colors; + s_bit_depth = 8; + s_color_type = PNG_COLOR_TYPE_PALETTE; + png_set_invalid(pp,info,PNG_INFO_PLTE); + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors); break; case INDEXEDA_IMAGE : bpp = 2; - info->bit_depth = 8; - info->color_type = PNG_COLOR_TYPE_PALETTE; + s_bit_depth = 8; + s_color_type = PNG_COLOR_TYPE_PALETTE; respin_cmap (pp, info, image_ID); /* fix up transparency */ break; case U16_RGB_IMAGE : - info->color_type = PNG_COLOR_TYPE_RGB; - info->bit_depth = 16; + s_color_type = PNG_COLOR_TYPE_RGB; + s_bit_depth = 16; bpp = 6; break; case U16_RGBA_IMAGE : - info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; - info->bit_depth = 16; + s_color_type = PNG_COLOR_TYPE_RGB_ALPHA; + s_bit_depth = 16; bpp = 8; break; case U16_GRAY_IMAGE : - info->color_type = PNG_COLOR_TYPE_GRAY; - info->bit_depth = 16; + s_color_type = PNG_COLOR_TYPE_GRAY; + s_bit_depth = 16; bpp = 2; break; case U16_GRAYA_IMAGE : - info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; - info->bit_depth = 16; + s_color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + s_bit_depth = 16; bpp = 4; break; case U16_INDEXED_IMAGE : bpp = 2; - info->bit_depth = 16; - info->color_type = PNG_COLOR_TYPE_PALETTE; - info->valid |= PNG_INFO_PLTE; - info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors); - info->num_palette= num_colors; + s_bit_depth = 16; + s_color_type = PNG_COLOR_TYPE_PALETTE; + png_set_invalid(pp,info,PNG_INFO_PLTE); + png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors); break; case U16_INDEXEDA_IMAGE : bpp = 4; - info->bit_depth = 16; - info->color_type = PNG_COLOR_TYPE_PALETTE; + s_bit_depth = 16; + s_color_type = PNG_COLOR_TYPE_PALETTE; respin_cmap (pp, info, image_ID); /* fix up transparency */ break; default: @@ -946,34 +966,51 @@ return 0; }; + png_set_IHDR( pp, info, s_width, s_height, s_bit_depth, s_color_type, + s_interlace_method, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT ); + /* * Fix bit depths for (possibly) smaller colormap images */ - - if (info->valid & PNG_INFO_PLTE) { + /* + if (png_get_valid(pp,info,PNG_INFO_PLTE)) { if (info->num_palette <= 2) - info->bit_depth= 1; + png_get_bit_depth(pp,info)= 1; else if (info->num_palette <= 4) - info->bit_depth= 2; + png_get_bit_depth(pp,info)= 2; else if (info->num_palette <= 16) - info->bit_depth= 4; - /* otherwise the default is fine */ + png_get_bit_depth(pp,info)= 4; + // otherwise the default is fine } - +*/ // write icc profile #if defined(PNG_iCCP_SUPPORTED) if (gimp_image_has_icc_profile (image_ID, ICC_IMAGE_PROFILE)) { int size; char *buffer; + png_charpp iccp_name; + int *compression_type; + png_bytepp profile; + png_uint_32 *proflen; buffer = gimp_image_get_icc_profile_by_mem (image_ID, &size, ICC_IMAGE_PROFILE); + +/* + * PNG_EXPORT(159, void, png_set_iCCP, + * (png_structp png_ptr, png_infop info_ptr, + * png_const_charp name, int compression_type, png_const_bytep profile, + * png_uint_32 proflen)); + * */ + + png_set_iCCP (pp, info, gimp_image_get_icc_profile_description (image_ID, ICC_IMAGE_PROFILE), - 0, buffer, size); + 0, (png_const_bytep)buffer, size); + png_get_iCCP(pp, info, iccp_name, compression_type, profile, proflen); printf (\"%s:%d %s() embedd icc profile \\\"%s\\\"\\n\", __FILE__,__LINE__,__func__, - info->iccp_name); + (char *)iccp_name); } #endif @@ -1039,13 +1076,13 @@ * Convert unpacked pixels to packed if necessary */ - if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) + if (png_get_color_type(pp,info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp,info) < 8) png_set_packing(pp); /* Set swapping for 16 bit per sample images */ #ifndef WORDS_BIGENDIAN - if (info->bit_depth == 16) + if (png_get_bit_depth(pp,info) == 16) png_set_swap(pp); #endif @@ -1077,7 +1114,7 @@ num = end - begin; gimp_pixel_rgn_get_rect (&pixel_rgn, pixel, 0, begin, drawable->width, num); - if (info->valid & PNG_INFO_tRNS) { + if (png_get_valid(pp,info, PNG_INFO_tRNS)) { for (i = 0; i < num; ++i) { fixed= pixels[i]; for (k = 0; k < drawable->width; ++k) { @@ -1085,7 +1122,7 @@ } } /* Forgot this case before, what if there are too many colors? */ - } else if (info->valid & PNG_INFO_PLTE && bpp == 2) { + } else if (png_get_valid(pp,info,PNG_INFO_PLTE) && bpp == 2) { for (i = 0; i < num; ++i) { fixed= pixels[i]; for (k = 0; k < drawable->width; ++k) { @@ -1097,7 +1134,7 @@ png_write_rows (pp, pixels, num); gimp_progress_update (((double)pass + (double)end / - (double)info->height) / (double)num_passes); + (double)png_get_image_height(pp, info)) / (double)num_passes); }; }; @@ -1157,7 +1194,7 @@ png_set_PLTE(pp, info, (png_colorp) before, colors); } #else - info->valid |= PNG_INFO_PLTE; + png_set_invalid(pp,info,PNG_INFO_PLTE); info->palette= (png_colorp) before; info->num_palette= colors; #endif /* PNG_LIBPNG_VER > 99 */
But you both don't seem to understand that your paste doesn't guaranty that the content isn't modified. This is the reason why this need to be provided as an attachment.
This is how I got it. Sorry but this is the best I can do, apart from taking the line breaks out myself. Roman P. replied on a private sourceforge message and they do not have an "attach" feature implemented there.
(In reply to comment #5) ? > message and they do not have an "attach" feature implemented there. Come on! Yes of course they have. At least on the public "submit patch" feature. I don't have a public internet access at day work, so hopefully you can forward me a fixed patch. I don't have much time these days, specially to fix nice but truncated patch.
I still cannot get a clean patch
Is there any improvement on this ? I'm not going to spent time on reshaping this patch Please use Add in Attachement
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle. Changing version to '19'. (As we did not run this process for some time, it could affect also pre-Fedora 19 development cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.) More information and reason for this action is here: https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora19
Set to won't fix as this bug as superseeded my capacity for unproductive discussion. It should have been dead easy to have a patch that would apply. Still this isn't provided as a applyable attachement. It would have been dead easy to fix, but nevernind the package is now orphaned and will be removed from the fedora collection for the next release
That been said, the patch should have been reported to upstream at the first step. (might not be easier)