cei@ipvvis.unipv.it (Ugo Cei) (06/12/91)
I would like to thank all the respondents to my original query and to acknowledge their contributions with a summary of the responses I have received via e-mail. However, since I have had only partial success in using standard colormaps, I am posing some more questions to the net that I have just sent in a message to Adrian Nye, an excerpt of which I am appending to the end of this posting. Thank you everybody, Ugo ...................................................................... From: hill@luke.Lanl.GOV (Jeff Hill) To avoid flashing (when the mouse moves betweeen client windows) we allocate all of our colors in the default color map. This works well unless you need quite a few colors out of the available 256. We have implemented our own color map abstraction to do this. Jeff ...................................................................... From: Chris Kent <kent@parc.xerox.com> Besides, my application is ready to create the requested colormap if it does not exist, but it is unable to locate the XA_RGB_GRAY_MAP property via XGetRGBColormaps. The fact that your application can't find the property implies that the StdColormap doesn't exist. Create it, and set the property to point to it. See the R4 sample client xstdcmap. -- Chris Kent Xerox PARC CSL Palo Alto, CA USA kent@arisia.xerox.com xerox!kent +1.415.494.4821 ...................................................................... From: George Ross <gdmr@lfcs.ed.ac.uk> You did remember to run xstdcmap to install the thing first? The standard colormaps aren't installed by default; you have to do it explicitly. -- George D M Ross, Department of Computer Science, University of Edinburgh Kings Buildings, Mayfield Road, Edinburgh, Scotland, EH9 3JZ Tel: 031-650 5147 Internet: gdmr@cs.ed.ac.uk JANET: gdmr@uk.ac.ed.cs ...................................................................... From: stevev@theopolis.orl.mmc.com (steve venable) Ugo, I am doing much the same as you (with roughly the same environment). That is imaging applications using 8-bit gray scale images. Actually I have 8-bit images in which I also want some color, for highlighting and such, so I actually use some of the color slots for color and don't use all 256 values for the gray scale image. My solution has been to use my own colormap, forget the "default RGB maps". I really have not attempted to use them, but then as stated since I want gray scale and color, a standard gray map is not really what I want. What follows is my color allocation and initial load routine. Hope it is of use... It uses the global "xdisplay" which should be the (Display *) for the X server. It also uses a few C macros and symbols which I think you can figure out easily enough. ----------------------------------- BEGIN ----------------------------------- /*--------------------------------------------------------------------------- Setup the color table to be used. Modify the entries here if you wish different colors. Due to problems with XView and color tables (CMS), we drop down to the X level which seems to work find. Here are the current values loaded by this routine. The first 16 values are obtained from the "default" color map so that other windows don't go pseudo-color. 0 .. 15 reserved for window manager usage 16 .. 31 specialized colors (black initially) 32 .. 255 gray scale (224 shades) S.F. Venable 19-Apr-1991 14:00 ---------------------------------------------------------------------------*/ #include <appropriate stuff> #define PIXEL_RANGE (255 - 32 + 1) Colormap ColorSetup(void) { IXDEFunction(ColorSetup); Colormap colormap; unsigned long pixvals[256]; int base; bool gotem = False; /* We start with the default colormap for the screen */ colormap = DefaultColormap(xdisplay,DefaultScreen(xdisplay)); for (base = 2; base < 16; ++base) { if (XAllocColorCells(xdisplay,colormap,True,NULL,0,pixvals,256-base)) { if (pixvals[0] != base) /* Got somme but above 16? */ { XFreeColors(xdisplay,colormap,pixvals,256-base,0); break; /* Didn't really get the ones we need */ } else if (pixvals[0] < 16) /* If first is earlier than needed... */ XFreeColors(xdisplay,colormap,pixvals,16-base,0); gotem = True; break; } } /* If didn't get 'em, need our own colormap */ if (!gotem) { /* Get the values for slots 0 .. 15 */ int n; XColor rgb[16]; for (n=0; n<16; ++n) rgb[n].pixel = n; XQueryColors(xdisplay,colormap,rgb,16); /* Need a new colormap and allocate all cells */ { Visual *vis = DefaultVisual(xdisplay,DefaultScreen(xdisplay)); colormap = XCreateColormap(xdisplay, RootWindow(xdisplay,DefaultScreen(xdisplay)), vis, AllocAll); if (!colormap) { (IXERRMSG,"failed in allocating new colormap for display"); return (Colormap) 0; } } XStoreColors(xdisplay,colormap,rgb,16); /* Fill the first 16 slots */ } /* Load our initial gray scale range and color range */ { int n; XColor rgb[PIXEL_RANGE+16]; for (n = 0; n < PIXEL_RANGE; ++n) { unsigned short intensity = (unsigned short) ((double)(n) * 256.0 / (double)PIXEL_RANGE); rgb[n].pixel = n + 32; rgb[n].flags = DoRed | DoGreen | DoBlue; rgb[n].red = rgb[n].green = rgb[n].blue = intensity << 8; } for (n = PIXEL_RANGE; n < PIXEL_RANGE+16; ++n) { rgb[n].pixel = n - PIXEL_RANGE + 16; rgb[n].flags = DoRed | DoGreen | DoBlue; rgb[n].red = rgb[n].green = rgb[n].blue = 0; } XStoreColors(xdisplay,colormap,rgb,PIXEL_RANGE+16); } return colormap; } ---------------------------------- END -------------------------------------- -- ___ Steven F. Venable / _____ Martin Marietta Orlando \___ | ___\ / ___ Voice: [407] 356-3927 or -6958 \ | |__ \ / |__ Email: stevev@iplmail.orl.mmc.com \___/ | |___ \/ |___ (soon steve-venable@mail.orl.mmc.com) ...................................................................... From: adrian@spike.ora.com (adrian) I posted a response to your posting, but it probably won't help much. Standard colormaps are only just beginning to be used and few people know much about them. I personally think your problem is due to xstdcmap failing, not your program (or my example). ...................................................................... From cei Wed Jun 12 12:49:46 1991 Subject: Re: standard colormaps To: adrian@spike.ora.com (adrian) Dear Adrian (Mr. Nye, I suppose), thank you for your answer. I eventually managed to get some work done with standard colormaps. It seems that I need to make xstdcmap work (which I succeeded in) and to get the standard colormap from the root window and not from my application's toplevel or other window. Having done that, I wanted to assign different colormaps to different subwindows of my applications and have the window manager swap these in and out when the pointer is in the subwindow. This would have a terrible visual effect on a machine with only one hardware colormap but I am prepared to pay the price. I tried this method: XSetWindowColormap(dpy, w, cmap->colormap); XSetWMColormapWindows(dpy, toplevel, & w, 1); In this case I have only one subwindow (w), to simplify things. cmap is the "XStandardColormap *" that is set by the call to XGetRGBColormaps. This method has no effect and my subwindow always uses the colormap of the toplevel one (i.e. the default colormap). The window manager does not change it. However, if I only set the colormap of the toplevel window: XSetWindowColormap(dpy, toplevel, cmap->colormap); the window manager can swap it in and out when the pointer moves from this application's toplevel to another application's windows. This does no good to me, since I would like to have a different colormap for every one of a set of subwindows in my application. Is there any way to get this behaviour from the wm ? Besides, everytime the colormap is swapped in or out, the wm (twm) complains that my "client illegally changed colormap". ...................................................................... -- Ugo Cei - Dipartimento Informatica e Sistemistica Via Abbiategrasso 209 - 27100 Pavia - ITALY +39 382 391.372 Internet: cei@ipvvis.unipv.it