Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!mailrus!ncar!karl!davis From: davis@karl.ucar.edu (Glenn P. Davis) Newsgroups: comp.windows.x Subject: Setting up color tables for an image. Keywords: XInstallColormap Message-ID: <4743@ncar.ucar.edu> Date: 17 Oct 89 20:36:16 GMT Sender: news@ncar.ucar.edu Reply-To: davis@karl.UCAR.EDU (Glenn P. Davis) Organization: Unidata/UCAR, Boulder CO Lines: 100 References: I'm experimenting with a very simple X client to render color images. I'm using the R3 Athena widgets only. I have looked at 'xim' and NCSA 'ximage' as examples and use the folowing sequence of calls: Widget box ; /* boxWidget class */ Display *dpy ; GC gc ; XGCValues gcvalues ; Visual *vis ; XImage *cimage ; dpy = XtDisplay(box3) ; vis = GetVisual(dpy) ; cimage = XCreateImage(dpy,vis,8,ZPixmap,0,ap->image, ap->dir->esiz, ap->dir->lsiz, 8, ap->dir->esiz); /* XInstallColormap(dpy,cmap); */ gc = XtGetGC(box3, NULL, &gcvalues) ; XPutImage( dpy, XtWindow(box3), gc, cimage, 0,0,0,0, ap->dir->esiz, ap->dir->lsiz) ; ('ap' is the input image structure I have to work with. ) This works and I get the image in the box. My questions has to do with the color mapping. The input images are 8 bit greyscale. What is the correct sequence of calls to create and install the new colormap? Actually I have two cases, one where there are 'nearly' 256 distinct grey levels - 8 bit sensor a second where there are more like 64 distinct grey levels - 6 bit sensor Actually, in both of these cases the top and bottom few grey values do not occur in the actual images. The sequence I have started with is Xcolor colors[256] ; int ncolors ; /* 64 or 256 */ /* set up color table */ for (ii=0; ii < ncolors; ii++) { colors[ii].pixel = (u_long)ii; colors[ii].red = colors[ii].green = colors[ii].blue = (u_short)(ii * 257 *(256/ncolors)) ; colors[ii].flags = DoRed | DoGreen | DoBlue; } . . . /* set up colormap */ { Display *dpy ; Visual *vis ; void SetColormap() ; dpy = XtDisplay(box3) ; vis = GetVisual(dpy) ; if ((vis->class != PseudoColor) && (vis->class != StaticColor)) { fprintf(stderr, "Can't use this display. Not a Pseudo Color device\n"); exit(-1) ; } if ( DisplayPlanes(dpy,XDefaultScreen(dpy)) != 8 ) { fprintf(stderr, "Can't use this display. Not an 8 bit display\n"); exit(-2) ; } cmap = XCreateColormap(dpy, XtWindow(box3), vis, AllocAll) ; XStoreColors(dpy, cmap, colors, ncolors) ; XInstallColormap(dpy,cmap); } I have also fooled around with not executing 'XInstallColormap' in the main line code, instead adding two event handler to 'box' for entering and leaving the box, Install and UnInstall the colormap. This latter system works when I'm not running any window manager. It doesn't with twm, even with ncolors = 64. I assume I'm not being 'a good client'. What should I be doing? For the case ncolors = 64, I would prefer to set things up so there is no 'flash', if possible. Thanks Glenn P. Davis UCAR / Unidata PO Box 3000 1685 38th St. Boulder, CO 80307-3000 Boulder, CO 80301 (303) 497 8643