diff options
| author | Mark Oteiza | 2017-09-15 23:49:42 -0400 |
|---|---|---|
| committer | Mark Oteiza | 2017-09-15 23:49:42 -0400 |
| commit | f5f261c6901e51b28deaa05dab157a38adf08912 (patch) | |
| tree | 096d0d991bab7e6cd5a98afb6c2fa8b977099cf2 | |
| parent | 30c955b1725258546c6152a6dda8f634867a6319 (diff) | |
| download | emacs-f5f261c6901e51b28deaa05dab157a38adf08912.tar.gz emacs-f5f261c6901e51b28deaa05dab157a38adf08912.zip | |
Add lcms-temp->white-point and initial tests
* src/lcms.c (lcms-temp->white-point): New function.
* test/src/lcms-tests.el: New file.
| -rw-r--r-- | src/lcms.c | 28 | ||||
| -rw-r--r-- | test/src/lcms-tests.el | 69 |
2 files changed, 97 insertions, 0 deletions
diff --git a/src/lcms.c b/src/lcms.c index 49af402327a..974fcd49300 100644 --- a/src/lcms.c +++ b/src/lcms.c | |||
| @@ -232,6 +232,34 @@ Optional argument is the XYZ white point, which defaults to illuminant D65. */) | |||
| 232 | (bp2 - bp1) * (bp2 - bp1))); | 232 | (bp2 - bp1) * (bp2 - bp1))); |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | DEFUN ("lcms-temp->white-point", Flcms_temp_to_white_point, Slcms_temp_to_white_point, 1, 1, 0, | ||
| 236 | doc: /* Return XYZ black body chromaticity from TEMPERATURE given in K. | ||
| 237 | Valid range is 4000K to 25000K. */) | ||
| 238 | (Lisp_Object temperature) | ||
| 239 | { | ||
| 240 | cmsFloat64Number tempK; | ||
| 241 | cmsCIExyY whitepoint; | ||
| 242 | cmsCIEXYZ wp; | ||
| 243 | |||
| 244 | #ifdef WINDOWSNT | ||
| 245 | if (!lcms_initialized) | ||
| 246 | lcms_initialized = init_lcms_functions (); | ||
| 247 | if (!lcms_initialized) | ||
| 248 | { | ||
| 249 | message1 ("lcms2 library not found"); | ||
| 250 | return Qnil; | ||
| 251 | } | ||
| 252 | #endif | ||
| 253 | |||
| 254 | CHECK_NUMBER_OR_FLOAT(temperature); | ||
| 255 | |||
| 256 | tempK = XFLOATINT(temperature); | ||
| 257 | if (!(cmsWhitePointFromTemp(&whitepoint, tempK))) | ||
| 258 | signal_error("Invalid temperature", temperature); | ||
| 259 | cmsxyY2XYZ(&wp, &whitepoint); | ||
| 260 | return list3 (make_float (wp.X), make_float (wp.Y), make_float (wp.Z)); | ||
| 261 | } | ||
| 262 | |||
| 235 | DEFUN ("lcms2-available-p", Flcms2_available_p, Slcms2_available_p, 0, 0, 0, | 263 | DEFUN ("lcms2-available-p", Flcms2_available_p, Slcms2_available_p, 0, 0, 0, |
| 236 | doc: /* Return t if lcms2 color calculations are available in this instance of Emacs. */) | 264 | doc: /* Return t if lcms2 color calculations are available in this instance of Emacs. */) |
| 237 | (void) | 265 | (void) |
diff --git a/test/src/lcms-tests.el b/test/src/lcms-tests.el new file mode 100644 index 00000000000..0d6b8db3d4b --- /dev/null +++ b/test/src/lcms-tests.el | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | ;;; lcms-tests.el --- tests for Little CMS interface -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Maintainer: emacs-devel@gnu.org | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 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. | ||
| 13 | |||
| 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. | ||
| 18 | |||
| 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/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;; Some "exact" values computed using the colorspacious python library | ||
| 25 | ;; written by Nathaniel J. Smith. See | ||
| 26 | ;; https://colorspacious.readthedocs.io/en/v1.1.0/ | ||
| 27 | |||
| 28 | ;; Other references: | ||
| 29 | ;; http://www.babelcolor.com/index_htm_files/A%20review%20of%20RGB%20color%20spaces.pdf | ||
| 30 | |||
| 31 | ;;; Code: | ||
| 32 | |||
| 33 | (require 'ert) | ||
| 34 | (require 'color) | ||
| 35 | |||
| 36 | (defun lcms-approx-p (a b &optional delta) | ||
| 37 | "Check if A and B are within relative error DELTA of one another. | ||
| 38 | B is considered the exact value." | ||
| 39 | (> (or delta 0.001) (abs (1- (/ a b))))) | ||
| 40 | |||
| 41 | (defun lcms-triple-approx-p (a b &optional delta) | ||
| 42 | "Like `lcms-approx-p' except for color triples." | ||
| 43 | (pcase-let ((`(,a1 ,a2 ,a3) a) | ||
| 44 | (`(,b1 ,b2 ,b3) b)) | ||
| 45 | (and (lcms-approx-p a1 b1 delta) | ||
| 46 | (lcms-approx-p a2 b2 delta) | ||
| 47 | (lcms-approx-p a3 b3 delta)))) | ||
| 48 | |||
| 49 | (ert-deftest lcms-whitepoint () | ||
| 50 | "Test use of `lcms-temp->white-point'." | ||
| 51 | (should-error (lcms-temp->white-point 3999)) | ||
| 52 | (should-error (lcms-temp->white-point 25001)) | ||
| 53 | ;; D55 | ||
| 54 | (should | ||
| 55 | (lcms-triple-approx-p | ||
| 56 | (apply #'color-xyz-to-xyy (lcms-temp->white-point 5503)) | ||
| 57 | '(0.33242 0.34743 1.0))) | ||
| 58 | ;; D65 | ||
| 59 | (should | ||
| 60 | (lcms-triple-approx-p | ||
| 61 | (apply #'color-xyz-to-xyy (lcms-temp->white-point 6504)) | ||
| 62 | '(0.31271 0.32902 1.0))) | ||
| 63 | ;; D75 | ||
| 64 | (should | ||
| 65 | (lcms-triple-approx-p | ||
| 66 | (apply #'color-xyz-to-xyy (lcms-temp->white-point 7504)) | ||
| 67 | '(0.29902 0.31485 1.0)))) | ||
| 68 | |||
| 69 | ;;; lcms-tests.el ends here | ||