Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!ncar!gatech!bloom-beacon!LARRY.MCRCIM.MCGILL.EDU!mouse From: mouse@LARRY.MCRCIM.MCGILL.EDU Newsgroups: comp.windows.x Subject: Re: Can XAllocColor/XAllocNamedColor fail ? Message-ID: <9011112253.AA20761@Larry.McRCIM.McGill.EDU> Date: 11 Nov 90 22:53:19 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 51 >> XAllocColor finds the closest color supported by the visual, not the >> closest color in the colormap. It will fail if the requested color >> is not in the colormap and the colormap is full. (That's true for GrayScale, PseudoColor, and DirectColor. The first half of the first sentence is true for all six visuals; the second sentence is vacuously true for the three static visuals. (But see my note [$] below.)) > This leads me to a problem Im having, in that what exactly is > closest, and what is the best way to allocate colors so that you get > approx. what your looking for, even if the color map is getting > "full" It might not be possible. If someone has nearly filled up the colormap with a grayscale ramp, so there are only two cells left, and you want red, green, and blue, there really isn't much you can do: you simply can't get anything that is even approximately what you're looking for without creating your own colormap. Allocating a color on any visual will always, as a first step, approximate the requested color as closely as possible for that visual. Taking the resulting approximation as "the requested color", then - If the requested color is present in a read-only cell of the colormap, that cell is returned[#]; - Otherwise, if there is a cell free[%], it is filled in with the requested color and returned; - Otherwise, an error is generated. Note that the first step will always succeed for a static visual, because the colormap always contains all the colors the visual supports. [%] For DirectColor, this may be[$] more complicated than "if there is a cell free", because there are three distinct mapping tables involved, one for each primary. I haven't looked at it in detail. [$] I am not certain XAllocColor works for decomposed visuals (DirectColor and TrueColor); I haven't checked in detail. [#] What happens if more than one read-only cell contains the color is not quite as clear, though some one of them should be returned. Due to the semantics of allocating colors, this can happen only when a server implementor provides a static visual with redundant cells in the colormap. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu