[cairo] 8 bit pseudo color missing.
spitzak at d2.com
Wed Mar 22 15:14:33 PST 2006
I'm certain the only way Cairo is going to work and produce the correct
picture is to keep a local full-color buffer and then draw the resulting
dirty area onto the output device. I think error diffusion is
preferrable over patterned dither. Patterned dither is used by Windows
and looks really bad, while error diffusion I have found looks quite
reasonable, even for line graphics.
A technique I have used that works pretty well is the following. It
works on Pseudo color visuals with as few as 4 bits and produce a
visible picture. It is also good for fixed-color displays with 8 bits
or less such as the 3/4 bit VGA displays or even monochrome ones.
1. Invent your own color cube with < 256 colors. Ideally this should be
a cube that is used by other programs, such as the Netscape cube. This
maximizes the chances the cube will allocate exactly. Use less than 256
colors so that you will not allocate all the colors on an 8-bit display.
2. Make a table the size of this cube, with space for color index and
for an actual rgb color.
3. Allocate every one of the cube colors from the colormap. Cycle
through it in some pattern so that widely-seperated colors are allocated
first (I just cycle through with a relatively prime constant increment).
Put the resulting index, and the resulting color (masked to the
abilities of the device) into the table. Eventually the allocation will
fail (either because the colormap is full or because this is a TrueColor
4. For all remaining colors, search the entire colormap from the device
(including the ones you allocated) to find the closest color, and put
this closest color and index into the table. Notice that several table
entries may get the same index.
5. The dithering algorithim dithers to the desired color cube, as though
you really had it. It then draws the color index from the table. But the
*error* for the neighboring pixels is calculated from the difference
between the source color and the color in the table, which may be
different than the color the cube should have.
More information about the cairo