Determine original image type (RGBA or only alpha)

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
ismfismf

Determine original image type (RGBA or only alpha)

Post by ismfismf »

Hi!

I have looked through the forum, but could not find an answer. I have troubles to tell an RGBA image apart from a black/white image.

If a PNG or TGA image is stored as RGBA, but the whole image is transparent, then ImageMagick always returns type BilevelType and color space RGBColorspace when reading the file. How can I tell that apart from a real bilevel image (indexed black/white with transparency)?

Image *image = new Image();
image->adjoin(true);
image->read(filename);
ImageType image_type = image->type(); // is BilevelType
ColorspaceType colorType = image->colorSpace(); // is RGBColorspace

If ImageMagick does some automatic quantization/color reduction, how can I turn that off for reading an image (for the sample code above).

Thanks.
ismfismf

Re: Determine original image type (RGBA or only alpha)

Post by ismfismf »

BTW, the version of ImageMagick is 6.6.0.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Determine original image type (RGBA or only alpha)

Post by fmw42 »

In command line you can use -format "%[channels]" info:

convert logo: -format "%[channels]" info:
rgb

convert logo: -transparent white -format "%[channels]" info:
rgba

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

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



convert logo: -monochrome -format "%r" info:
pseudoclassgray

convert logo: -format "%r" info:
PseudoClassRGB

convert logo: -transparent white -format "%r" info:
DirectClassRGBMatte


see http://www.imagemagick.org/script/escape.php
ismfismf

Re: Determine original image type (RGBA or only alpha)

Post by ismfismf »

This works. Thanks.

I actually need the same as C++ call. Any idea which method does the same?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Determine original image type (RGBA or only alpha)

Post by fmw42 »

Sorry I only use command line. Hopefully someone else can point you in the right direction.
ismfismf

Re: Determine original image type (RGBA or only alpha)

Post by ismfismf »

Does anyone have an idea how to get the right format programmatically?
ismfismf

Re: Determine original image type (RGBA or only alpha)

Post by ismfismf »

Anyone any idea?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Determine original image type (RGBA or only alpha)

Post by fmw42 »

FYI: see viewtopic.php?f=3&t=16794 for issues related to string format [channels]
Post Reply