aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-06-13 09:08:46 -0700
committerPaul Eggert2011-06-13 09:08:46 -0700
commita690a978ec42934c3f9d29c15cddd0240ab7a009 (patch)
tree6c35fc712c161a2f8816a3e7852bc6b1f787baf9 /src
parent01103c441a5c97c734c087fa074a941082fd0adb (diff)
downloademacs-a690a978ec42934c3f9d29c15cddd0240ab7a009.tar.gz
emacs-a690a978ec42934c3f9d29c15cddd0240ab7a009.zip
* xterm.c (x_alloc_nearest_color_1): Go back to original algorithm.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/xterm.c8
2 files changed, 5 insertions, 7 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 6bac6f00a3f..43e1f9dbc06 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,8 +1,6 @@
12011-06-13 Paul Eggert <eggert@cs.ucla.edu> 12011-06-13 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * xterm.c (x_alloc_nearest_color_1): Use a more-precise algorithm 3 * xterm.c (x_alloc_nearest_color_1): Prefer int to long when int works.
4 for nearest color, one that neither overflows nor relies on unsigned
5 arithmetic.
6 4
7 Remove unnecessary casts. 5 Remove unnecessary casts.
8 * xterm.c (x_term_init): 6 * xterm.c (x_term_init):
diff --git a/src/xterm.c b/src/xterm.c
index 914cdc429d6..f40d260dabe 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1697,7 +1697,7 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
1697 a least-squares matching, which is what X uses for closest 1697 a least-squares matching, which is what X uses for closest
1698 color matching with StaticColor visuals. */ 1698 color matching with StaticColor visuals. */
1699 int nearest, i; 1699 int nearest, i;
1700 int max_color_delta = (1 << (16 - 2)) - 1; 1700 int max_color_delta = 255;
1701 int max_delta = 3 * max_color_delta; 1701 int max_delta = 3 * max_color_delta;
1702 int nearest_delta = max_delta + 1; 1702 int nearest_delta = max_delta + 1;
1703 int ncells; 1703 int ncells;
@@ -1705,9 +1705,9 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
1705 1705
1706 for (nearest = i = 0; i < ncells; ++i) 1706 for (nearest = i = 0; i < ncells; ++i)
1707 { 1707 {
1708 int dred = (color->red >> 2) - (cells[i].red >> 2); 1708 int dred = (color->red >> 8) - (cells[i].red >> 8);
1709 int dgreen = (color->green >> 2) - (cells[i].green >> 2); 1709 int dgreen = (color->green >> 8) - (cells[i].green >> 8);
1710 int dblue = (color->blue >> 2) - (cells[i].blue >> 2); 1710 int dblue = (color->blue >> 8) - (cells[i].blue >> 8);
1711 int delta = dred * dred + dgreen * dgreen + dblue * dblue; 1711 int delta = dred * dred + dgreen * dgreen + dblue * dblue;
1712 1712
1713 if (delta < nearest_delta) 1713 if (delta < nearest_delta)