Function: list-colors-sort-key
list-colors-sort-key is a byte-compiled function defined in
facemenu.el.gz.
Signature
(list-colors-sort-key COLOR)
Documentation
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.
Source Code
;; Defined in /usr/src/emacs/lisp/facemenu.el.gz
(defun list-colors-sort-key (color)
"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)
(downcase color))
((eq list-colors-sort 'rgb)
(color-values color))
((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-name-to-rgb color)))
((eq (car-safe list-colors-sort) 'hsv-dist)
(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-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)
(+ (expt (- 180 (abs (- 180 (abs (- (nth 0 c-hsv) ; wrap hue
(nth 0 o-hsv)))))) 2)
(expt (- (nth 1 c-hsv) (nth 1 o-hsv)) 2)
(expt (- (nth 2 c-hsv) (nth 2 o-hsv)) 2)))))
((eq list-colors-sort 'luminance)
(let ((c-rgb (color-name-to-rgb color)))
(+ (* (nth 0 c-rgb) 0.21266729)
(* (nth 1 c-rgb) 0.7151522)
(* (nth 2 c-rgb) 0.0721750))))))