http://imagej.273.s1.nabble.com/Rotate-an-image-with-given-angle-tp5000544p5000588.html
source and destination image sizes were the same. In your case, they are
cost of complicating the logic, which may be why you didn't catch this.
David M. Gauntt, Ph.D.
>Date: Fri, 26 Oct 2012 17:36:20 +0530
>From: Veeranjaneyulu TOka <
[hidden email]>
>Subject: Rotate an image with given angle
>
>Hi All,
>
>I am trying to rotate an image with given angle but really could not
>manage to work this properly... Below is the piece of code i have ported
>from ImageJ to rotate arbitrarly.
>
>for example here
>
>destWidth = 464 and destHeight = 464
>
>source size is uWidth = 405 and uHeight = 227.
>
>
> double centerX, centerY, angleRadians, ca, sa, tmp1, tmp2, tmp3, tmp4,
>xs, ys, dwidth, dheight;
> int index, x, y;
> centerX = destWidth /2.0;
> centerY = destHeight / 2.0;
>
> angleRadians = -angle/(180.0/3.14159265358979323846);
> ca = cos(angleRadians);
> sa = sin(angleRadians);
> tmp1 = centerY*sa-centerX*ca;
> tmp2 = -centerX*sa-centerY*ca;
> dwidth = uWidth, dheight= uHeight;
>
> for (y=0; y<destHeight; y++)
> {
> index = y*destWidth*4;
> tmp3 = tmp1 - y*sa + centerX;
> tmp4 = tmp2 + y*ca + centerY;
> for (x=0; x<destHeight; x++)
> {
> xs = x*ca + tmp3;
> ys = x*sa + tmp4;
> if ((xs>=-0.01) && (xs<dwidth) && (ys>=-0.01) && (ys<dheight))
> {
> pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 0];
> pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 1];
> pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 2];
> pbOut[index++] = pbInput[uWidth*(int)ys*4+(int)xs*4 + 3];
> }
> else
> {
> pbOut[index++] = 0xff; pbOut[index++] = 0xff; pbOut[index++] = 0xff;
>pbOut[index++] = 0xff;
> }
> }
>
>With the above code, the output that i get is cropping of top-right,
>right-bottom corners. I think something problem with my output buffer
>filling procedure though am not sure.
>
>Could you plz help me to figure the issue plz? I really do not have clue
>and need your help on this.
>
>
>thanks,
>Veeru.
>