Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > rotating an array....

Reply
Thread Tools

rotating an array....

 
 
Roozbeh GHolizadeh
Guest
Posts: n/a
 
      05-04-2004
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
 
Reply With Quote
 
 
 
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      05-04-2004

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

 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      05-04-2004
Roozbeh GHolizadeh <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- 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
 
Reply With Quote
 
Paul Hsieh
Guest
Posts: n/a
 
      05-04-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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/
 
Reply With Quote
 
Roozbeh GHolizadeh
Guest
Posts: n/a
 
      05-04-2004
Thanks guys....

they worked perfect for me!!!

"Arthur J. O'Dwyer" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) u>...
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating my shield harmonics MCSE 16 06-13-2005 03:23 PM
Rotating text in chat? Ray Java 2 05-16-2005 05:44 PM
rotating a bufferedimage e4_java Java 7 12-01-2004 03:08 AM
Rotating a Picturebox Charles A. Lackman ASP .Net 1 10-14-2004 09:39 AM
rotating an image mark | r HTML 4 07-02-2003 10:42 PM



Advertisments