[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Doc string and operation of color-distance
From: |
Mark Oteiza |
Subject: |
Re: Doc string and operation of color-distance |
Date: |
Thu, 14 Sep 2017 15:43:28 -0400 |
Eli Zaretskii <address@hidden> writes:
> Mark, the new color-distance says something strange in its doc string:
>
> (color-distance COLOR1 COLOR2 &optional FRAME METRIC)
>
> 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 unspecified or nil, a modified L*u*v* metric is used.
>
> The last sentence should say "non-nil", I think, and it should
> document that METRIC is supposed to be a function of 2 colors.
>
> Also, this is unexpected:
>
> (color-distance "red" "blue" nil 'lcms-cam02-ucs)
> => (error "Invalid color" "red")
>
> I think the new lcms2 functions should support colors specified as
> strings, because all the other color-related functions do.
At the very least we should feed metrics the translated RGBs.
Beyond that, in order to use (for example) lcms2-cam02-ucs with
color-distance, one has to translate RGB to XYZ, so the metric would be
(lambda (a b)
(lcms2-cam02-ucs (color-srgb-to-xyz a) (color-srgb-to-xyz b))
diff --git a/src/xfaces.c b/src/xfaces.c
index 012de4e7af..9804c96c39 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -4093,7 +4093,9 @@ DEFUN ("color-distance", Fcolor_distance,
Scolor_distance, 2, 4, 0,
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 unspecified or nil, a modified L*u*v* metric is used. */)
+If METRIC is specified, it should be a function that accepts two
+lists of the form (RED GREEN BLUE). The default metric uses a
+modified L*u*v* space. */)
(Lisp_Object color1, Lisp_Object color2, Lisp_Object frame,
Lisp_Object metric)
{
@@ -4112,7 +4114,15 @@ If METRIC is unspecified or nil, a modified L*u*v*
metric is used. */)
if (NILP (metric))
return make_number (color_distance (&cdef1, &cdef2));
else
- return call2 (metric, color1, color2);
+ {
+ Lisp_Object rgb1 = list3 (make_number (&cdef1.red),
+ make_number (&cdef1.green),
+ make_number (&cdef1.blue));
+ Lisp_Object rgb2 = list3 (make_number (&cdef2.red),
+ make_number (&cdef2.green),
+ make_number (&cdef2.blue));
+ return call2 (metric, rgb1, rgb2);
+ }
}