Re: 90 Rotation in one buffer only



Hi,

> you are right, sorry for this mistake.

> here is code which works (tested):

> public void rotate() {
> int w = width - 1;
> int h = height - 1;
> int w2 = width / 2;
> int h2 = height / 2;
> int tmp;

> for (int y = 0; y < h2; y++) {
> for (int x = 0; x < w2; x++) {
> tmp = getPixel(x, y);
> setPixel(x, y, getPixel(w - y, x));
> setPixel(w - y, x, getPixel(w - x, h - y));
> setPixel(w - x, h - y, getPixel(y, h - x));
> setPixel(y, h - x, tmp);
> }
> }
> }

That looks of course better. (-; However, there's still a problem
here: You need at least a buffer of width and height =
max(width,height) of the original image data, i.e. it will perform
"out of bounds" accesses unless the image is square. Solving that
problem is actually the harder part of it. Of course a memory chunk of
width * height pixels should be enough to perform a rotation "in
place", but it is very hard to do unless width = height.

So long,
Thomas
.


Loading