Function: color-distance
color-distance is a function defined in xfaces.c.
Signature
(color-distance COLOR1 COLOR2 &optional FRAME METRIC)
Documentation
Return an integer distance between COLOR1 and COLOR2 on FRAME.
COLOR1 and COLOR2 may be either strings containing the color name, or lists of the form (RED GREEN BLUE), each in the range 0 to 65535 inclusive. If FRAME is unspecified or nil, the current frame is used. If METRIC is specified, it should be a function that accepts two lists of the form (RED GREEN BLUE) aforementioned. Despite the name, this is not a true distance metric as it does not satisfy the triangle inequality.
Probably introduced at or before Emacs version 26.1.
Source Code
// Defined in /usr/src/emacs/src/xfaces.c
{
struct frame *f = decode_live_frame (frame);
Emacs_Color cdef1, cdef2;
if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
&& !(STRINGP (color1)
&& FRAME_TERMINAL (f)->defined_color_hook (f,
SSDATA (color1),
&cdef1,
false,
true)))
signal_error ("Invalid color", color1);
if (!(CONSP (color2) && parse_rgb_list (color2, &cdef2))
&& !(STRINGP (color2)
&& FRAME_TERMINAL (f)->defined_color_hook (f,
SSDATA (color2),
&cdef2,
false,
true)))
signal_error ("Invalid color", color2);
if (NILP (metric))
return make_fixnum (color_distance (&cdef1, &cdef2));
else
return call2 (metric,
list3i (cdef1.red, cdef1.green, cdef1.blue),
list3i (cdef2.red, cdef2.green, cdef2.blue));
}