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