diff options
author | Eli Zaretskii <eliz@gnu.org> | 2017-09-14 19:37:35 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2017-09-14 19:37:35 +0300 |
commit | 56ab0c4a4c99766c041a12f737353c9b889d1750 (patch) | |
tree | 578a58fea6da5312c3a522d4a3c58d7c2d5b16a3 /src | |
parent | bc5485edeff0ccb3fbcc7fe6b6f13c666699e959 (diff) | |
download | emacs-56ab0c4a4c99766c041a12f737353c9b889d1750.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/lcms.c | 84 | ||||
-rw-r--r-- | src/w32fns.c | 1 |
2 files changed, 85 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>. */ #include "lisp.h" +#ifdef WINDOWSNT +# include <windows.h> +# 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)); |