Read Palettized RGBA PNG

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
chand81

Read Palettized RGBA PNG

Post by chand81 »

I need to read the palette and pixel indices from an indexed PNG with RGBA pixels.
Can I use Magick::Image to retrieve this information?

Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read Palettized RGBA PNG

Post by magick »

Yes, see http://www.imagemagick.org/Magick++/ and look for a discussion of pixel iterators.
chand81

Re: Read Palettized RGBA PNG

Post by chand81 »

I found this page on pixel iterator but cant see how it can be used.
http://www.imagemagick.org/api/pixel-iterator.php

Can you please provide short code snippet here?

Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read Palettized RGBA PNG

Post by magick »

chand81

Re: Read Palettized RGBA PNG

Post by chand81 »

magick wrote:Did you review this page: http://www.imagemagick.org/Magick++/Pixels.html?
Yes, but I couldn't see how to retrieve the color palette !?

I had tried the following code using Image. But the color returned by img.colorMap() has opacity=0 irrespective of the palette index sampled.

Code: Select all

	Magick::Image img;
	img.read(fileName.c_str());
	Magick::IndexPacket *ip = img.getIndexes();
	if(ip)
	{
		int clrMapSz = img.colorMapSize();
		Magick::Color clr = img.colorMap(10);
	}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read Palettized RGBA PNG

Post by magick »

Not sure what you're looking for. The getConst() method returns the pixel red, green, blue, and opacity and the indexes() method returns the colormap indexes and the colorMap() method returns the red, green, blue of each colormap entry.
chand81

Re: Read Palettized RGBA PNG

Post by chand81 »

I'm writing a utility that will save decoded PNG to a custom file format. This file will then be used to load compressed (palette + indices) texture into OpenGL.
So I need to read the palette entires RGBA (alpha is required) and the pixel indices from the PNG file and dump this information in an uncompressed form to a binary file.

I can use getConstPixels to retrieve the pixel opacity values and add this to the RGB returned by colorMap. Is there a better way to directly get the complete palette information (RGB + A) ?

Thanks.
Post Reply