aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorMark Oteiza2017-09-21 22:47:24 -0400
committerMark Oteiza2017-09-21 23:06:00 -0400
commitd24ec5854098841388dfecf2c668e7f48f348af0 (patch)
treef8abf85b73a971d981874daa9876aa0640403ab3 /test/src
parenta81d5a3d3fcb76f6b074c2c721b80b1802135d41 (diff)
downloademacs-d24ec5854098841388dfecf2c668e7f48f348af0.tar.gz
emacs-d24ec5854098841388dfecf2c668e7f48f348af0.zip
Expose viewing conditions in CAM02-UCS metric
Also add tests from the colorspacious library. Finally, catch an errant calculation, where degrees were not being converted to radians. * src/lcms.c (deg2rad, default_viewing_conditions): (parse_viewing_conditions): New functions. (lcms-cam02-ucs): Add comments pointing to references used. Expand the docstring and explain viewing conditions. JCh hue is given in degrees and needs to be converted to radians. (lcms-d65-xyz): Remove. No need to duplicate this in Lisp or make the API needlessly impure. * test/src/lcms-tests.el: Reword commentary. (lcms-rgb255->xyz): New function. (lcms-cri-cam02-ucs): Fix let-binding. (lcms-dE-cam02-ucs-silver): New test, assimilated from colorspacious.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/lcms-tests.el37
1 files changed, 32 insertions, 5 deletions
diff --git a/test/src/lcms-tests.el b/test/src/lcms-tests.el
index 3d0942c8d15..d6d1d16b9ad 100644
--- a/test/src/lcms-tests.el
+++ b/test/src/lcms-tests.el
@@ -21,9 +21,11 @@
21 21
22;;; Commentary: 22;;; Commentary:
23 23
24;; Some "exact" values computed using the colorspacious python library 24;; Some reference values computed using the colorspacious python
25;; written by Nathaniel J. Smith. See 25;; library, assimilated from its test suite, or adopted from its
26;; https://colorspacious.readthedocs.io/en/v1.1.0/ 26;; aggregation of gold values.
27;; See https://colorspacious.readthedocs.io/en/v1.1.0/ and
28;; https://github.com/njsmith/colorspacious
27 29
28;; Other references: 30;; Other references:
29;; http://www.babelcolor.com/index_htm_files/A%20review%20of%20RGB%20color%20spaces.pdf 31;; http://www.babelcolor.com/index_htm_files/A%20review%20of%20RGB%20color%20spaces.pdf
@@ -49,6 +51,11 @@ B is considered the exact value."
49 (lcms-approx-p a2 b2 delta) 51 (lcms-approx-p a2 b2 delta)
50 (lcms-approx-p a3 b3 delta)))) 52 (lcms-approx-p a3 b3 delta))))
51 53
54(defun lcms-rgb255->xyz (rgb)
55 "Return XYZ tristimulus values corresponding to RGB."
56 (let ((rgb1 (mapcar (lambda (x) (/ x 255.0)) rgb)))
57 (apply #'color-srgb-to-xyz rgb1)))
58
52(ert-deftest lcms-cri-cam02-ucs () 59(ert-deftest lcms-cri-cam02-ucs ()
53 "Test use of `lcms-cam02-ucs'." 60 "Test use of `lcms-cam02-ucs'."
54 (skip-unless (featurep 'lcms2)) 61 (skip-unless (featurep 'lcms2))
@@ -56,8 +63,8 @@ B is considered the exact value."
56 (should-error (lcms-cam02-ucs '(0 0 0) 'error)) 63 (should-error (lcms-cam02-ucs '(0 0 0) 'error))
57 (should-not 64 (should-not
58 (lcms-approx-p 65 (lcms-approx-p
59 (let ((lcms-d65-xyz '(0.44757 1.0 0.40745))) 66 (let ((wp '(0.44757 1.0 0.40745)))
60 (lcms-cam02-ucs '(0.5 0.5 0.5) '(0 0 0))) 67 (lcms-cam02-ucs '(0.5 0.5 0.5) '(0 0 0) wp))
61 (lcms-cam02-ucs '(0.5 0.5 0.5) '(0 0 0)))) 68 (lcms-cam02-ucs '(0.5 0.5 0.5) '(0 0 0))))
62 (should (eql 0.0 (lcms-cam02-ucs '(0.5 0.5 0.5) '(0.5 0.5 0.5)))) 69 (should (eql 0.0 (lcms-cam02-ucs '(0.5 0.5 0.5) '(0.5 0.5 0.5))))
63 (should 70 (should
@@ -87,4 +94,24 @@ B is considered the exact value."
87 (apply #'color-xyz-to-xyy (lcms-temp->white-point 7504)) 94 (apply #'color-xyz-to-xyy (lcms-temp->white-point 7504))
88 '(0.29902 0.31485 1.0)))) 95 '(0.29902 0.31485 1.0))))
89 96
97(ert-deftest lcms-dE-cam02-ucs-silver ()
98 "Test CRI-CAM02-UCS deltaE metric values from colorspacious."
99 (skip-unless (featurep 'lcms2))
100 (should
101 (lcms-approx-p
102 (lcms-cam02-ucs (lcms-rgb255->xyz '(173 52 52))
103 (lcms-rgb255->xyz '(59 120 51))
104 lcms-colorspacious-d65
105 (list 20 (/ 64 float-pi 5) 1 1))
106 44.698469808449964
107 0.03))
108 (should
109 (lcms-approx-p
110 (lcms-cam02-ucs (lcms-rgb255->xyz '(69 100 52))
111 (lcms-rgb255->xyz '(59 120 51))
112 lcms-colorspacious-d65
113 (list 20 (/ 64 float-pi 5) 1 1))
114 8.503323264883667
115 0.04)))
116
90;;; lcms-tests.el ends here 117;;; lcms-tests.el ends here