summaryrefslogtreecommitdiff
path: root/lisp/facemenu.el
diff options
context:
space:
mode:
authorChong Yidong <cyd@stupidchicken.com>2011-02-21 01:03:36 -0500
committerChong Yidong <cyd@stupidchicken.com>2011-02-21 01:03:36 -0500
commit6d7132563c23774dddcd825797a29ce7ae94253a (patch)
tree28a2b790f0a182a17c3936d087b008b47086239d /lisp/facemenu.el
parent6b483b66430254ac219305874dce0ee15ab09eda (diff)
downloademacs-6d7132563c23774dddcd825797a29ce7ae94253a.tar.gz
Merge some code from hexrgb.el into color.el.
* lisp/color.el (color-name-to-rgb): Rename from color-rgb->normalize. Autoload. Add optional arg FRAME, and pass it to color-values. (color-complement): Caller changed. Doc fix. (color-gradient): Rewrite for better clarity and efficiency. (color-rgb-to-hex): Rename from color-rgb->hex. (color-rgb-to-hsv): Rename from color-rgb->hsv. Force hue and saturation to zero if the value is too small. (color-rgb-to-hsl): Rename from color-rgb->hsl. (color-srgb-to-xyz): Rename from color-srgb->xyz. Doc fix. (color-xyz-to-srgb): Rename from color-xyz->srgb. Doc fix. (color-xyz-to-lab): Rename from color-xyz->lab. Doc fix. (color-lab-to-xyz): Rename from color-lab->xyz. Doc fix. (color-lab-to-srgb): Rename from color-lab->srgb. Doc fix. (color-cie-de2000): Doc fix. * lisp/facemenu.el (color-rgb-to-hsv): Deleted; use the version in lisp/color.el instead. (list-colors-sort-key, list-colors-print): Use color-normalized-values. * lisp/faces.el (color-values): Use cond for clarity. Doc fix. * lisp/gnus/shr-color.el (shr-color->hexadecimal): Use renamed function names color-rgb-to-hex, color-name-to-rgb, color-srgb-to-lab, and color-lab-to-srgb.
Diffstat (limited to 'lisp/facemenu.el')
-rw-r--r--lisp/facemenu.el28
1 files changed, 5 insertions, 23 deletions
diff --git a/lisp/facemenu.el b/lisp/facemenu.el
index e76e920a9f0..360383aa32b 100644
--- a/lisp/facemenu.el
+++ b/lisp/facemenu.el
@@ -463,25 +463,6 @@ These special properties include `invisible', `intangible' and `read-only'."
(defalias 'facemenu-read-color 'read-color)
-(defun color-rgb-to-hsv (r g b)
- "For R, G, B color components return a list of hue, saturation, value.
-R, G, B input values should be in [0..65535] range.
-Output values for hue are integers in [0..360] range.
-Output values for saturation and value are integers in [0..100] range."
- (let* ((r (/ r 65535.0))
- (g (/ g 65535.0))
- (b (/ b 65535.0))
- (max (max r g b))
- (min (min r g b))
- (h (cond ((= max min) 0)
- ((= max r) (mod (+ (* 60 (/ (- g b) (- max min))) 360) 360))
- ((= max g) (+ (* 60 (/ (- b r) (- max min))) 120))
- ((= max b) (+ (* 60 (/ (- r g) (- max min))) 240))))
- (s (cond ((= max 0) 0)
- (t (- 1 (/ min max)))))
- (v max))
- (list (round h) (round s 0.01) (round v 0.01))))
-
(defcustom list-colors-sort nil
"Color sort order for `list-colors-display'.
`nil' means default implementation-dependent order (defined in `x-colors').
@@ -508,6 +489,7 @@ and excludes grayscale colors."
"Return a list of keys for sorting colors depending on `list-colors-sort'.
COLOR is the name of the color. When return value is nil,
filter out the color from the output."
+ (require 'color)
(cond
((null list-colors-sort) color)
((eq list-colors-sort 'name)
@@ -517,12 +499,12 @@ filter out the color from the output."
((eq (car-safe list-colors-sort) 'rgb-dist)
(color-distance color (cdr list-colors-sort)))
((eq list-colors-sort 'hsv)
- (apply 'color-rgb-to-hsv (color-values color)))
+ (apply 'color-rgb-to-hsv (color-name-to-rgb color)))
((eq (car-safe list-colors-sort) 'hsv-dist)
- (let* ((c-rgb (color-values color))
+ (let* ((c-rgb (color-name-to-rgb color))
(c-hsv (apply 'color-rgb-to-hsv c-rgb))
(o-hsv (apply 'color-rgb-to-hsv
- (color-values (cdr list-colors-sort)))))
+ (color-name-to-rgb (cdr list-colors-sort)))))
(unless (and (eq (nth 0 c-rgb) (nth 1 c-rgb)) ; exclude grayscale
(eq (nth 1 c-rgb) (nth 2 c-rgb)))
;; 3D Euclidean distance (sqrt is not needed for sorting)
@@ -638,7 +620,7 @@ You can change the color sort order by customizing `list-colors-sort'."
'mouse-face 'highlight
'help-echo
(let ((hsv (apply 'color-rgb-to-hsv
- (color-values (car color)))))
+ (color-name-to-rgb (car color)))))
(format "H:%d S:%d V:%d"
(nth 0 hsv) (nth 1 hsv) (nth 2 hsv)))))
(when callback