[mot.cad] XParseColor

razdan@oakhill.UUCP (Anshuman Razdan) (12/07/89)


I am trying to install a private colormap for my application. I am following
the procedure listed below :

1.      Open the display and initialize the toolkit

2.      Get display (mxdisplay).

3.      Allocate 16(thats howmany colors I can have on a  4 plane system) c
        lor cells and initialize their flagsd to DoRed|DoGreen|DoBlue.

4.      Since all the 16 colors I want (stored in char array colornames) are
        in the default rgb.txt, I next used XParseColor to get the RGB values
        XError:  BadMatch, invalid parameter attributes
        Request Major Code 78 ()
	Request Minor Code 
	ResourceID 0x800000
	Error Serial #6
	Current Serial #23

I am including the sorce code here for perusal of XGuru's

#include <stdio.h>

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>

Display *mxdisplay;

static int colorflag = MFALSE;

static char *colornames[] = {   "black",
                                "dark olive green",
                                "lime green",
                                "green yellow",
                                "cornflower blue",
                                "blue violet",
                      } ;

main(argc,argv )

int argc;
char *argv[];


extern MXcreateAndInstallCmap();

extern char *MPpaste();
extern char *getenv();
char *home;
char *mpostrc;

        mxdisplay = XOpenDisplay(NULL);



/* see what happens */



XColor cells[16], *exact;
int ncolors, i;
int scrn = DefaultScreen(mxdisplay);
Colormap defcmap = XDefaultColormap(mxdisplay,scrn);
Visual *visual;
        visual = DefaultVisual(mxdisplay,scrn);

        ncolors = DisplayCells(mxdisplay,scrn);

        cmap = XCreateColormap(mxdisplay,RootWindow(mxdisplay,scrn),visual,AllocAll);

        for(i = 0; i < 16; i++){  /* 16 to ncolors */
                cells[i].flags = DoRed | DoGreen | DoBlue;
                cells[i].pixel = i;
        } /* for */

        XStoreColors(mxdisplay,cmap,&cells[0],16); /* 16 to ncolors */

} /* End of install Color map */

If the above is succesfull( given I am doing something wrong some where)
I want to access the colors by their pixels i.e. if I want to find pixel value
of "blue" I call the following routine :


/**     Routine : MXgetColor
        Function:Using installed or default color map of the system it converts a string
                to pixel from the default colormap. It gets the color map
                just once at time of initialiasing the application      **/


Pixel MXgetColor(name)

char *name;


static Colormap defcmap;
XColor *scdef, *exactdef;
Pixel pixel;
int cells;
char *colorname;

        if(cmap == NULL && !colorflag){
                defcmap = XDefaultColormap(mxdisplay, DefaultScreen(mxdisplay));
                cells = XDisplayCells(mxdisplay,XDefaultScreen(mxdisplay));
                colorflag = MTRUE;
        } /* if */

        else defcmap = cmap;

        scdef = NULL;exactdef = NULL;
        scdef = (XColor *)XtMalloc(sizeof(XColor));
        exactdef = (XColor *)XtMalloc(sizeof(XColor));
	if(XAllocNamedColor(mxdisplay,defcmap,name,scdef,exactdef) == 0)

	 pixel = exactdef->pixel;
        XtFree(scdef); XtFree(exactdef);
} /* End fo MXgetColor */


What am I doing wrong ?? or better Is ther a better way to approach this problem ?

Thanx in advance
Pl. e-mail or post any solutions.

Anshuman Razdan

Sector CAD
Motorola Austin Tx.