Page 1 of 1

how to get number of channels with PingImage

Posted: 2011-12-19T01:57:02-07:00
by jcupitt
Hi everyone,

What's the recommended way to get the number of channels in an image with ping? I've been using GetImageType() after ReadImage() but this seem not to work for PingImage().

Here's what I see with IM 6.6.0 on Ubuntu 11.10 with a generic RGB jpg image.

PingImage(Gugg_coloured.jpg)
GetImageChannelDepth(DefaultChannels) = 1
GetImageChannelDepth(AllChannels) = 1
GetImageDepth() = 1
image->depth = 8
GetImageQuantumDepth(MagickFalse) = 8
GetImageType() = 1
IsGrayImage() = 1
IsMonochromeImage() = 1
IsOpaqueImage() = 1

ReadImage(Gugg_coloured.jpg):
GetImageChannelDepth(DefaultChannels) = 8
GetImageChannelDepth(AllChannels) = 8
GetImageDepth() = 8
image->depth = 8
GetImageQuantumDepth(MagickFalse) = 8
GetImageType() = 6
IsGrayImage() = 0
IsMonochromeImage() = 0
IsOpaqueImage() = 1

Re: how to get number of channels with PingImage

Posted: 2012-01-17T08:22:04-07:00
by jcupitt
To answer my own question:

After reading the sources it looks like GetImageType() will only work after ReadImage(). For example, GetImageType() calls IsMonochromeImage(), which needs a pixel cache to work.

The jpeg loader ReadJPEGImage() only sets ->colorspace in ping, so probably the only way to get the number of bands is to directly read that field. But for many formats (eg. png and tiff) colorspace will not be enough to tell you all you need to know about color channels (I think).

So therefore it seems to not be possible to get the number of channels in an image with PingImage(). Corrections very welcome of course!