color.el (color-name-to-rgb): Use the white color to find the max color component...
[bpt/emacs.git] / lisp / color.el
index 5b67eb5..6fab613 100644 (file)
@@ -1,6 +1,6 @@
 ;;; color.el --- Color manipulation library -*- coding: utf-8; -*-
 
-;; Copyright (C) 2010-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
 
 ;; Authors: Julien Danjou <julien@danjou.info>
 ;;          Drew Adams <drew.adams@oracle.com>
@@ -28,7 +28,7 @@
 ;; complements, and computing CIEDE2000 color distances.
 ;;
 ;; Supported color representations include RGB (red, green, blue), HSV
-;; (hue, saturation, value), HSL (hue, saturation, luminence), sRGB,
+;; (hue, saturation, value), HSL (hue, saturation, luminance), sRGB,
 ;; CIE XYZ, and CIE L*a*b* color components.
 
 ;;; Code:
@@ -53,7 +53,10 @@ numbers, (RED GREEN BLUE), each between 0.0 and 1.0 inclusive.
 Optional arg FRAME specifies the frame where the color is to be
 displayed.  If FRAME is omitted or nil, use the selected frame.
 If FRAME cannot display COLOR, return nil."
-  (mapcar (lambda (x) (/ x 65535.0)) (color-values color frame)))
+  ;; `colors-values' maximum value is either 65535 or 65280 depending on the
+  ;; display system. So we use a white conversion to get the max value.
+  (let ((valmax (float (car (color-values "#ffffff")))))
+    (mapcar (lambda (x) (/ x valmax)) (color-values color frame))))
 
 (defun color-rgb-to-hex  (red green blue)
   "Return hexadecimal notation for the color RED GREEN BLUE.
@@ -128,8 +131,8 @@ inclusive."
 RED, GREEN, and BLUE should each be numbers between 0.0 and 1.0,
 inclusive.
 
-Return a list (HUE, SATURATION, LUMINENCE), where HUE is in radians
-and both SATURATION and LUMINENCE are between 0.0 and 1.0,
+Return a list (HUE, SATURATION, LUMINANCE), where HUE is in radians
+and both SATURATION and LUMINANCE are between 0.0 and 1.0,
 inclusive."
   (let* ((r red)
          (g green)