From: Paul Eggert Date: Mon, 13 Jun 2011 16:08:46 +0000 (-0700) Subject: * xterm.c (x_alloc_nearest_color_1): Go back to original algorithm. X-Git-Tag: emacs-pretest-24.0.90~104^2~548^2~20 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a690a978ec42934c3f9d29c15cddd0240ab7a009;p=emacs.git * xterm.c (x_alloc_nearest_color_1): Go back to original algorithm. --- diff --git a/src/ChangeLog b/src/ChangeLog index 6bac6f00a3f..43e1f9dbc06 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,8 +1,6 @@ 2011-06-13 Paul Eggert - * xterm.c (x_alloc_nearest_color_1): Use a more-precise algorithm - for nearest color, one that neither overflows nor relies on unsigned - arithmetic. + * xterm.c (x_alloc_nearest_color_1): Prefer int to long when int works. Remove unnecessary casts. * 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) a least-squares matching, which is what X uses for closest color matching with StaticColor visuals. */ int nearest, i; - int max_color_delta = (1 << (16 - 2)) - 1; + int max_color_delta = 255; int max_delta = 3 * max_color_delta; int nearest_delta = max_delta + 1; int ncells; @@ -1705,9 +1705,9 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color) for (nearest = i = 0; i < ncells; ++i) { - int dred = (color->red >> 2) - (cells[i].red >> 2); - int dgreen = (color->green >> 2) - (cells[i].green >> 2); - int dblue = (color->blue >> 2) - (cells[i].blue >> 2); + int dred = (color->red >> 8) - (cells[i].red >> 8); + int dgreen = (color->green >> 8) - (cells[i].green >> 8); + int dblue = (color->blue >> 8) - (cells[i].blue >> 8); int delta = dred * dred + dgreen * dgreen + dblue * dblue; if (delta < nearest_delta)