Re: 90 Rotation in one buffer only
- From: "Andrey Kuznetsov" <spam0@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 24 Nov 2005 16:18:48 +0100
> what could be the BEST Memory Optimal way of rotating an image or
> matrix by 90
> degrees using input buffer only? i.e. Input buffer only is the output
> memory buffer.
>
> Say, we can use small amount of memory locations (say 30-40 bytes extra
> considering 1 pixel/byte) for temporary storage of any block/blocks in
> the image but not the whole of image.
all you need is only one tmp pixel:
//assume for simplicity that pixels are integers:
int tmp;
//image width and height
int w, h;
//only first quadrant
int w2 = w / 2;
int h2 = h / 2;
//loop through pixels
for(int j = 0; j < h2; j++) {
for(int i = 0; i < w2; i++) {
tmp = getPixel(i, j);
setPixel(i, j, getPixel(i, h - j));
setPixel(i, h - j, getPixel(w - i, h - j));
setPixel(w - i, h - j, getPixel(w - i, j));
setPixel(w - i, j, tmp);
}
}
//get value of pixel at coordinates x, y
int getPixel(int x, int y);
//set value of pixel at coordinates x, y
int setPixel(int x, int y, int value);
HTH
--
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
.
- Follow-Ups:
- Re: 90 Rotation in one buffer only
- From: Thomas Richter
- Re: 90 Rotation in one buffer only
- References:
- 90 Rotation in one buffer only
- From: Naresh
- 90 Rotation in one buffer only
- Prev by Date: interlacing/de-interlacing optimizations in image data
- Next by Date: Re: 90 Rotation in one buffer only
- Previous by thread: 90 Rotation in one buffer only
- Next by thread: Re: 90 Rotation in one buffer only
- Index(es):
Relevant Pages
|
Loading