rotating an array....

Discussion in 'C Programming' started by Roozbeh GHolizadeh, May 4, 2004.

  1. 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
    Roozbeh GHolizadeh, May 4, 2004
    #1
    1. Advertising

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

    -Arthur
    Arthur J. O'Dwyer, May 4, 2004
    #2
    1. Advertising

  3. Roozbeh GHolizadeh <> 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 () ------------- 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
    Joona I Palaste, May 4, 2004
    #3
  4. Roozbeh GHolizadeh

    Paul Hsieh Guest

    (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/
    Paul Hsieh, May 4, 2004
    #4
  5. Thanks guys....

    they worked perfect for me!!!

    "Arthur J. O'Dwyer" <> wrote in message news:<>...
    > 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/opensource/RotateGWorld.c.txt
    > which is pretty ugly C code, but *says* it does what you want.
    >
    > -Arthur
    Roozbeh GHolizadeh, May 5, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman

    Rotating a Picturebox

    Charles A. Lackman, Oct 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    930
    Supra
    Oct 14, 2004
  2. e4_java

    rotating a bufferedimage

    e4_java, Nov 29, 2004, in forum: Java
    Replies:
    7
    Views:
    1,046
    Babu Kalakrishnan
    Dec 1, 2004
  3. Ray

    Rotating text in chat?

    Ray, May 16, 2005, in forum: Java
    Replies:
    2
    Views:
    453
    Brooks Hagenow
    May 16, 2005
  4. mark | r

    rotating an image

    mark | r, Jul 2, 2003, in forum: HTML
    Replies:
    4
    Views:
    4,711
    Mark Parnell
    Jul 2, 2003
  5. ravxm
    Replies:
    2
    Views:
    1,804
    ravxm
    Jan 27, 2007
Loading...

Share This Page