From 56ab0c4a4c99766c041a12f737353c9b889d1750 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 14 Sep 2017 19:37:35 +0300 Subject: [PATCH] Support lcms2 in MS-Windows builds * lisp/term/w32-win.el (dynamic-library-alist): Include association for the lcms2 library. * src/lcms.c [WINDOWSNT]: Include windows.h and w32.h. Use DEF_DLL_FN to define pointers to dynamically loaded lcms2 functions. (cmsCIE2000DeltaE, cmsCIECAM02Init, cmsCIECAM02Forward) (cmsCIECAM02Done): New macros. (init_lcms_functions, Flcms2_available_p): New functions. (Flcms_cie_de2000, Flcms_cam02_ucs) [WINDOWSNT]: Call init_lcms_functions. (syms_of_lcms2): Defsubr lcms2-available-p. * src/w32fns.c (syms_of_w32fns): DEFSYM Qlcms2. * configure.ac: Include lcms2 in the final report and in emacs_config_features. * nt/INSTALL: * nt/INSTALL.W64: Update with the information about lcms2 library. --- configure.ac | 3 +- lisp/term/w32-win.el | 3 +- nt/INSTALL | 9 ++++++ nt/INSTALL.W64 | 1 + src/lcms.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/w32fns.c | 1 + 6 files changed, 99 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 1cce2107dc2..39f7cfb8978 100644 --- a/configure.ac +++ b/configure.ac @@ -5367,7 +5367,7 @@ emacs_config_features= for opt in XAW3D XPM JPEG TIFF GIF PNG RSVG CAIRO IMAGEMAGICK SOUND GPM DBUS \ GCONF GSETTINGS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT \ LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS X_TOOLKIT OLDXMENU X11 NS MODULES \ - XWIDGETS LIBSYSTEMD CANNOT_DUMP; do + XWIDGETS LIBSYSTEMD CANNOT_DUMP LCMS2; do case $opt in CANNOT_DUMP) eval val=\${$opt} ;; @@ -5400,6 +5400,7 @@ AS_ECHO([" Does Emacs use -lXaw3d? ${HAVE_XAW3D Does Emacs use a png library? ${HAVE_PNG} $LIBPNG Does Emacs use -lrsvg-2? ${HAVE_RSVG} Does Emacs use cairo? ${HAVE_CAIRO} + Does Emacs use -llcms2? ${HAVE_LCMS2} Does Emacs use imagemagick (version 6)? ${HAVE_IMAGEMAGICK} Does Emacs support sound? ${HAVE_SOUND} Does Emacs use -lgpm? ${HAVE_GPM} diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el index bd16145756e..4e0e54ae179 100644 --- a/lisp/term/w32-win.el +++ b/lisp/term/w32-win.el @@ -275,7 +275,8 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") '(gnutls "libgnutls-30.dll") '(gnutls "libgnutls-28.dll" "libgnutls-26.dll")) '(libxml2 "libxml2-2.dll" "libxml2.dll") - '(zlib "zlib1.dll" "libz-1.dll"))) + '(zlib "zlib1.dll" "libz-1.dll") + '(lcms2 "liblcms2-2.dll"))) ;;; multi-tty support (defvar w32-initialized nil diff --git a/nt/INSTALL b/nt/INSTALL index b7f47a5d7c2..c6182c22cef 100644 --- a/nt/INSTALL +++ b/nt/INSTALL @@ -486,6 +486,8 @@ build will run on Windows 9X and newer systems). Does Emacs use a gif library? yes Does Emacs use a png library? yes Does Emacs use -lrsvg-2? yes + Does Emacs use cairo? no + Does Emacs use -llcms2? yes Does Emacs use imagemagick? no Does Emacs support sound? no Does Emacs use -lgpm? no @@ -797,6 +799,13 @@ build will run on Windows 9X and newer systems). (This library is also a prerequisite for several image libraries, so you may already have it; look for zlib1.dll or libz-1.dll.) +* Optional support for lcms2 library + + Emacs can expose some capabilities of the Little CMS color + management engine to Lisp programs using the lcms2 library. + Prebuilt binaries of lcms2 DLL (for 32-bit builds of Emacs) are + available from the ezwinports site and from the MSYS2 project. + This file is part of GNU Emacs. diff --git a/nt/INSTALL.W64 b/nt/INSTALL.W64 index b40f2238b5e..cb134735738 100644 --- a/nt/INSTALL.W64 +++ b/nt/INSTALL.W64 @@ -63,6 +63,7 @@ packages (you can copy and paste it into the shell with Shift + Insert): mingw-w64-x86_64-libpng \ mingw-w64-x86_64-libjpeg-turbo \ mingw-w64-x86_64-librsvg \ + mingw-w64-x86_64-liblcms2 \ mingw-w64-x86_64-libxml2 \ mingw-w64-x86_64-gnutls \ mingw-w64-x86_64-zlib diff --git a/src/lcms.c b/src/lcms.c index 10c79ae24a0..49af402327a 100644 --- a/src/lcms.c +++ b/src/lcms.c @@ -25,6 +25,48 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" +#ifdef WINDOWSNT +# include +# include "w32.h" + +DEF_DLL_FN (cmsFloat64Number, cmsCIE2000DeltaE, + (const cmsCIELab* Lab1, const cmsCIELab* Lab2, cmsFloat64Number Kl, + cmsFloat64Number Kc, cmsFloat64Number Kh)); +DEF_DLL_FN (cmsHANDLE, cmsCIECAM02Init, + (cmsContext ContextID, const cmsViewingConditions* pVC)); +DEF_DLL_FN (void, cmsCIECAM02Forward, + (cmsHANDLE hModel, const cmsCIEXYZ* pIn, cmsJCh* pOut)); +DEF_DLL_FN (void, cmsCIECAM02Done, (cmsHANDLE hModel)); + +static bool lcms_initialized; + +static bool +init_lcms_functions (void) +{ + HMODULE library = w32_delayed_load (Qlcms2); + + if (!library) + return false; + + LOAD_DLL_FN (library, cmsCIE2000DeltaE); + LOAD_DLL_FN (library, cmsCIECAM02Init); + LOAD_DLL_FN (library, cmsCIECAM02Forward); + LOAD_DLL_FN (library, cmsCIECAM02Done); + return true; +} + +# undef cmsCIE2000DeltaE +# undef cmsCIECAM02Init +# undef cmsCIECAM02Forward +# undef cmsCIECAM02Done + +# define cmsCIE2000DeltaE fn_cmsCIE2000DeltaE +# define cmsCIECAM02Init fn_cmsCIECAM02Init +# define cmsCIECAM02Forward fn_cmsCIECAM02Forward +# define cmsCIECAM02Done fn_cmsCIECAM02Done + +#endif /* WINDOWSNT */ + static bool parse_lab_list (Lisp_Object lab_list, cmsCIELab *color) { @@ -58,6 +100,16 @@ chroma, and hue, respectively. The parameters each default to 1. */) cmsCIELab Lab1, Lab2; cmsFloat64Number Kl, Kc, Kh; +#ifdef WINDOWSNT + if (!lcms_initialized) + lcms_initialized = init_lcms_functions (); + if (!lcms_initialized) + { + message1 ("lcms2 library not found"); + return Qnil; + } +#endif + if (!(CONSP (color1) && parse_lab_list (color1, &Lab1))) signal_error ("Invalid color", color1); if (!(CONSP (color2) && parse_lab_list (color2, &Lab2))) @@ -112,6 +164,16 @@ Optional argument is the XYZ white point, which defaults to illuminant D65. */) double Jp1, ap1, bp1, Jp2, ap2, bp2; double Mp1, Mp2, FL, k, k4; +#ifdef WINDOWSNT + if (!lcms_initialized) + lcms_initialized = init_lcms_functions (); + if (!lcms_initialized) + { + message1 ("lcms2 library not found"); + return Qnil; + } +#endif + if (!(CONSP (color1) && parse_xyz_list (color1, &xyz1))) signal_error ("Invalid color", color1); if (!(CONSP (color2) && parse_xyz_list (color2, &xyz2))) @@ -170,6 +232,27 @@ Optional argument is the XYZ white point, which defaults to illuminant D65. */) (bp2 - bp1) * (bp2 - bp1))); } +DEFUN ("lcms2-available-p", Flcms2_available_p, Slcms2_available_p, 0, 0, 0, + doc: /* Return t if lcms2 color calculations are available in this instance of Emacs. */) + (void) +{ +#ifdef WINDOWSNT + Lisp_Object found = Fassq (Qlcms2, Vlibrary_cache); + if (CONSP (found)) + return XCDR (found); + else + { + Lisp_Object status; + lcms_initialized = init_lcms_functions (); + status = lcms_initialized ? Qt : Qnil; + Vlibrary_cache = Fcons (Fcons (Qlcms2, status), Vlibrary_cache); + return status; + } +#else /* !WINDOWSNT */ + return Qt; +#endif +} + /* Initialization */ void @@ -177,6 +260,7 @@ syms_of_lcms2 (void) { defsubr (&Slcms_cie_de2000); defsubr (&Slcms_cam02_ucs); + defsubr (&Slcms2_available_p); Fprovide (intern_c_string ("lcms2"), Qnil); } diff --git a/src/w32fns.c b/src/w32fns.c index 6b93afa8b8d..a77464465ec 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -10405,6 +10405,7 @@ syms_of_w32fns (void) DEFSYM (Qlibxml2, "libxml2"); DEFSYM (Qserif, "serif"); DEFSYM (Qzlib, "zlib"); + DEFSYM (Qlcms2, "lcms2"); Fput (Qundefined_color, Qerror_conditions, listn (CONSTYPE_PURE, 2, Qundefined_color, Qerror)); -- 2.11.4.GIT