possible bug string format channels

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 string format channels

Post by fmw42 »

IM 6.6.3.2 Q16 Mac OSX Tiger.

If I do:

convert logo: -type grayscale -format "%[channels]" info:
gray

and

convert logo: -type grayscale -verbose info:

Shows:

Class: PseudoClass
Type: Grayscale
Base type: Grayscale
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit


However, if I do

convert logo: -type grayscale logo_gray.png
convert logo_gray.png -format "%[channels]" info:
rgb

but

identify -verbose logo_gray.png

Shows exactly the same as above:

Class: PseudoClass
Type: Grayscale
Base type: Grayscale
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit


I get the same rgb from the string format for channels when saving as tif or jpg

convert logo: -type grayscale logo_gray.tif
convert logo_gray.tif -format "%[channels]" info:
rgb

convert logo: -type grayscale logo_gray.jpg
convert logo_gray.jpg -format "%[channels]" info:
rgb


Is this a bug or am I misunderstanding something with regard to the string format [channels]?

Does only IM internal formats recognize the channels as gray?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: possible bug string format channels

Post by anthony »

fmw42 wrote:Does only IM internal formats recognize the channels as gray?
That is correct. specifying a colorspace of greyscale will just set a colorspace of RGB and convert the image to greyscale.

IM channel specification does not have any understanding of 'single channel images' at all. To make it understand this would be a re-write a a lot of code.

Actually making IM use an 'array' of channels which is variable in size, and with only the special alpha channel flagged as 'special' would make a lot of code a lot easier. You could then loop though channels rather than having to process each channel by name. But that is the way the internal structures are arranged. Using an array would not only allow for single channel images but images with multiple alpha channels and masks. Even CMYK could be simplified in that case.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug string format channels

Post by fmw42 »

Thanks, that was what I thought it might be.
Anthony wrote:That is correct. specifying a colorspace of greyscale will just set a colorspace of RGB and convert the image to greyscale.
Actually I did not specify -colorspace gray, but -type grayscale. But I guess there is no difference in the result in this case as you say IM does not recognize external formats as gray.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: possible bug string format channels

Post by anthony »

What it does do is look at images to see how 'grey' they are when writing to determine if they should be written using a grayscale sub-format for the image file format you specified.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug string format channels

Post by fmw42 »

One other comment. When you look at -verbose info for png,tif,jpg, the Type is grayscale. So if verbose info know that, why cannot [channels] look for that. Or perhaps more properly make a new string format for [type]?

In the meantime, for unix, this works:

type=`identify -verbose <image> | sed -n 's/^.*Type: \(.*\).*$/\1/p'`

in combination with

alpha=`convert <image> -format "%A" info:`


PS this all relates to trying to help on topic viewtopic.php?f=1&t=16258 and viewtopic.php?f=2&t=16782
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug string format channels

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick-6.6.3-4 Beta available by sometime tomorrow. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug string format channels

Post by fmw42 »

thanks. this now works in IM 6.6.3.4 Q16 Mac OSX Tiger


convert logo: -type grayscale logo_gray.png
convert logo_gray.png -format "%[channels]" info:
gray
Post Reply