Newbie question on reading pixel color
Posted: 2008-04-20T11:47:33-07:00
Hi guys,
I am a newbie and I am trying to figure out a a simple program using a c interface and imagemagick. First I have to load a picture and reduce the number of colors to a given number (e.g. 8). Next, I have to read the pixel colors one by one.
I got across and example to read pixel color and I stripped it down to:
MagickWandGenesis();
wand=NewMagickWand();
MagickReadImage(wand,argv[1]);
PixelWand **pixels;
iterator=NewPixelIterator(wand);
unsigned long width;
MagickPixelPacket pixel;
wpxl=MagickGetImageWidth(wand);
hpxl=MagickGetImageHeight(wand);
for (y=0; y < hpxl; y++)
{
pixels=PixelGetNextIteratorRow(iterator,&width);
for (x=0; x < wpxl; x++)
{
PixelGetMagickColor(pixels[x],&pixel);
printf("%d %d => %f %f %f \n",x,y,pixel.red,pixel.green,pixel.blue);
}
}
Something I dont fully understand is why pixels is ** and not * if only one row at a time is read into it. Aslo, do I really need an iterator? Isnt there a function that allows me to access pixels directly (e.g. color= function(wand,x,y) or pixels=function(wand,x1,y1,x2,y2) and PixelGetMagickVolor(pixels[x,y],&pixel))?
Sorry for the dumb questions but I am having hard time finding detailed documentation on the matter.
Thanks.
Efo
I am a newbie and I am trying to figure out a a simple program using a c interface and imagemagick. First I have to load a picture and reduce the number of colors to a given number (e.g. 8). Next, I have to read the pixel colors one by one.
I got across and example to read pixel color and I stripped it down to:
MagickWandGenesis();
wand=NewMagickWand();
MagickReadImage(wand,argv[1]);
PixelWand **pixels;
iterator=NewPixelIterator(wand);
unsigned long width;
MagickPixelPacket pixel;
wpxl=MagickGetImageWidth(wand);
hpxl=MagickGetImageHeight(wand);
for (y=0; y < hpxl; y++)
{
pixels=PixelGetNextIteratorRow(iterator,&width);
for (x=0; x < wpxl; x++)
{
PixelGetMagickColor(pixels[x],&pixel);
printf("%d %d => %f %f %f \n",x,y,pixel.red,pixel.green,pixel.blue);
}
}
Something I dont fully understand is why pixels is ** and not * if only one row at a time is read into it. Aslo, do I really need an iterator? Isnt there a function that allows me to access pixels directly (e.g. color= function(wand,x,y) or pixels=function(wand,x1,y1,x2,y2) and PixelGetMagickVolor(pixels[x,y],&pixel))?
Sorry for the dumb questions but I am having hard time finding detailed documentation on the matter.
Thanks.
Efo