473,385 Members | 2,269 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,385 software developers and data experts.

rotating an array....

Hi there...

i think it is a very common problem but i dont know why i didnt find
anything good for me on internet...

i want to simply rotate an array with 90,180,270 degrees....

here is how i allocated this....

srcimage = (LPBYTE)LocalAlloc(LMEM_FIXED, 320 * 200);

so any help or link?

Regards
Nov 14 '05 #1
4 5439
Roozbeh GHolizadeh <ro*******@yahoo.com> scribbled the following:
Hi there... i think it is a very common problem but i dont know why i didnt find
anything good for me on internet... i want to simply rotate an array with 90,180,270 degrees.... here is how i allocated this.... srcimage = (LPBYTE)LocalAlloc(LMEM_FIXED, 320 * 200); so any help or link?


Rotating it in place is going to be too hard for me to write off-hand,
but if you have a spare one, it's fairly easy.
Ditch all this system-specific rubbish (for the context of comp.lang.c
that is) first.

Rotate 180 degrees:
char *srcimage = malloc(320*200);
char *dstimage = malloc(320*200);
int i, j;
for (i=0; i<320; i++) {
for (j=0; j<200; j++) {
dstimage[i*200+j] = srcimage[(320-i)*200+200-j];
}
}

Rotating 90 or 270 degrees is going to lose information as your array is
not square. I'll make it square by chopping off a bit.

char *srcimage = malloc(200*200);
char *dstimage = malloc(200*200);
int i, j;
for (i=0; i<200; i++) {
for (j=0; j<200; j++) {
dstimage[i*200+j] = srcimage[j*200+i];
}
}

The rest is left as an exercise.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"A friend of mine is into Voodoo Acupuncture. You don't have to go into her
office. You'll just be walking down the street and... ohh, that's much better!"
- Stephen Wright
Nov 14 '05 #2

On Tue, 4 May 2004, Roozbeh GHolizadeh wrote:

i think it is a very common problem but i dont know why i didnt find
anything good for me on internet...

i want to simply rotate an array with 90,180,270 degrees....

here is how i allocated this....

srcimage = (LPBYTE)LocalAlloc(LMEM_FIXED, 320 * 200);


You should try Google again. The first hit I got on
"rotate image array C source" was
http://www.worldserver.com/turk/open...teGWorld.c.txt
which is pretty ugly C code, but *says* it does what you want.

-Arthur

Nov 14 '05 #3
ro*******@yahoo.com (Roozbeh GHolizadeh) wrote:
i think it is a very common problem but i dont know why i didnt find
anything good for me on internet...

i want to simply rotate an array with 90,180,270 degrees....

here is how i allocated this....

srcimage = (LPBYTE)LocalAlloc(LMEM_FIXED, 320 * 200);

so any help or link?


comp.lang.c is the wrong newsgroup. They don't really do algorithms.
comp.graphics.algorithms is probably the right group. The basic
transformation for 90 degrees is just this:

for (y=0; y < YMAX; y++) for (x=0; x < XMAX; x++) {
dst[x][YMAX-1-y] = src[y][x];
}

But it assumes that you have allocated a dst array in a flipped
version of src. If you have a non-square array, and have some
flexibility about aspect ratios or sub-clip rectangles, then there are
more things you can and may desire to do in post processing of dst.

Anyhow, a more general rotation can be composed of 3 sheers, two
horizontal, and one vertical:

H * V * H^-1

Its just a question of solving for how much to sheer in the horizontal
and vertical directions. The point is that horizontal and vertical
sheers are fairly straight forward -- and can look really good if you
use bilinear filtering.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
Nov 14 '05 #4
Thanks guys....

they worked perfect for me!!!

"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message news:<Pi**********************************@fibergl ass.ww.andrew.cmu.edu>...
On Tue, 4 May 2004, Roozbeh GHolizadeh wrote:

i think it is a very common problem but i dont know why i didnt find
anything good for me on internet...

i want to simply rotate an array with 90,180,270 degrees....

here is how i allocated this....

srcimage = (LPBYTE)LocalAlloc(LMEM_FIXED, 320 * 200);


You should try Google again. The first hit I got on
"rotate image array C source" was
http://www.worldserver.com/turk/open...teGWorld.c.txt
which is pretty ugly C code, but *says* it does what you want.

-Arthur

Nov 14 '05 #5

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

Similar topics

4
by: Ian Hubling | last post by:
I'm trying to complete a rotating banner ad within a page I have. The rotating add has four images that rotate in three-second increments. I've got the images to rotate ok - but now I want to go...
1
by: Grunt | last post by:
Hi, I have been trying to put together a rotating banner. the code works but I am having a problem with the caching of the banner images. no matter what I try the page is constantly reloading the...
31
by: Royal Denning | last post by:
I am designing a table with 2 columns and 20 rows. I want to insert small images (each with a link) and a text title in each cell of the table. On refresh of the page, I would like to have the...
14
by: mikeoley | last post by:
Why would this script below work on an html page: http://www.eg-designdev.com/aircylinders/test.htm But not a java page such as this: "http://www.eg-designdev.com/aircylinders/index3.jsp" Or...
5
by: Ricardo Furtado | last post by:
I'm trying, for a week or two, to create a procedure in order to rotate the image in any picturebox control in a cephalometry software. I've found a web site that shows how that can be done:...
3
by: avalence | last post by:
Hello, I am trying to create a nice rotating earth globe (on mouse) on my web site, in order to display my professional relationships all over the world. The best way seems to be a javascript. In...
1
by: AR123 | last post by:
Hi I want to set up a rotating banner. Not sure how to incorporate my rotating banner code into the code below. I want the rotating banner to be the main feature image? This is set up in...
6
by: swethak | last post by:
Hi, I displayed the image taken from database.How to raotate that image using javascript.plz tell that how to start the logic.plz tell that some reference websites.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.