diff options
| author | Paul Eggert <eggert@cs.ucla.edu> | 2017-09-25 11:19:07 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-09-25 11:19:07 -0700 |
| commit | abcb2e62dae6aa26308f7ac9efc89247f89cbe65 (patch) | |
| tree | fd2c052c3ec67555b0a92dc86da7ecba9b1ab3f6 /src/lcms.c | |
| parent | 0bd61c212fe53fb843a10da9a2da88e110d3785a (diff) | |
| parent | 49cd561dc62ea6b3fbedab7aef0f020733f4cf09 (diff) | |
| download | emacs-abcb2e62dae6aa26308f7ac9efc89247f89cbe65.tar.gz | |
Merge from origin/emacs-26
49cd561dc6 * test/lisp/tramp-tests.el (tramp-test21-file-links): Spec...
b719f6b20b Loosen strict parsing requirement for desktop files
c7a0c13777 * lisp/xdg.el (xdg-thumb-uri): Fix doc string.
dc6b3560e5 Fix documentation of `make-frame' and related variables an...
3d3778d82a Accept new `always' value for option `buffer-offer-save'
638f64c40a Improve new NS scrolling variable names
d93301242f Document 'replace-buffer-contents' in the manual.
00e4e3e9d2 Fix undecorated frame resizing issues on NS (bug#28512)
820739bbb5 ; * doc/emacs/display.texi (Display Custom): Fix wording.
f2b2201594 ; Spelling and URL fixes
0e143b1fc5 Documentation improvements for 'display-line-numbers'
f656ccdb43 ; Fix typo
d64da52d57 Fix last change in bat-mode.el
908af46abd Fix restoring in GUI sessions desktop saved in TTY sessions
51cbd85454 Improve syntax highlighting in bat-mode
0273916618 Document the 'list-FOO' convention
d24ec58540 Expose viewing conditions in CAM02-UCS metric
a81d5a3d3f Revert "Set frame size to actual requested size (bug#18215)"
0bf066d4b2 Add tests for Edebug
68baca3ee1 Catch more messages in ert-with-message-capture
28e0c410c9 ; * lisp/mouse.el (secondary-selection-exist-p): Doc fix.
31e1d9ef2f Support setting region from secondary selection and vice v...
047f02f00f Fix new copy-directory bug with empty dirs
fbd15836af * doc/lispref/strings.texi (Formatting Strings): Improve i...
f16a8d5dbd Fix 2 testsuite tests for MS-Windows
965cffd89c Rename timer-list to list-timers
a5fec62b51 Provide native touchpad scrolling on macOS
7b3d1c6beb Fix MinGW64 build broken by recent MinGW64 import libraries
c83d0c5fdf Fix crashes in 'move-point-visually' in minibuffer windows
7f3d5f929d * src/emacs.c (usage_message): Don't mention 'find-file'.
6845282200 Fix a minor inaccuracy in the Emacs manual
74d7bb9498 Fix errors in flyspell-post-command-hook
40fdbb01d0 Work on Tramp's file-truename
1a01423b3c Fix bug with make-directory on MS-Windows root
066efb8666 Fix log-view-diff-common when point is after last entry
3f006b56cd Adapt fileio-tests--symlink-failure to Cygwin
ee512e9a82 Ignore buffers whose name begins with a space in save-some...
9e1b5bd92c Improve tramp-interrupt-process robustness
8d4223e61b Minor Tramp doc update
331d0e520f Fix gensym
466df76f7d Cleanup in files-tests.el
6359fe630a Remove old cl-assert calls in 'newline'
059184e645 Avoid crash with C-g C-g in GC
541006c536 Fix format-time-string %Z bug with negative tz
679e05eeb9 message-citation-line-format %Z is now tz name
4e8888d438 Use doc-view or pdf-tools on any window-system
5f28f0db73 Fix bug with min and max and NaNs
37b5e661d2 Fix recently-introduced copy-directory bug
6bbbc38b34 Merge from Gnulib
57249fb297 Fix compatibility problem in Tramp
411bec82c4 Avoid GCC 7 compilation warning in eval.c
34a6774daa ; Partially revert c3445aed5194
Diffstat (limited to 'src/lcms.c')
| -rw-r--r-- | src/lcms.c | 107 |
1 files changed, 84 insertions, 23 deletions
diff --git a/src/lcms.c b/src/lcms.c index f543a030399..a5e527911ef 100644 --- a/src/lcms.c +++ b/src/lcms.c @@ -139,6 +139,26 @@ chroma, and hue, respectively. The parameters each default to 1. */) return make_float (cmsCIE2000DeltaE (&Lab1, &Lab2, Kl, Kc, Kh)); } +static double +deg2rad (double degrees) +{ + return M_PI * degrees / 180.0; +} + +static cmsCIEXYZ illuminant_d65 = { .X = 95.0455, .Y = 100.0, .Z = 108.8753 }; + +static void +default_viewing_conditions (const cmsCIEXYZ *wp, cmsViewingConditions *vc) +{ + vc->whitePoint.X = wp->X; + vc->whitePoint.Y = wp->Y; + vc->whitePoint.Z = wp->Z; + vc->Yb = 20; + vc->La = 100; + vc->surround = AVG_SURROUND; + vc->D_value = 1.0; +} + /* FIXME: code duplication */ static bool @@ -160,11 +180,62 @@ parse_xyz_list (Lisp_Object xyz_list, cmsCIEXYZ *color) return true; } -DEFUN ("lcms-cam02-ucs", Flcms_cam02_ucs, Slcms_cam02_ucs, 2, 3, 0, +static bool +parse_viewing_conditions (Lisp_Object view, const cmsCIEXYZ *wp, + cmsViewingConditions *vc) +{ +#define PARSE_VIEW_CONDITION_FLOAT(field) \ + if (CONSP (view) && NUMBERP (XCAR (view))) \ + { \ + vc->field = XFLOATINT (XCAR (view)); \ + view = XCDR (view); \ + } \ + else \ + return false; +#define PARSE_VIEW_CONDITION_INT(field) \ + if (CONSP (view) && NATNUMP (XCAR (view))) \ + { \ + CHECK_RANGED_INTEGER (XCAR (view), 1, 4); \ + vc->field = XINT (XCAR (view)); \ + view = XCDR (view); \ + } \ + else \ + return false; + + PARSE_VIEW_CONDITION_FLOAT (Yb); + PARSE_VIEW_CONDITION_FLOAT (La); + PARSE_VIEW_CONDITION_INT (surround); + PARSE_VIEW_CONDITION_FLOAT (D_value); + + if (! NILP (view)) + return false; + + vc->whitePoint.X = wp->X; + vc->whitePoint.Y = wp->Y; + vc->whitePoint.Z = wp->Z; + return true; +} + +/* References: + Li, Luo et al. "The CRI-CAM02UCS colour rendering index." COLOR research + and application, 37 No.3, 2012. + Luo et al. "Uniform colour spaces based on CIECAM02 colour appearance + model." COLOR research and application, 31 No.4, 2006. */ + +DEFUN ("lcms-cam02-ucs", Flcms_cam02_ucs, Slcms_cam02_ucs, 2, 4, 0, doc: /* Compute CAM02-UCS metric distance between COLOR1 and COLOR2. -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) +Each color is a list of XYZ tristimulus values, with Y scaled about unity. +Optional argument WHITEPOINT is the XYZ white point, which defaults to +illuminant D65. +Optional argument VIEW is a list containing the viewing conditions, and +is of the form (YB LA SURROUND DVALUE) where SURROUND corresponds to + 1 AVG_SURROUND + 2 DIM_SURROUND + 3 DARK_SURROUND + 4 CUTSHEET_SURROUND +The default viewing conditions are (20 100 1 1). */) + (Lisp_Object color1, Lisp_Object color2, Lisp_Object whitepoint, + Lisp_Object view) { cmsViewingConditions vc; cmsJCh jch1, jch2; @@ -188,17 +259,13 @@ Optional argument is the XYZ white point, which defaults to illuminant D65. */) if (!(CONSP (color2) && parse_xyz_list (color2, &xyz2))) signal_error ("Invalid color", color2); if (NILP (whitepoint)) - parse_xyz_list (Vlcms_d65_xyz, &xyzw); + xyzw = illuminant_d65; else if (!(CONSP (whitepoint) && parse_xyz_list (whitepoint, &xyzw))) signal_error ("Invalid white point", whitepoint); - - vc.whitePoint.X = xyzw.X; - vc.whitePoint.Y = xyzw.Y; - vc.whitePoint.Z = xyzw.Z; - vc.Yb = 20; - vc.La = 100; - vc.surround = AVG_SURROUND; - vc.D_value = 1.0; + if (NILP (view)) + default_viewing_conditions (&xyzw, &vc); + else if (!(CONSP (view) && parse_viewing_conditions (view, &xyzw, &vc))) + signal_error ("Invalid view conditions", view); h1 = cmsCIECAM02Init (0, &vc); h2 = cmsCIECAM02Init (0, &vc); @@ -227,10 +294,10 @@ Optional argument is the XYZ white point, which defaults to illuminant D65. */) Mp2 = 43.86 * log (1.0 + 0.0228 * (jch2.C * sqrt (sqrt (FL)))); Jp1 = 1.7 * jch1.J / (1.0 + (0.007 * jch1.J)); Jp2 = 1.7 * jch2.J / (1.0 + (0.007 * jch2.J)); - ap1 = Mp1 * cos (jch1.h); - ap2 = Mp2 * cos (jch2.h); - bp1 = Mp1 * sin (jch1.h); - bp2 = Mp2 * sin (jch2.h); + ap1 = Mp1 * cos (deg2rad (jch1.h)); + ap2 = Mp2 * cos (deg2rad (jch2.h)); + bp1 = Mp1 * sin (deg2rad (jch1.h)); + bp2 = Mp2 * sin (deg2rad (jch2.h)); return make_float (sqrt ((Jp2 - Jp1) * (Jp2 - Jp1) + (ap2 - ap1) * (ap2 - ap1) + @@ -291,12 +358,6 @@ 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); |
