Flipping an image horizontally - Xwindows

This is a discussion on Flipping an image horizontally - Xwindows ; Hi all, Whats the best way to display in image (created with XCreateImage()) upside down. I experimeted with XCreateImage by changing the bytes_per_line to a negative number and pasing a modified (pointing to the las scan line) data pointer. No ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Flipping an image horizontally

  1. Flipping an image horizontally

    Hi all,

    Whats the best way to display in image (created with XCreateImage())
    upside down. I experimeted with XCreateImage by changing the
    bytes_per_line to a negative number and pasing a modified (pointing to
    the las scan line) data pointer. No luck yet, any ideas?

    Thanks


  2. Re: Flipping an image horizontally

    On Wed, 14 Jun 2006 19:51:02 -0700, chandaka wrote:

    > Hi all,
    >
    > Whats the best way to display in image (created with XCreateImage())
    > upside down. I experimeted with XCreateImage by changing the
    > bytes_per_line to a negative number and pasing a modified (pointing to the
    > las scan line) data pointer. No luck yet, any ideas?
    >
    > Thanks


    If you're lucky, that might flip the image *vertically*. Horizontally is
    a bit tougher. Did you want it rotated 180 degrees or simply mirrored?

    Of course one can brute-force it in various ways. The simplest method
    on non-OpenGL X to rotate an image 180 degrees is to do something along
    the following lines:

    XImage *rotate180( XImage * inp)
    {
    char * outd = malloc(inp->bytes_per_line * inp->height);
    int yi, yo;
    int xi, xo;

    XImage * out = XCreateImage(dpy, visual, inp->depth, ZPixmap, 0, outd,
    inp->width, inp->height, inp->bytes_per_line
    );
    for(yi = 0, yo = inp->height-1; yi <= yo; yi++, yo--) {
    for(xi = 0, xo = inp->width-1; xi <= xo; xi++, xo++) {
    unsigned long tmp = XGetPixel(inp, xi, yi);
    XPutPixel(out, xo, yo, tmp);
    }
    }

    return out;
    }

    This is probably also the slowest.

    If one is lucky enough to have OpenGL, one can set up a surface with a
    single quad and orient it appropriately.

    --
    #191, ewill3@earthlink.net
    It's still legal to go .sigless.


  3. Re: Flipping an image horizontally

    chandaka@gmail.com wrote:

    > Whats the best way to display in image (created with XCreateImage())
    > upside down. I experimeted with XCreateImage by changing the
    > bytes_per_line to a negative number and pasing a modified (pointing to
    > the las scan line) data pointer. No luck yet, any ideas?


    Once upon a time, David Lemke posted to comp.sources.x two programs
    named "flip" and "meltdown". The first one had two functions named
    "flip_horz" and "flip_vert" that could flip a drawable (not an XImage).

    You may get David's post at

    http://groups.google.com.br/group/co...6?dmode=source

    Be warned that this is quite dated code, not ANSI-compliant. The
    programs still work but with current hardware they run too fast.
    Used to be much more funny on a DECstation with Ultrix. Gosh, I'm
    getting old...

    --- Casantos


+ Reply to Thread