comparison src/xfaces.c @ 65781:d9e5cd5bce05

(face_color_gray_p): Colors close to black count as gray.
author Richard M. Stallman <rms@gnu.org>
date Sun, 02 Oct 2005 03:28:56 +0000
parents ad24f42046b1
children da86e1af8629 2a679c81f552 aa89c814f853
comparison
equal deleted inserted replaced
65780:6e229fd94815 65781:d9e5cd5bce05
1475 return Qunspecified; 1475 return Qunspecified;
1476 } 1476 }
1477 1477
1478 1478
1479 /* Return non-zero if COLOR_NAME is a shade of gray (or white or 1479 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1480 black) on frame F. The algorithm is taken from 20.2 faces.el. */ 1480 black) on frame F.
1481
1482 The criterion implemented here is not a terribly sophisticated one. */
1481 1483
1482 static int 1484 static int
1483 face_color_gray_p (f, color_name) 1485 face_color_gray_p (f, color_name)
1484 struct frame *f; 1486 struct frame *f;
1485 char *color_name; 1487 char *color_name;
1486 { 1488 {
1487 XColor color; 1489 XColor color;
1488 int gray_p; 1490 int gray_p;
1489 1491
1490 if (defined_color (f, color_name, &color, 0)) 1492 if (defined_color (f, color_name, &color, 0))
1491 gray_p = ((abs (color.red - color.green) 1493 gray_p = (/* Any color sufficiently close to black counts as grey. */
1492 < max (color.red, color.green) / 20) 1494 (color.red < 5000 && color.green < 5000 && color.blue < 5000)
1493 && (abs (color.green - color.blue) 1495 ||
1494 < max (color.green, color.blue) / 20) 1496 ((abs (color.red - color.green)
1495 && (abs (color.blue - color.red) 1497 < max (color.red, color.green) / 20)
1496 < max (color.blue, color.red) / 20)); 1498 && (abs (color.green - color.blue)
1499 < max (color.green, color.blue) / 20)
1500 && (abs (color.blue - color.red)
1501 < max (color.blue, color.red) / 20)));
1497 else 1502 else
1498 gray_p = 0; 1503 gray_p = 0;
1499 1504
1500 return gray_p; 1505 return gray_p;
1501 } 1506 }