speed up

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));
}
 
B

ben

do you have to copy the whole matrix to a device, or you are just gonna use
it as an array? If latter then write yourself a class overloading the
operator [] and do some index translation, that'd be quick.

ben
 
L

Lionel B

Gernot Frisch said:
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).

What you appear to be looking for is an "in-place matrix transpose". This is fairly non-trivial (for non-square
matrices). Knuth gives some algorithms:

Knuth, D. E. "Transposing a Rectangular Matrix." Ch. 1.3.3 Ex. 12. The
Art of Computer Programming, Vol. 1: Fundamental Algorithms, 3rd ed.

These generally involve cycles of element swapping. If I recall, E. Robert Tisdale recently posted some code in this ng
from his Scalar, Vector, Matrix and Tensor class Library (http://www.netwood.net/~edwin/­svmtl/). I've no idea, though,
whether these types of algorithms, which generally involve cycles of element swapping, would really be any faster than
using a temporary buffer and copying as you do.
 
C

Carlos

ben said:
do you have to copy the whole matrix to a device, or you are just gonna use
it as an array? If latter then write yourself a class overloading the
operator [] and do some index translation, that'd be quick.

ben

Please look up the meaning of top-posting and then stop doing it. Thanks.
 
B

ben

I just had a top-posting for and against topic in
microsoft.public.vc.language, no one seems too against top posting though.

ben
 
A

Alf P. Steinbach

* ben:
[top-posting, re-arranged]

Don't top-post in this group. Read the FAQ.

I just had a top-posting for and against topic in
microsoft.public.vc.language, no one seems too against top posting though.

Different places, different people, different technological level, different
intellectual level, and different social rules.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top