From: mek@hydrox.enet.dec.com (Mark Klamerus)
Newsgroups: fj.mail-lists.x-window
Subject: Help on XSetWindowColormap
Date: 9 Oct 92 13:21:21 GMT
Distribution: fj
Organization: Workstation Div., Supermicro Systems Group, Sony Corporation

Date: 6 Oct 92 20:35:34 GMT
Message-Id: <9210062035.AA09271@enet-gw.pa.dec.com>
Newsgroups: comp.windows.x



	
        Help,

        I'm writing an image display application.  This will be in Motif,
        but the problem I'm running into is X (I think).  The gist of things
        is problems with the colormaps.

        These images will have a fair number of colors (this is for pseudo-
        color displays), so I knew I needed to create my own colormap and
        set the values to those I need (< 256 colors).  I'll then be using
        XPutImage Calls to update the screen.  I'm not having any luck in
        doing this.  I'm using the following code.  This code is testing
        my colormaps by trying to set just 2 colors.  Once I get this right,
        I'll move on to what colors I really need.  This routine is called
        to finish initializing a DrawingArea widget by the expose event
        callback for the DrawingArea widget (first time only).  The wdg
        in the parameter list is that Drawing Area widget.


        When I use this, I get the same black and white, rather than the
        red and cyan I expect.

        any help much appreciated.

        thanks,

        mark



void
utox_finish(
        Widget    wdg )
{
        img_wdgt = wdg;
        img_wind = XtWindow( wdg );

        display  = XtDisplay( wdg );

        root     = DefaultRootWindow( display );
        screen   = DefaultScreen( display );
        visual   = DefaultVisual( display, screen );
        depth    = DefaultDepth( display, screen );
        gc       = DefaultGC( display, screen );

        if ( visual->class != PseudoColor && visual->class != TrueColor )
        {
                fprintf( stderr, "\nOnly PseudoColor and TrueColor displays sup`
                exit( 0 );
        }

        if ( visual->class == PseudoColor )
        {
                XColor    colors[ 256 ];

                cmap = XCreateColormap( display, img_wind, visual, AllocAll );

                colors[ 0 ].pixel = 0;
                colors[ 0 ].flags = ( DoRed | DoGreen | DoBlue );
                colors[ 0 ].red   = 0xffff;
                colors[ 0 ].green = 0x0000;
                colors[ 0 ].blue  = 0x0000;

                colors[ 1 ].pixel = 1;
                colors[ 1 ].flags = ( DoRed | DoGreen | DoBlue );
                colors[ 1 ].red   = 0x0000;
                colors[ 1 ].green = 0xffff;

                XSetWindowColormap( display, img_wind, cmap );

                XStoreColors( display, cmap, colors, 2 );

                pixmap = XCreatePixmapFromBitmapData( display, img_wind,
                        utox2_xbm_bits, utox2_xbm_width, utox2_xbm_height,
                        0, 1, depth );

                XCopyArea( display, pixmap, img_wind, gc,
                        0, 0, utox2_xbm_width, utox2_xbm_height, 0, 0 );
        }
        else
        {
                /* Not Done Yet */
        }

        return;
}