Commit 5490ccc5 authored by Mark Oteiza's avatar Mark Oteiza
Browse files

Add lisp variable lcms-d65-xyz

This serves as the default optional argument for functions in this
library.
* src/lcms.c (lcms-d65-xyz): New variable.
(lcms-cam02-ucs): Use it.  Use better word in docstring.  Fix bug
color1 -> color2.
* test/src/lcms-tests.el: Add some tests for lcms-cri-cam02-ucs.
(lcms-colorspacious-d65): New variable.
parent dee96f4a
......@@ -162,7 +162,7 @@ parse_xyz_list (Lisp_Object xyz_list, cmsCIEXYZ *color)
DEFUN ("lcms-cam02-ucs", Flcms_cam02_ucs, Slcms_cam02_ucs, 2, 3, 0,
doc: /* Compute CAM02-UCS metric distance between COLOR1 and COLOR2.
Each color is a list of XYZ coordinates, with Y scaled to unity.
Each color is a list of XYZ coordinates, with Y scaled about unity.
Optional argument is the XYZ white point, which defaults to illuminant D65. */)
(Lisp_Object color1, Lisp_Object color2, Lisp_Object whitepoint)
{
......@@ -186,15 +186,11 @@ Optional argument is the XYZ white point, which defaults to illuminant D65. */)
if (!(CONSP (color1) && parse_xyz_list (color1, &xyz1)))
signal_error ("Invalid color", color1);
if (!(CONSP (color2) && parse_xyz_list (color2, &xyz2)))
signal_error ("Invalid color", color1);
signal_error ("Invalid color", color2);
if (NILP (whitepoint))
{
xyzw.X = 95.047;
xyzw.Y = 100.0;
xyzw.Z = 108.883;
}
parse_xyz_list (Vlcms_d65_xyz, &xyzw);
else if (!(CONSP (whitepoint) && parse_xyz_list (whitepoint, &xyzw)))
signal_error("Invalid white point", whitepoint);
signal_error ("Invalid white point", whitepoint);
vc.whitePoint.X = xyzw.X;
vc.whitePoint.Y = xyzw.Y;
......@@ -295,6 +291,12 @@ DEFUN ("lcms2-available-p", Flcms2_available_p, Slcms2_available_p, 0, 0, 0,
void
syms_of_lcms2 (void)
{
DEFVAR_LISP ("lcms-d65-xyz", Vlcms_d65_xyz,
doc: /* D65 illuminant as a CIE XYZ triple. */);
Vlcms_d65_xyz = list3 (make_float (0.950455),
make_float (1.0),
make_float (1.088753));
defsubr (&Slcms_cie_de2000);
defsubr (&Slcms_cam02_ucs);
defsubr (&Slcms2_available_p);
......
......@@ -33,6 +33,9 @@
(require 'ert)
(require 'color)
(defconst lcms-colorspacious-d65 '(0.95047 1.0 1.08883)
"D65 white point from colorspacious.")
(defun lcms-approx-p (a b &optional delta)
"Check if A and B are within relative error DELTA of one another.
B is considered the exact value."
......@@ -46,6 +49,22 @@ B is considered the exact value."
(lcms-approx-p a2 b2 delta)
(lcms-approx-p a3 b3 delta))))
(ert-deftest lcms-cri-cam02-ucs ()
"Test use of `lcms-cam02-ucs'."
(should-error (lcms-cam02-ucs '(0 0 0) '(0 0 0) "error"))
(should-error (lcms-cam02-ucs '(0 0 0) 'error))
(should-not
(lcms-approx-p
(let ((lcms-d65-xyz '(0.44757 1.0 0.40745)))
(lcms-cam02-ucs '(0.5 0.5 0.5) '(0 0 0)))
(lcms-cam02-ucs '(0.5 0.5 0.5) '(0 0 0))))
(should (eql 0.0 (lcms-cam02-ucs '(0.5 0.5 0.5) '(0.5 0.5 0.5))))
(should
(lcms-approx-p (lcms-cam02-ucs lcms-colorspacious-d65
'(0 0 0)
lcms-colorspacious-d65)
100.0)))
(ert-deftest lcms-whitepoint ()
"Test use of `lcms-temp->white-point'."
(should-error (lcms-temp->white-point 3999))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment