getting the colormapindex for each pixel
Posted: 2016-10-20T08:24:32-07:00
hi,
unluckely I'm a complete newbe using the magickwand within c-lang. first of all my magickwand-version is the debian-sid (8:6.8.9.9-7.2)
I tried to generate a small test image with 3 colors in it.
the goal to reach was printing out the palette index for each pixel. so I wrote a small program
the outcoming result is:
why does this not work?
thank you in advance for helping me
murmel
unluckely I'm a complete newbe using the magickwand within c-lang. first of all my magickwand-version is the debian-sid (8:6.8.9.9-7.2)
I tried to generate a small test image with 3 colors in it.
Code: Select all
$ convert -size 4x4 xc:red xc:green xc:blue +append a.png
$ identify -format "%k %wx%h %f\n" a.png
3 12x4 a.png
Code: Select all
// cc -o `pkg-config --cflags --libs MagickWand` -o c c.c
#include <wand/magick_wand.h>
int main(int argc,char **argv)
{
MagickWand *m_wand = NULL;
PixelWand *color = NULL;
MagickPixelPacket pixel;
PixelIterator* pixel_iterator = NULL;
int x, y;
size_t width, height;
size_t indexedcolors;
double R, G, B;
char* file = argv[1];
MagickWandGenesis();
m_wand = NewMagickWand();
color = NewPixelWand();
MagickReadImage(m_wand, file);
width = MagickGetImageWidth(m_wand);
height = MagickGetImageHeight(m_wand);
indexedcolors = MagickGetImageColors(m_wand);
printf("image: %s width: %d height: %d countindex: %d\n", file, (int) width, (int) height, indexedcolors);
for (y = 0; y <= (int)height; y++)
{
printf("line: %03d pixel: ", y);
for (x = 0; x < (int)width; x++)
{
MagickGetImagePixelColor(m_wand, (ssize_t)x,(ssize_t)y, color);
printf("%02x ", PixelGetColorCount(color));
}
printf("\n");
}
MagickWandTerminus();
exit(0);
}
Code: Select all
image: a.png width: 12 height: 4 countindex: 3
line: 000 pixel: 00 00 00 00 00 00 00 00 00 00 00 00
line: 001 pixel: 00 00 00 00 00 00 00 00 00 00 00 00
line: 002 pixel: 00 00 00 00 00 00 00 00 00 00 00 00
line: 003 pixel: 00 00 00 00 00 00 00 00 00 00 00 00
line: 004 pixel: 00 00 00 00 00 00 00 00 00 00 00 00
thank you in advance for helping me
murmel