Index:
[thread]
[date]
[subject]
[author]
From: WHS <wouters@cistron.nl>
To : ggi-develop@eskimo.com
Date: Fri, 14 Aug 1998 15:50:46 +0200
X colourmap code [X/Xlib target]
Steve Cheng wrote:
> Didn't somebody say that they have the code to this?
> This is to minimize color flashing in X.
>From my x11 frambuffer code:
0. /* get the deafult colour map (i.e. the shared one) */
colourmap = DefaultColormap(display, DefaultScreen(display));
1. /* Create X window with AllocAll */
if (Bpp==1) {
private_cmap = XCreateColormap(display, main_win,
DefaultVisual(display, XDefaultScreen(display)), AllocAll);
}
2. /* Fill the colourmap with the original colours */
for (i=0; i<NUM_COLOURS; i++) {
Free_cell(i); /* sets the private entry to the default one! */
palette_trans[i]=i; /* no translation */
}
NUM_COLOURS=256, but could be 4096 for SGI modes (12 bit)
3. if (Bpp==1)
XSetWindowColormap(display, main_win, private_cmap);
That initializes, now some functions:
-------------------------------------
/* Free allocated cell and restore to colour in original colour map */
int X11_framebuf:: Free_cell(byte cell) {
XColor colour_cell;
if (Bpp==1) {
colour_cell.pixel=cell;
colour_cell.flags=DoRed | DoGreen | DoBlue;
XQueryColor(display, colourmap, &colour_cell);
pixel_val[cell]=cell;
pixel_colours[cell]=(((colour_cell.red>>8)&255)<<16) |
(((colour_cell.green>>8)&255)<<8) | ((colour_cell.blue>>8)&255);
XStoreColor(display, private_cmap, &colour_cell);
}
private_cmap_used[cell]=0;
return 0;
}
/* Allocate colour cell in private colour map */
int X11_framebuf:: Alloc_cell(byte cell, byte r, byte g, byte b) {
XColor colour_cell;
if (Bpp==1) {
colour_cell.pixel=cell;
colour_cell.flags=DoRed | DoGreen | DoBlue;
colour_cell.red=((short)r)<<8;
colour_cell.green=((short)g)<<8;
colour_cell.blue=((short)b)<<8;
XStoreColor(display, private_cmap, &colour_cell);
pixel_val[cell]=cell;
}
else
pixel_val[cell]=((((int) r)>>red_mask_bits_compl) <<red_shift) |
((((int) g)>>green_mask_bits_compl) <<green_shift) |
((((int) b)>>blue_mask_bits_compl) <<blue_shift);
pixel_colours[cell]=(((int)r)<<16 ) | (((int)g)<<8 ) | (int)b;
//15+ bpp
palette_changed_bits[ cell >>5] |= 1<< (cell &31);
palette_changed=True;
private_cmap_used[cell]=1;
return pixel_val[cell];
}
---------------------
Now what you want to do is allocate from 255 down, as X allocates
colours from 0 up.
There are other improvements possible analysing the colourmap (to work
round a few isolated used entries in the upper range, e.g. as happens
when lots of programs have started, then most are stopped again).
Wouter
Index:
[thread]
[date]
[subject]
[author]