2000-11-06 Miles Bader * xterm.c (x_alloc_lighter_color): Boost FACTOR for dark colors. (Vhighlight_color_dark_boost, Vhighlight_color_dark_boost_limit): New variables. (syms_of_xterm): Initialize new variables. Include . diff -up src/xterm.c.\~1\~ src/xterm.c --- src/xterm.c.~1~ Tue Oct 31 09:44:48 2000 +++ src/xterm.c Tue Nov 7 12:39:08 2000 @@ -29,6 +29,7 @@ Boston, MA 02111-1307, USA. */ #include #include +#include #ifdef HAVE_X_WINDOWS @@ -383,6 +384,10 @@ extern XrmDatabase x_load_resources P_ ( extern Lisp_Object x_icon_type P_ ((struct frame *)); +/* Parameters used by x_alloc_lighter_color. */ +Lisp_Object Vhighlight_color_dark_boost, Vhighlight_color_dark_boost_limit; + + /* Enumeration for overriding/changing the face to use for drawing glyphs in x_draw_glyphs. */ @@ -3511,6 +3516,59 @@ x_alloc_lighter_color (f, display, cmap, color.pixel = *pixel; x_query_color (f, &color); + if (NUMBERP (Vhighlight_color_dark_boost)) + /* Boost FACTOR for dark colors. */ + { + long bright, limit; + + /* Use the maximum component brightness as the overall brightness + (this works quite well in practice). */ + bright = color.red; + if (color.green > bright) + bright = color.green; + if (color.blue > bright) + bright = color.blue; + + if (INTEGERP (Vhighlight_color_dark_boost_limit)) + { + limit = XINT (Vhighlight_color_dark_boost_limit); + if (limit > 0xFFFF) + /* Limit LIMIT to the maximum color component value. */ + limit = 0xFFFF; + } + else + limit = 48000; /* "grey" */ + + /* We only boost colors that are darker than + Vhighlight_color_dark_boost_limit. */ + if (bright > 0 && bright < limit) + { + double boost = XFLOATINT (Vhighlight_color_dark_boost); + + if (boost > 10) + /* We arbitrarily limit BOOST to 10 to avoid problems with + `pow' (as the default is 0.5, 10 is probably enough). */ + boost = 10; + + if (boost > 0) + { + /* How far below LIMIT this color is. */ + double dimness = (double)limit / bright; + /* How much to change FACTOR to account for BOOST at DIMNESS. */ + double adjust = + /* The default value of BOOST is 0.5, which can be + calculated about 3 times faster using `sqrt', so + optimize that case. */ + (boost == 0.5 ? sqrt (dimness) : pow (dimness, boost)); + + if (factor >= 1) + factor *= adjust; + else + factor /= adjust; + } + } + } + /* Change RGB values by specified FACTOR. Avoid overflow! */ xassert (factor >= 0); new.red = min (0xffff, factor * color.red); @@ -13887,7 +13945,35 @@ wide as that tab on the display."); staticpro (&last_mouse_motion_frame); last_mouse_motion_frame = Qnil; + + /* Initialize parameters used by x_alloc_lighter_color. */ + + DEFVAR_LISP ("highlight-color-dark-boost", + &Vhighlight_color_dark_boost, + "How much to boost the brightness of 3d highlights for dark colors.\n\ +Nominally, highlight colors for `3d' faces are calculated by brightening\n\ +an object's color by a constant factor. If `highlight-color-dark-boost'\n\ +is a floating point number between 0 and 1, colors darker than\n\ +`highlight-color-dark-boost-limit' have their highlight factor\n\ +increased: a value of 0 means no increase at all, and a value of 1\n\ +means that all dark colors will have a highlight with a brightness\n\ +equal to `highlight-color-dark-boost-limit'.\n\ +\n\ +Changing this value will not have an effect until a new frame is created."); + Vhighlight_color_dark_boost = make_float (0.5); + + DEFVAR_LISP ("highlight-color-dark-boost-limit", + &Vhighlight_color_dark_boost_limit, + "Brightness beyond which a color won't have its highlight brightness boosted.\n\ +See `highlight-color-dark-boost'.\n\ +\n\ +The `brightness' of a color, for this purpose, is defined to be the\n\ +maximum of the color's red, green, or blue components, as returned by\n\ +`color-values'."); + /* The default value here is set so that the default + menu-bar/mode-line color (grey75) will not have its highlights + changed at all. */ + Vhighlight_color_dark_boost_limit = 48000; } #endif /* not HAVE_X_WINDOWS */ -