473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

speed up

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

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

Jul 23 '05 #1
6 1244
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
"Gernot Frisch" <Me@Privacy.net> wrote in message
news:3e************@individual.net...
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));
}

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

Jul 23 '05 #2
"Gernot Frisch" <Me@Privacy.net> wrote in message news:3e************@individual.net...
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.

--
Lionel B

Jul 23 '05 #3
ben wrote:
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.

Jul 23 '05 #4
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
Please look up the meaning of top-posting and then stop doing it. Thanks.

Jul 23 '05 #5
* ben:
[top-posting, re-arranged]


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

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


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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #6
ben wrote:
I just had a top-posting for and against topic in
microsoft.public.vc.language, no one seems too against top posting though.

ben

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


And?

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Yang Li Ke | last post by:
Hi guys, Is it possible to know the internet speed of the visitors with php? Thanx -- Yang
8
by: Rob Ristroph | last post by:
I have tried out PHP 5 for the first time (with assistance from this group -- thanks!). The people I was working with have a site that uses lots of php objects. They are having problems with...
34
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
28
by: Maboroshi | last post by:
Hi I am fairly new to programming but not as such that I am a total beginner From what I understand C and C++ are faster languages than Python. Is this because of Pythons ability to operate on...
52
by: Neuruss | last post by:
It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. I just wonder what do you all think? Will Python...
7
by: YAZ | last post by:
Hello, I have a dll which do some number crunching. Performances (execution speed) are very important in my application. I use VC6 to compile the DLL. A friend of mine told me that in Visual...
6
by: Ham | last post by:
Yeah, Gotto work with my VB.Net graphic application for days, do any possible type of code optimization, check for unhandled errors and finally come up with sth that can't process 2D graphics and...
6
by: Jassim Rahma | last post by:
I want to detect the internet speed using C# to show the user on what speed he's connecting to internet?
11
by: kyosohma | last post by:
Hi, We use a script here at work that runs whenever someone logs into their machine that logs various bits of information to a database. One of those bits is the CPU's model and speed. While...
4
by: nestle | last post by:
I have DSL with a download speed of 32MB/s and an upload speed of 8MB/s(according to my ISP), and I am using a router. My upload speed is always between 8MB/s and 9MB/s(which is above the max upload...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.