Commit 9d35adc7 authored by Jan Djärv's avatar Jan Djärv
Browse files

Fix pixel calculation for TrueVisuals.

parent d5947564
2003-08-30 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
* xterm.c (x_term_init): Initialize new fields in x_display_info.
* xterm.h (struct x_display_info): Add red/green/blue_bits and
*_offset.
* xfns.c (lookup_rgb_color): Use new fields in x_display_info to
calculate pixel value.
2003-08-29 Gerd Moellmann <gerd.moellmann@t-online.de>
* xdisp.c (redisplay_internal): Fix change of 2003-04-30. Don't
......
......@@ -6755,16 +6755,15 @@ lookup_rgb_color (f, r, g, b)
unsigned hash = CT_HASH_RGB (r, g, b);
int i = hash % CT_SIZE;
struct ct_color *p;
Visual *visual;
struct x_display_info *dpyinfo;
/* Handle TrueColor visuals specially, which improves performance by
two orders of magnitude. Freeing colors on TrueColor visuals is
a nop, and pixel colors specify RGB values directly. See also
the Xlib spec, chapter 3.1. */
visual = FRAME_X_DISPLAY_INFO (f)->visual;
if (visual->class == TrueColor)
dpyinfo = FRAME_X_DISPLAY_INFO (f);
if (dpyinfo->red_bits > 0)
{
int bits = visual->bits_per_rgb;
unsigned long pr, pg, pb;
/* Apply gamma-correction like normal color allocation does. */
......@@ -6779,14 +6778,9 @@ lookup_rgb_color (f, r, g, b)
/* Scale down RGB values to the visual's bits per RGB, and shift
them to the right position in the pixel color. Note that the
original RGB values are 16-bit values, as usual in X. */
pr = (r >> (16 - bits)) << 2 * bits;
pg = (g >> (16 - bits)) << 1 * bits;
pb = (b >> (16 - bits)) << 0 * bits;
/* Apply RGB masks of the visual. */
pr &= visual->red_mask;
pg &= visual->green_mask;
pb &= visual->blue_mask;
pr = (r >> (16 - dpyinfo->red_bits)) << dpyinfo->red_offset;
pg = (g >> (16 - dpyinfo->green_bits)) << dpyinfo->green_offset;
pb = (b >> (16 - dpyinfo->blue_bits)) << dpyinfo->blue_offset;
/* Assemble the pixel color. */
return pr | pg | pb;
......
......@@ -10120,6 +10120,34 @@ same_x_server (name1, name2)
}
#endif
/* Count number of set bits in mask and number of bits to shift to
get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
to 5. */
static void
get_bits_and_offset (mask, bits, offset)
unsigned long mask;
int *bits;
int *offset;
{
int nr = 0;
int off = 0;
while (!(mask & 1))
{
off++;
mask >>= 1;
}
while (mask & 1)
{
nr++;
mask >>= 1;
}
*offset = off;
*bits = nr;
}
struct x_display_info *
x_term_init (display_name, xrm_option, resource_name)
Lisp_Object display_name;
......@@ -10367,6 +10395,20 @@ x_term_init (display_name, xrm_option, resource_name)
dpyinfo->x_highlight_frame = 0;
dpyinfo->image_cache = make_image_cache ();
/* See if we can construct pixel values from RGB values. */
dpyinfo->red_bits = dpyinfo->blue_bits = dpyinfo->green_bits = 0;
dpyinfo->red_offset = dpyinfo->blue_offset = dpyinfo->green_offset = 0;
if (dpyinfo->visual->class == TrueColor)
{
get_bits_and_offset (dpyinfo->visual->red_mask,
&dpyinfo->red_bits, &dpyinfo->red_offset);
get_bits_and_offset (dpyinfo->visual->blue_mask,
&dpyinfo->blue_bits, &dpyinfo->blue_offset);
get_bits_and_offset (dpyinfo->visual->green_mask,
&dpyinfo->green_bits, &dpyinfo->green_offset);
}
/* See if a private colormap is requested. */
if (dpyinfo->visual == DefaultVisualOfScreen (dpyinfo->screen))
{
......
......@@ -360,6 +360,11 @@ struct x_display_info
use this directly, call x_color_cells instead. */
XColor *color_cells;
int ncolor_cells;
/* Bits and shifts to use to compose pixel values on Direct and TrueColor
visuals. */
int red_bits, blue_bits, green_bits;
int red_offset, blue_offset, green_offset;
};
#ifdef HAVE_X_I18N
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment