Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!tikal!ole!august From: august@ole.UUCP (Augustine Chan) Newsgroups: comp.windows.x Subject: Re: color map question Message-ID: <460@ole.UUCP> Date: 15 Jun 88 18:44:15 GMT References: <8806091630.AA02763@velveeta> Reply-To: august@ole.UUCP (Augustine Chan) Organization: Seattle Silicon Corporation, Bellevue, WA. Lines: 104 In article <8806091630.AA02763@velveeta> rusty@cartan.berkeley.edu writes: >How does one go about printing out the "default" color map? I'm on a >sun 3/60 (cgfour) running x11r2. My code looks something like > > dpy = XOpenDisplay(NULL)); > scr = DefaultScreen(dpy); > scrn = XScreenOfDisplay(dpy, scr); > nplanes = XDefaultDepth(dpy, scr); > ncells = XCellsOfScreen(scrn); > > XAllocColorCells(dpy, XDefaultColormap(dpy, scr), 0, plane_masks, > nplanes, cmap_cells, ncells); > > for (i = 0; i < nplanes; i++) > printf("plane_masks[%d] = 0x%x\n", i, plane_masks[i]); > for (i = 0; i < ncells; i++) > printf("cmap_cells[%d] = 0x%x\n", i, cmap_cells[i]); > >If I run my program after starting up the server all I get is 0's. > >The cgfour has a 256 cell color map and I just want to display a 16 by >16 grid with each color of the color map in a square. > >Is there a good book that explains the concepts, principals, etc. of >color maps? There is a bit of misunderstanding here. Your XAllocColorCells() tries to allocate so-far unused slots in your Default Colormap. This routine will fail if all the slots in the default colormap is already in use. When the call fails, you'll get all 0's in the plane masks and the cells. Such is the case with, e.g., the Apollo DN3000 which has only 4 bit planes, and all 16 available slots are probably tied up the window manager. Your cgfour with 256 color cells should have room to spare unless your window manager + other X-things running have tied up all 256 slots. If successful the newly allocated cells are now at your disposal. You may use XStoreColor() or XStoreColors() to put your own rgb specifications into the slots. You have to keep track of which color goes into which slot (pixel value) for later use, e.g., in calls to XSetForeground. If the Default colormap is full and XAllocColorCells() fails, you can always Create your own color map, allocate cells in it and store your own colors in the cells. Once installed with XInstallColormap(), this new map will apply to the entire display and therefore will mess up the colors of everything except the window it is intended for. There is actually supposed to be another solution to your problem, without having to store your own colors, but the color you obtain will be only an approximation, the closest match in the standard map to your rgb specification. There is this function XGetStandardColormap() which supposedly fills a XStandardColormap structure, which has all the information needed for computing the pixel value of any rgb for the standard colormap. However I have not yet been able to get this function to return SUCCESS. The XGetStandardColormap() call in the program below returns a FAILURE status on an APollo DN3000 and a Sun/260. I would appreciate it if anyone out there could point out what we are doing wrong. /* ----------------------------- cut here -------------------------- */ #include #include #include #include int main() { Display *dpy; Window win; int scrn; int planes; XStandardColormap sc_map; if ((dpy = XOpenDisplay (NULL)) == NULL) { fprintf (stderr, "Could not connect to default X display.\n"); XCloseDisplay(dpy); exit (1); } scrn = XDefaultScreen(dpy); planes = XDisplayPlanes(dpy, scrn); printf("no of planes: %d\n", planes); win = XDefaultRootWindow(dpy); if (XGetStandardColormap(dpy, win, &sc_map, XA_RGB_COLOR_MAP) == 0) fprintf(stderr, "cannot obtain standard colormap\n"); else fprintf(stderr, "standard colormap obtained\n"); XCloseDisplay(dpy); } /* -------------------------- cut here ------------------------------- */ Augustine Chan Seattle Silicon Corp. Bellevue, Wash