Re: XForms: pixel value from XImage & flimage...

From: Steve Lamont (spl@szechuan.ucsd.edu)
Date: Thu Mar 09 2000 - 11:08:36 EST

  • Next message: zaatri abdelouahab: "XForms: Pgm and xforms"

    # To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

    > How should i process to convert pixel values from the ximage to color
    > index in the lookup table ??
    >
    > here is a piece of code i wrote :
    > /*** filling the look up table ***/
    >
    > for (i=0;i<fl_image->map_len;i++)
    > {
    >
    > fl_getmcolor(IDCOL1+i,&red,&green,&blue); <--- i think my problem is
    > coming from here

    Yep, that's where the problem is.

    The problem is that the XForms colormap is *not* the same as the real
    Colormap used by X.

    To fetch the actual LUT used by X, you need to use XQueryColors() to
    fetch the actual RGB tuples. For example:

            XColor color_cells[256];
            int i;

            for ( i = 0; i < 256; i++ ) {

                color_cells[i].pixel = i;
                color_cells[i].flags = DoRed | DoGreen | DoBlue;

            }

            XQueryColors( fl_get_display(), fl_state[fl_get_vclass()].colormap,
                          color_cells, 256 );

            for ( i = 0; i < 256; i++ ) {

                fl_image->red_lut[i] = color_cells[i].red;
                fl_image->green_lut[i] = color_cells[i].green;
                fl_image->blue_lut[i] = color_cells[i].blue;
            
            }

    I'm, of course, assuming a 256 entry Colormap. To be completely
    kosher, you should use the depth of the Visual, also found in the
    fl_state[] for your Visual class.

                                    - - -

    BTW, this is okay

    > /*** filling the color Index array ***/
    >
    > for (i=0; i<ximage->width; i++)
    > for (j=0; j<ximage->height ; j++)

    but you may wish to change it to

            for (j=0; j<ximage->height ; j++)
                    for (i=0; i<ximage->width; i++)
            [...]

    for performance reasons. Pixels are arranged in scan line (column)
    order and it will be somewhat faster to read them in that manner
    rather than in row order.

                                                            spl
    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Thu Mar 09 2000 - 11:12:21 EST