G
Gernot Frisch
Hi,
I have a 320x240 buffer of WORDS (2 bytes per cell). I must write a
code that "rotates" the buffer from 320x240 to 240x320. Here's my
solution, which is awfully slow. The device is an ARM processor
(PocketPC).
I use a 2nd buffer for the swapping, maybe the same buffer can be
used? So the memcpy at the end could be left off (costs quite a lot on
a PPC).
// Rotate a 320x240 WORD buffer by 90 degrees
void Rotate90Degs(unsigned short* Buffer)
{
static unsigned short rotBuffer[320*240];
register int x,y, x319240, y320;
// x319240 = (319-x)*240
x=0; x319240 = 319*240;
do
{
y=x319240; y320=0;
do
{
// rotBuffer[(319-x)*240+y] = Buffer[y*320 + x];
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
} while(y<240+x319240);
} while(x319240-=240, ++x<320);
memcpy(Buffer, rotBuffer, 320*240*sizeof(unsigned short));
}
I have a 320x240 buffer of WORDS (2 bytes per cell). I must write a
code that "rotates" the buffer from 320x240 to 240x320. Here's my
solution, which is awfully slow. The device is an ARM processor
(PocketPC).
I use a 2nd buffer for the swapping, maybe the same buffer can be
used? So the memcpy at the end could be left off (costs quite a lot on
a PPC).
// Rotate a 320x240 WORD buffer by 90 degrees
void Rotate90Degs(unsigned short* Buffer)
{
static unsigned short rotBuffer[320*240];
register int x,y, x319240, y320;
// x319240 = (319-x)*240
x=0; x319240 = 319*240;
do
{
y=x319240; y320=0;
do
{
// rotBuffer[(319-x)*240+y] = Buffer[y*320 + x];
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
rotBuffer[y] = Buffer[y320 + x]; ++y; y320+=320;
} while(y<240+x319240);
} while(x319240-=240, ++x<320);
memcpy(Buffer, rotBuffer, 320*240*sizeof(unsigned short));
}