Possible bug in MagickDistortImage
Posted: 2008-11-24T19:11:06-07:00
I've been playing with affine transformations (which will eventually end up in my MagickWand examples) and the program below rotates the logo: image clockwise by 90 degrees and requests that the distorted result be retained (otherwise the result is a white image). The logo: image is 640x480 but the final image is 481x641. Is this just a result of round-off or some other unavoidable feature of the affine transformation, or is it a bug in the way the bestfit is made?
The program first puts a black pixel in each corner of logo: so that you can see that in the final image the top row and right edge have each been extended by one pixel to produce the extension from the expected 480x630 to 481x641.
Pete
The program first puts a black pixel in each corner of logo: so that you can see that in the final image the top row and right edge have each been extended by one pixel to produce the extension from the expected 480x630 to 481x641.
Pete
Code: Select all
#include <windows.h>
#include <wand/magick_wand.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define DegreesToRadians(a) (a*M_PI/180.)
// Set the affine array to rotate image by 'degrees' clockwise
double *set_rotate_affine(double r[],double degrees)
{
r[0] = cos(DegreesToRadians(fmod(degrees,360.0)));
r[1] = sin(DegreesToRadians(fmod(degrees,360.0)));
r[2] = -sin(DegreesToRadians(fmod(degrees,360.0)));
r[3] = cos(DegreesToRadians(fmod(degrees,360.0)));
r[4] = 0;
r[5] = 0;
return(r);
}
void test_wand(void) {
{
double r[6];
DrawingWand *dw = NULL;
PixelWand *pw = NULL;
MagickWand *mw = NULL;
MagickWandGenesis();
mw=NewMagickWand();
MagickReadImage(mw,"logo:");
// Put a black pixel in each of the corners
pw = NewPixelWand();
dw = NewDrawingWand();
PixelSetColor(pw,"black");
DrawSetFillColor(dw,pw);
DrawPoint(dw,0,0);
DrawPoint(dw,0,479);
DrawPoint(dw,639,479);
DrawPoint(dw,639,0);
MagickDrawImage(mw,dw);
// Do the affine rotation
MagickDistortImage(mw,AffineProjectionDistortion,
6,set_rotate_affine(r,90),MagickTrue);
// Output as GIF - avoid JPG artifacts
MagickWriteImage(mw,"logo_affine_4.gif");
if(mw)mw = DestroyMagickWand(mw);
if(dw)dw = DestroyDrawingWand(dw);
if(pw)pw = DestroyPixelWand(pw);
MagickWandTerminus();
}