From: Jan Djärv Date: Sat, 30 Aug 2003 17:44:40 +0000 (+0000) Subject: Fix pixel calculation for TrueVisuals. X-Git-Tag: ttn-vms-21-2-B4~8943 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9d35adc75f3a64f909530381c257f68439712ca1;p=emacs.git Fix pixel calculation for TrueVisuals. --- diff --git a/src/ChangeLog b/src/ChangeLog index bd89e6d25b9..c8944754767 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2003-08-30 Jan Dj,Ad(Brv + + * 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 * xdisp.c (redisplay_internal): Fix change of 2003-04-30. Don't diff --git a/src/xfns.c b/src/xfns.c index 0a87cc5950e..dbc01dffa86 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -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; diff --git a/src/xterm.c b/src/xterm.c index 60bd3cc375c..bf80b9044cd 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -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)) { diff --git a/src/xterm.h b/src/xterm.h index 03c0dc32acc..4b598f48098 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -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