summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Djärv <jan.h.d@swipnet.se>2003-08-30 17:44:40 +0000
committerJan Djärv <jan.h.d@swipnet.se>2003-08-30 17:44:40 +0000
commita9ba16fe5168004c87e0268208ab435f865c9009 (patch)
tree700792eec8db158b87656ec934eedd2ec490ef61
parentd168a83fd820a15b858489be0039363b252df68d (diff)
downloademacs-a9ba16fe5168004c87e0268208ab435f865c9009.tar.gz
Fix pixel calculation for TrueVisuals.
-rw-r--r--src/ChangeLog10
-rw-r--r--src/xfns.c18
-rw-r--r--src/xterm.c42
-rw-r--r--src/xterm.h5
4 files changed, 63 insertions, 12 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 3e7763e126b..96ede0f4adb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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
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