how to get number of channels with PingImage

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jcupitt
Posts: 26
Joined: 2011-04-26T05:14:01-07:00
Authentication code: 8675308

how to get number of channels with PingImage

Post 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
jcupitt
Posts: 26
Joined: 2011-04-26T05:14:01-07:00
Authentication code: 8675308

Re: how to get number of channels with PingImage

Post 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!
Post Reply