// Last updated 2011/12/02 14:48
//example/pixel_mod.c
// Change the colour of one pixel in the logo: image
// using either DrawPoint or a RegionIterator
#include <windows.h>
#include <wand/magick_wand.h>
void test_wand(void)
{
MagickWand *mw = NULL;
// Comment out this define to use the region iterator instead of the Draw
#define USE_DRAW
#ifndef USE_DRAW
PixelIterator *iterator = NULL;
PixelWand **pixels = NULL;
size_t x;
#else
DrawingWand *dw = NULL;
PixelWand *fill = NULL;
#endif
MagickWandGenesis();
/* Create a wand */
mw = NewMagickWand();
/* Read the input image */
MagickReadImage(mw,"logo:");
#ifndef USE_DRAW
// Get a one-pixel region at coordinate 200,100
iterator = NewPixelRegionIterator(mw,200,100,1,1);
pixels=PixelGetNextIteratorRow(iterator,&x);
// Modify the pixel
PixelSetColor(pixels[0],"red");
// then sync it back into the wand
PixelSyncIterator(iterator);
#else
fill = NewPixelWand();
dw = NewDrawingWand();
// Set the fill to "red" or you can do the same thing with this:
// PixelSetColor(fill,"rgb(255,0,0)");
PixelSetColor(fill,"red");
DrawSetFillColor(dw,fill);
// Uses the current Fill as the colour of the point at 200,100
DrawPoint(dw,200,100);
/*
srand(time(0));
for(i=0;i<50;i++) {
// plonk some random black pixels in the image
j = rand()%DS_WIDTH;
k = rand()%DS_HEIGHT;
image[k*DS_WIDTH+j] = 0;
}
*/
MagickDrawImage(mw,dw);
#endif
/* write it */
MagickWriteImage(mw,"logo_pixel.gif");
/* Tidy up */
#ifndef USE_DRAW
iterator=DestroyPixelIterator(iterator);
#else
if(dw)dw = DestroyDrawingWand(dw);
if(fill)fill = DestroyPixelWand(fill);
#endif
if(mw) mw = DestroyMagickWand(mw);
MagickWandTerminus();
}