[magick-users] Trouble Quantizating an Image [I was unable to
get/set the proper values in RGB]
Victor Silva
vfbsilva at gmail.com
Sat Sep 16 20:54:12 CDT 2006
Hi folks I'm here again bugging you :)
I have the following function (to read better use
http://pastey.net/847) wich holds the follwing piece of code
for (x=0; x < (long) source->columns; x++)
{
{
q->red = (p->red) / tones;
q->green = (p->green) / tones;
q->blue= (q->blue) / tones;
q->opacity= p->opacity;
p++;
q+
}
}
where p and q are pixel packets, but by some reason I get no change on
the image.
Ive read on the boards and googled and found this
http://support.imagiware.com/info/images/ImageMagick/quantize.html
and this
http://www.imagemagick.org/discussion-server/viewtopic.php?p=21104&sid=8e26689ed4382c04cb39d2d2693d1128
But none of the links where exactly what I'm looking for. So question is
is there is any way of getting the pixel value it self, Ive looked the
docs and maybe what I would need is Read/Write Stream but I can't
understand why does my current approach fails.
Folks thanks a lot for all the support, docs, and disponibility. :)
P.S.:I have appended the whole source above if you have some problem
with the link.
int quantizateImage(Image* source, ImageInfo* source_data, int tones)
{
long x, y;
const PixelPacket *p;
PixelPacket* q;
ExceptionInfo* exception;
Image* destination; ImageInfo* destination_data;
Image* canvas;
PixelPacket white = {MaxRGB, MaxRGB, MaxRGB, OpaqueOpacity};
destination_data = CloneImageInfo( source_data );
exception = &source->exception;
destination = CloneImage( source,0,0,MagickTrue, exception );
if (destination == (Image *) NULL)
{ return 0; } //@TODO: Provide a better exception handler
for (y=0; y < (long) source->rows; y++)
{
p = AcquireImagePixels( source,0,y,source->columns,1, exception );
q = GetImagePixels( destination,0,y,destination->columns,1 );
if ((p == ( const PixelPacket* ) NULL) || (q == ( PixelPacket * ) NULL))
break;
for (x=0; x < (long) source->columns; x++)
{
{
q->red = (p->red) / tones;
q->green = (p->green) / tones;
q->blue= (q->blue) / tones;
q->opacity= p->opacity;
p++;
q++;
}
/* else
{
q->red = p->red;
q->green= p->green;
q->blue= p->blue;
q->opacity= p->opacity;
p++;
q++;
}
*/
}
if (SyncImagePixels(destination) == MagickFalse)
break;
}
if (y < (long) source->rows)
{ return 0; } //@TODO: provide a better exception handler
destination_data = CloneImageInfo( source_data );
destination_data->size = AcquireMemory(sizeof ( "800x600" ) );
strcpy( destination_data-> size , "800x600");
destination_data->background_color = white;
canvas=AllocateImage( destination_data );
assert( canvas != NULL );
SetImage( canvas, OpaqueOpacity );
DisplayImages ( destination_data, destination );
DestroyImageInfo( destination_data );
}
More information about the Magick-users
mailing list