Page 1 of 1
Read Palettized RGBA PNG
Posted: 2008-06-02T07:37:40-07:00
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.
Re: Read Palettized RGBA PNG
Posted: 2008-06-02T07:46:52-07:00
by magick
Yes, see
http://www.imagemagick.org/Magick++/ and look for a discussion of pixel iterators.
Re: Read Palettized RGBA PNG
Posted: 2008-06-02T23:55:54-07:00
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.
Re: Read Palettized RGBA PNG
Posted: 2008-06-03T06:08:36-07:00
by magick
Re: Read Palettized RGBA PNG
Posted: 2008-06-03T08:29:48-07:00
by chand81
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);
}
Re: Read Palettized RGBA PNG
Posted: 2008-06-03T08:48:27-07:00
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.
Re: Read Palettized RGBA PNG
Posted: 2008-06-04T00:35:35-07:00
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.