Mercurial > emacs
changeset 52387:2415f47f227a
Fix pixel calculation for TrueVisuals.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Sat, 30 Aug 2003 17:44:40 +0000 |
parents | e2a889e11ec6 |
children | b851ebbed6d8 |
files | src/ChangeLog src/xfns.c src/xterm.c src/xterm.h |
diffstat | 4 files changed, 64 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Sat Aug 30 10:58:15 2003 +0000 +++ b/src/ChangeLog Sat Aug 30 17:44:40 2003 +0000 @@ -1,3 +1,13 @@ +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
--- a/src/xfns.c Sat Aug 30 10:58:15 2003 +0000 +++ b/src/xfns.c Sat Aug 30 17:44:40 2003 +0000 @@ -6755,16 +6755,15 @@ 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) - { - int bits = visual->bits_per_rgb; + dpyinfo = FRAME_X_DISPLAY_INFO (f); + if (dpyinfo->red_bits > 0) + { unsigned long pr, pg, pb; /* Apply gamma-correction like normal color allocation does. */ @@ -6779,14 +6778,9 @@ /* 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;
--- a/src/xterm.c Sat Aug 30 10:58:15 2003 +0000 +++ b/src/xterm.c Sat Aug 30 17:44:40 2003 +0000 @@ -10120,6 +10120,34 @@ } #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 @@ 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)) {
--- a/src/xterm.h Sat Aug 30 10:58:15 2003 +0000 +++ b/src/xterm.h Sat Aug 30 17:44:40 2003 +0000 @@ -360,6 +360,11 @@ 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