6755 |
unsigned hash = CT_HASH_RGB (r, g, b); |
unsigned hash = CT_HASH_RGB (r, g, b); |
6756 |
int i = hash % CT_SIZE; |
int i = hash % CT_SIZE; |
6757 |
struct ct_color *p; |
struct ct_color *p; |
6758 |
Visual *visual; |
struct x_display_info *dpyinfo; |
6759 |
|
|
6760 |
/* Handle TrueColor visuals specially, which improves performance by |
/* Handle TrueColor visuals specially, which improves performance by |
6761 |
two orders of magnitude. Freeing colors on TrueColor visuals is |
two orders of magnitude. Freeing colors on TrueColor visuals is |
6762 |
a nop, and pixel colors specify RGB values directly. See also |
a nop, and pixel colors specify RGB values directly. See also |
6763 |
the Xlib spec, chapter 3.1. */ |
the Xlib spec, chapter 3.1. */ |
6764 |
visual = FRAME_X_DISPLAY_INFO (f)->visual; |
dpyinfo = FRAME_X_DISPLAY_INFO (f); |
6765 |
if (visual->class == TrueColor) |
if (dpyinfo->red_bits > 0) |
6766 |
{ |
{ |
|
int bits = visual->bits_per_rgb; |
|
6767 |
unsigned long pr, pg, pb; |
unsigned long pr, pg, pb; |
6768 |
|
|
6769 |
/* Apply gamma-correction like normal color allocation does. */ |
/* Apply gamma-correction like normal color allocation does. */ |
6778 |
/* Scale down RGB values to the visual's bits per RGB, and shift |
/* Scale down RGB values to the visual's bits per RGB, and shift |
6779 |
them to the right position in the pixel color. Note that the |
them to the right position in the pixel color. Note that the |
6780 |
original RGB values are 16-bit values, as usual in X. */ |
original RGB values are 16-bit values, as usual in X. */ |
6781 |
pr = (r >> (16 - bits)) << 2 * bits; |
pr = (r >> (16 - dpyinfo->red_bits)) << dpyinfo->red_offset; |
6782 |
pg = (g >> (16 - bits)) << 1 * bits; |
pg = (g >> (16 - dpyinfo->green_bits)) << dpyinfo->green_offset; |
6783 |
pb = (b >> (16 - bits)) << 0 * bits; |
pb = (b >> (16 - dpyinfo->blue_bits)) << dpyinfo->blue_offset; |
|
|
|
|
/* Apply RGB masks of the visual. */ |
|
|
pr &= visual->red_mask; |
|
|
pg &= visual->green_mask; |
|
|
pb &= visual->blue_mask; |
|
6784 |
|
|
6785 |
/* Assemble the pixel color. */ |
/* Assemble the pixel color. */ |
6786 |
return pr | pg | pb; |
return pr | pg | pb; |