1 ;;; lcms-tests.el --- tests for Little CMS interface -*- lexical-binding: t -*-
3 ;; Copyright (C) 2017-2018 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
24 ;; Some reference values computed using the colorspacious python
25 ;; library, assimilated from its test suite, or adopted from its
26 ;; aggregation of gold values.
27 ;; See https://colorspacious.readthedocs.io/en/v1.1.0/ and
28 ;; https://github.com/njsmith/colorspacious
31 ;; http://www.babelcolor.com/index_htm_files/A%20review%20of%20RGB%20color%20spaces.pdf
38 (defconst lcms-colorspacious-d65
'(0.95047
1.0 1.08883)
39 "D65 white point from colorspacious.")
41 (defun lcms-approx-p (a b
&optional delta
)
42 "Check if A and B are within relative error DELTA of one another.
43 B is considered the exact value."
44 (> (or delta
0.001) (abs (1- (/ a b
)))))
46 (defun lcms-triple-approx-p (a b
&optional delta
)
47 "Like `lcms-approx-p' except for color triples."
48 (pcase-let ((`(,a1
,a2
,a3
) a
)
50 (and (lcms-approx-p a1 b1 delta
)
51 (lcms-approx-p a2 b2 delta
)
52 (lcms-approx-p a3 b3 delta
))))
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
)))
59 (ert-deftest lcms-cri-cam02-ucs
()
60 "Test use of `lcms-cam02-ucs'."
61 (skip-unless (featurep 'lcms2
))
62 (should-error (lcms-cam02-ucs '(0 0 0) '(0 0 0) "error"))
63 (should-error (lcms-cam02-ucs '(0 0 0) 'error
))
66 (let ((wp '(0.44757
1.0 0.40745)))
67 (lcms-cam02-ucs '(0.5
0.5 0.5) '(0 0 0) wp
))
68 (lcms-cam02-ucs '(0.5
0.5 0.5) '(0 0 0))))
69 (should (eql 0.0 (lcms-cam02-ucs '(0.5
0.5 0.5) '(0.5
0.5 0.5))))
71 (lcms-approx-p (lcms-cam02-ucs lcms-colorspacious-d65
73 lcms-colorspacious-d65
)
76 (ert-deftest lcms-whitepoint
()
77 "Test use of `lcms-temp->white-point'."
78 (skip-unless (featurep 'lcms2
))
79 (should-error (lcms-temp->white-point
3999))
80 (should-error (lcms-temp->white-point
25001))
84 (apply #'color-xyz-to-xyy
(lcms-temp->white-point
5503))
85 '(0.33242
0.34743 1.0)))
89 (apply #'color-xyz-to-xyy
(lcms-temp->white-point
6504))
90 '(0.31271
0.32902 1.0)))
94 (apply #'color-xyz-to-xyy
(lcms-temp->white-point
7504))
95 '(0.29902
0.31485 1.0))))
97 (ert-deftest lcms-roundtrip
()
98 "Test accuracy of converting to and from different color spaces"
99 (skip-unless (featurep 'lcms2
))
101 (let ((color '(.5 .3 .7)))
102 (lcms-triple-approx-p (lcms-jch->xyz
(lcms-xyz->jch color
))
106 (let ((color '(.8 -
.2 .2)))
107 (lcms-triple-approx-p (lcms-jch->jab
(lcms-jab->jch color
))
111 (ert-deftest lcms-ciecam02-gold
()
112 "Test CIE CAM02 JCh gold values"
113 (skip-unless (featurep 'lcms2
))
115 (lcms-triple-approx-p
116 (lcms-xyz->jch
'(0.1931
0.2393 0.1014)
117 '(0.9888
0.900 0.3203)
119 '(48.0314
38.7789 191.0452)
122 (lcms-triple-approx-p
123 (lcms-xyz->jch
'(0.1931
0.2393 0.1014)
124 '(0.9888
0.90 0.3203)
126 '(47.6856
36.0527 185.3445)
129 (ert-deftest lcms-dE-cam02-ucs-silver
()
130 "Test CRI-CAM02-UCS deltaE metric values from colorspacious."
131 (skip-unless (featurep 'lcms2
))
134 (lcms-cam02-ucs (lcms-rgb255->xyz
'(173 52 52))
135 (lcms-rgb255->xyz
'(59 120 51))
136 lcms-colorspacious-d65
137 (list 20 (/ 64 float-pi
5) 1 1))
142 (lcms-cam02-ucs (lcms-rgb255->xyz
'(69 100 52))
143 (lcms-rgb255->xyz
'(59 120 51))
144 lcms-colorspacious-d65
145 (list 20 (/ 64 float-pi
5) 1 1))
149 (ert-deftest lcms-jmh-
>cam02-ucs-silver
()
150 "Compare JCh conversion to CAM02-UCS to values from colorspacious."
151 (skip-unless (featurep 'lcms2
))
153 (lcms-triple-approx-p (lcms-jch->jab
'(50 20 10))
154 '(62.96296296
16.22742674 2.86133316)
157 (lcms-triple-approx-p (lcms-jch->jab
'(10 60 100))
158 '(15.88785047 -
6.56546789 37.23461867)
161 ;;; lcms-tests.el ends here