Page 1 of 1

Converting grayscale png affects bit depth

Posted: 2015-06-04T11:29:45-07:00
by albertisi
Hi,
I have 2 test scenarios:
First converting 16 bit Grayscale produces, 48 bit RGB.
Second converting 8 bit Grayscale produces, 24 bit RGB.

Tested using this image:
16 bit grayscale: http://cosmin.users.sourceforge.net/tes ... 6g_lin.png
8 bit grayscale: http://upload.wikimedia.org/wikipedia/c ... _image.png

performing these convert commands:

convert grayscale16.png grayscale16_2.png
Changes bit depth to 48 bit RGB

convert grayscale8.png grayscale8_2.png
changes bit depth to 24 bit RGB

I tested using ImageMagick 6.9.1-4

Debugged into png.c and seems like ping_have_color is defaulted to MagickTrue, and never gets set to MagickFalse, or somehow the logic needs to set ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY;

Re: Converting grayscale png affects bit depth

Posted: 2015-06-04T13:09:42-07:00
by fmw42
IM does not seem to honor -define png:color-type=0 when using it in your convert, either.

The PNG developer glennrp will have to take a look and inform us further.

Re: Converting grayscale png affects bit depth

Posted: 2015-06-04T13:46:55-07:00
by albertisi
Thank you! I already PM Glen.

Re: Converting grayscale png affects bit depth

Posted: 2015-06-04T14:55:51-07:00
by glennrp
albertisi wrote:Hi,
Debugged into png.c and seems like ping_have_color is defaulted to MagickTrue, and never gets set to MagickFalse, or somehow the logic needs to set ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY;
It's due to a recent change to avoid inspecting every pixel; there was a complaint that it was too costly.

Re: Converting grayscale png affects bit depth

Posted: 2015-06-04T14:57:51-07:00
by albertisi
Yes Glen, I was complaining about it...

Re: Converting grayscale png affects bit depth

Posted: 2015-06-04T15:29:19-07:00
by fmw42
Glenn,

Perhaps you can still do what you did to speed up things, but respect the -define png:color-type=0 when used to process it so it keeps the grayscale.

Re: Converting grayscale png affects bit depth

Posted: 2015-06-08T08:43:32-07:00
by albertisi
Here is the updated png.c.
All i did was flipped the ping_have_color default value from MagickTrue to MagickFalse. It fixes my problem with performance, and bit depth. Tested it in my workflows with different images.

My patch is here:

File: png.c
line: 7969

Code: Select all

 ping_have_blob=MagickFalse;
  ping_have_cheap_transparency=MagickFalse;
  ping_have_color=MagickFalse; //MagickTrue; //Set Default to False, for Grayscale img handling
  ping_have_non_bw=MagickTrue;
  ping_have_PLTE=MagickFalse;
Not sure how to submit it, so i am posting it here.