Archived

This topic is now archived and is closed to further replies.

SMurf7

Rotating a buffer

Recommended Posts

Hi, I know this may sound a bit silly (there is a better way of doing it, I just don''t understand it enough to trust it but my program loads an 480x640 image into a UCHAR buffer, and I want to display it on the screen (which is 640x480). If I use memcpy to just copy the data from one buffer to the active surface, the result (naturally) is a really screwed-up image. How would I go about "rotating" the data in the buffer 90-degrees clockwise?

Share this post


Link to post
Share on other sites
To clarify things a bit:-

My source image is 480x640.
It is stored in a 307,200 byte buffer.
My destination image (the screen) is 640x480.
It is stored in buffer of the same size as the stored image (when it is locked).
I wish to move the pixels around in the buffer like thus:-
(0, 0) -> (639, 0)
(479, 0) -> (639, 479)
(479, 639) -> (0, 479)
(0, 639) -> (0, 0)

In terms of byte values:-

0 -> 639
479 -> 307199
307199 -> 306560
306720 -> 0

Is there a simple alogrithm with which this can be done?
Failing that, is there a way to read in data from a file "vertically" (this would eliminate the need for me to transform it in memory)?

Share this post


Link to post
Share on other sites