clive@x.co.uk (Clive Feather) (06/28/90)
In article <9006271450.AA21331@lance> jimf@SABER.COM writes: >Currently there is no way to allocate a shareable colormap cell only >if it already exists. [...] This function would fail if there was not >already a colormap cell with the given color value, even if there were free >colormap cells available. >I would also appreciate some way to convert read/write (private) >colormap cells to read-only (shareable) cells. This way an >application can allocate as many colors as it can, set them to values >which won't be changed, make them shareable, then other applications >can share those colors. You can do both of these, and lots of other colormap tricks, with a bit of effort (or develop a library to do it). For the first problem: - Grab the server. - Allocate writable all remaining cells in the colormap (a binary chop loop is a good way to do this). - XAllocColor the colour you want (this will fail if it isn't already in use). - XFreeColors all the cells you just allocated. - Ungrab the server. For the second problem: - Grab the server. - Allocate writable all remaining cells in the colormap (a binary chop loop is a good way to do this). - For each cell you want to allocate sharable (n.b. you can pick the pixel value *you* want from those just allocated): - XFreeColor the cell. - XAllocColor the colour you want (this will give you back the cell). - XFreeColors the remainder of the cells you just allocated. - Ungrab the server. This technique is obviously extensible to other tricks. -- Clive D.W. Feather | IXI Limited | If you lie to the compiler, clive@x.co.uk [x, not ixi] | 62-74 Burleigh St. | it will get its revenge. ...!uunet!ixi!clive | Cambridge CB1 1OJ | - Henry Spencer Phone: +44 223 462 131 | United Kingdom | [ These 28 bytes for rent ]