I'm trying to read the pixel index data from a palettized image. I've tried a lot of different approaches but my naive implementation is:
Code: Select all
int x, y;
size_t width;
PixelIterator* pixel_iterator = NewPixelIterator(read_wand);
for (y = 0; y < (long)MagickGetImageHeight(read_wand); y++)
{
PixelInfo pixel_info;
PixelWand** pixels = PixelGetNextIteratorRow(pixel_iterator, &width);
if ((pixels == (PixelWand **)NULL))
break;
for (x = 0; x < (long)width; x++)
{
int index = PixelGetIndex(pixels[x]);
// process index here
}
}
Code: Select all
WandExport Quantum PixelGetIndex(const PixelWand *wand)
{
assert(wand != (const PixelWand *) NULL);
assert(wand->signature == MagickWandSignature);
if (wand->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
return((Quantum) wand->pixel.black);
}
The image I've originally loaded is a 24 BPP png, but I've used ImageMagick to remap it to a 55 colour palette (the image only uses 29 of the colours). When I save the image:
Code: Select all
MagickWriteImage(read_wand, dest_file_name);
I called the following functions to try and 'force' ImageMagick to palettize the image:
Code: Select all
SetImageStorageClass(extent_image, PseudoClass, exception);
SetImageType(extent_image, PaletteType, exception);
I took a look at the colormap of the image. It seems to be completely correct, so obviously I could look up each pixel's rbg values to find the palette index, but this seems silly.
Any ideas?