rotating an array....

  • Thread starter Roozbeh GHolizadeh
  • Start date
R

Roozbeh GHolizadeh

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
 
A

Arthur J. O'Dwyer

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/opensource/RotateGWorld.c.txt
which is pretty ugly C code, but *says* it does what you want.

-Arthur
 
J

Joona I Palaste

Roozbeh GHolizadeh said:
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 ([email protected]) ------------- 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
 
P

Paul Hsieh

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.
 

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,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top