emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 5490ccc: Add lisp variable lcms-d65-xyz


From: Mark Oteiza
Subject: [Emacs-diffs] emacs-26 5490ccc: Add lisp variable lcms-d65-xyz
Date: Sat, 16 Sep 2017 12:51:36 -0400 (EDT)

branch: emacs-26
commit 5490ccc5ebf39759dfd084bbd31f464701a3e775
Author: Mark Oteiza <address@hidden>
Commit: Mark Oteiza <address@hidden>

    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.
---
 src/lcms.c             | 18 ++++++++++--------
 test/src/lcms-tests.el | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/lcms.c b/src/lcms.c
index 1f3ace3..cdfbc0e 100644
--- a/src/lcms.c
+++ b/src/lcms.c
@@ -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);
diff --git a/test/src/lcms-tests.el b/test/src/lcms-tests.el
index 0d6b8db..e176cff 100644
--- a/test/src/lcms-tests.el
+++ b/test/src/lcms-tests.el
@@ -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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]