mamou@bdblues.altair.fr (Jean Claude Mamou) (03/13/91)
Hello, I have a problem to allocate read/write colorcells in a colormap. If I create a new virtual colormap with XCopyColrormapAndFree after a failure of XAllocColorCells, one of the extra allocation requests returns a bad pixel value (e.g. 256) that is out of range of the colormap. I give below an example of code producing that problem. Does someone know about that, and is it a known way of doing such a thing ? Thanks. ----------------------------------------------------------------------------- Jean-Claude Mamou | tel : +33 (1) 39.63.58.20 GIP ALTAIR | fax : +33 (1) 39.63.58.90 Domaine de Voluceau | email : mamou@bdblues.altair.fr BP 105, 78153 Le Chesnay Cedex, FRANCE | ----------------------------------------------------------------------------- #include <X11/Xlib.h> #include <X11/X.h> #include <stdio.h> main (argc,argv) int argc; char *argv[]; { int i,j,numcols, alloccols,theScreen; Colormap cmap, theCmap,LocalCmap; XColor defs[256]; char * display; Display *theDisp; unsigned char r[256],g[256],b[256]; display = NULL; LocalCmap =0; if ((theDisp = XOpenDisplay(display)) == NULL) { printf(stderr, "%s: Can't open display\n",argv[0]); exit(1);} theScreen = DefaultScreen(theDisp); theCmap = DefaultColormap(theDisp, theScreen); cmap = theCmap; XSynchronize(theDisp, True); /* Allocate one pixel */ defs[0].pixel = 2; XAllocColor(theDisp, cmap, &defs[0]); alloccols = 0; numcols = 256; for (i=0; i<numcols; i++) { unsigned long pmr[1], pix[1]; if (XAllocColorCells(theDisp, cmap, False, pmr, 0, pix, 1)) { printf("%d%s%d\n",i, " : XAllocColorcells returns pix = ", pix[0]); defs[i].pixel = pix[0]; defs[i].red = r[i]<<8; defs[i].green = g[i]<<8; defs[i].blue = b[i]<<8; defs[i].flags = DoRed | DoGreen | DoBlue; alloccols++; } else if (!LocalCmap) { printf("%s%d\n","Creation of a new colormap for i = ", i); LocalCmap = XCopyColormapAndFree(theDisp,theCmap); cmap = LocalCmap; i--; } else printf("%s\n", "Color non allocated"); } printf("%s%d\n","Allocated colors = ", alloccols); fflush(stdout); for (i=0; i<alloccols; i++) XStoreColor(theDisp, cmap, &defs[i]); }
rws@expo.lcs.mit.EDU (Bob Scheifler) (03/14/91)
If I create a new virtual colormap with XCopyColrormapAndFree after a failure of XAllocColorCells, one of the extra allocation requests returns a bad pixel value (e.g. 256) that is out of range of the colormap. You've found a nice server bug.
mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (03/15/91)
> I have a problem to allocate read/write colorcells in a colormap. If > I create a new virtual colormap with XCopyColrormapAndFree after a > failure of XAllocColorCells, one of the extra allocation requests > returns a bad pixel value (e.g. 256) that is out of range of the > colormap. > /* Allocate one pixel */ > defs[0].pixel = 2; > XAllocColor(theDisp, cmap, &defs[0]); This does not necessarily allocate a cell in the colormap. (If your point is just to make sure at least one cell is allocated, it will work.) XAllocColor ignores the pixel field of the structure passed in; it fills that value in with the colormap index of the cell allocated for the given RGB values on return. What makes you think 256 is out of range? If you got 256 from the "size of colormap" field printed by xdpyinfo, or the analogous thing from Xlib calls, I would say this is a server bug...whose server are you using, on what machine? der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu