Possible bug converting grayscale to sRGB PNG

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Possible bug converting grayscale to sRGB PNG

Post by fmw42 »

.
When converting a grayscale image to RGB PNG, the string format %[colorspace] says sRGB but identify -verbose says grayscale. I think identify -verbose is wrong.

Code: Select all

convert logo: -colorspace gray logo.jpg
convert logo.jpg PNG24:logo.png
convert logo.png -format "%[colorspace]" info:
sRGB

Code: Select all

identify -verbose logo.png
Image: logo.png
...
Colorspace: Gray
...
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)


This occurs in IM 6.9.9.27 Q16 Mac OSX Sierra and IM 7.0.7.15 Q16 HDRI
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible bug converting grayscale to sRGB PNG

Post by magick »

Note identify -verbose says "Base colorspace: sRGB". The colorspace of gray is the colorspace *after* the image is analyzed. It means that all the colors have identical red, green, and blue intensities.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible bug converting grayscale to sRGB PNG

Post by fmw42 »

That is confusing to me.

Usually it says colorspace sRGB but type=grayscale. I do not see any Base colorspace in identify -verbose for the example above.

Code: Select all

Image: logo.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 640x480+0+0
  Units: Undefined
  Type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8-bit
  Channel depth:
    gray: 8-bit
  Channel statistics:
There is only colorspace and type.

If I do the same with miff using -type truecolor, I still get grayscale.

Code: Select all

convert logo: -colorspace gray logo.jpg
convert logo.jpg -type truecolor logo.miff
convert logo.miff -format "%[colorspace]\n" info:
Gray

Code: Select all

identify -verbose logo.miff
Image: logo.miff
  Format: MIFF (Magick Image File Format)
  Class: DirectClass
  Geometry: 640x480+0+0
  Units: Undefined
  Type: Grayscale
  Base type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8-bit
  Channel depth:
    gray: 8-bit

The point is that sometimes other tools can only read RGB images even when they are grayscale. We had ways around this before.


From the -define section of the options page:

"colorspace:auto-grayscale=on|off prevent automatic conversion to grayscale inside coders that support grayscale. This should be accompanied by -type truecolor. PNG and TIF do not need this define. With PNG, just use PNG24:image. With TIF, just use -type truecolor. JPG and PSD will need this define."

So using PNG24: should have converted the image to colorspace sRGB. Likewise, I would have thought using -type truecolor would have worked with miff:, but it does not.

With TIFF, I get similar results as to PNG -- %[colorspace] returns sRGB, but identify -verbose returns colorspace gray.

Code: Select all

convert logo.jpg -type truecolor logo.tiff
convert logo.tiff -format "%[colorspace]" info:
sRGB

identify -verbose logo.tiff
Image: logo.tiff
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 640x480+0+0
  Units: PixelsPerInch
  Type: Grayscale
  Base type: TrueColor
  Endianess: LSB
  Colorspace: Gray
  Depth: 8-bit
  Channel depth:
    gray: 8-bit
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible bug converting grayscale to sRGB PNG

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.
Post Reply