[cairo] Redoing the xlib surface constructors

Bill Spitzak spitzak at d2.com
Mon Mar 14 21:11:07 PST 2005


Owen Taylor wrote:

>>The problem is that the cube must be shared among all applications or it 
>>has little value.
>
> The way it worked years ago was basically a system where the first
> app allocated a big colorcube, and subsequent apps hopefully were
> smart enough to recognize it and reuse it. (This worked pretty
> well, when the world was netscape and the GIMP, plus an xterm)

A scheme I used that worked very well, and shared the colormap was:

It always used the default colormap.

A hard-coded color cube was designed that only used about half of it (we 
used a 5x8x5 plus a 32-entry gray ramp for compatability with Irix, but 
other more modern designs would be better).

The program would then try to allocate every color in the cube, in an 
order so that widely-seperated ones are allocated first. If the 
allocation fails, the colormap is read, and a least-squared-distance 
search is done to find the closest color to use (to speed it up it 
assummes that once one fails they all will fail). A table is built, 
indexed by our color cube, in it is the colormap index and the actual 
color in that location (either the correct color, or the closest one found).

Simple error diffusion is used to convert an rgb image to color cube 
entries. For each pixel the closest location in our color cube is 
picked, and then that location from the table is used. The difference 
between the rgb color wanted and the entry from the table is then added 
to the next pixel to the right before conversion. To hide patterns a 
random start point is chosen for each row in the image and the 
algorithim goes both directions away from that to the ends.

This cooperated with Netscape's color cube without forcing us to use the 
same cube. It was also pretty fast (because our color cube is hard-coded 
and thus the rgb->cube transformation was hard-coded). The error 
diffusion produced much nicer images than pattern dithering, and did not 
require the "origin" to be set to make the patterns line up.

In addition we only supported 8-bit colormaps. This allowed the code to 
work with bytes. I have never seen a display with more than 8 bit 
colormaps that did not also support TrueColor.



More information about the cairo mailing list