1 From 30af0e2edbf061b71bed9536d826894449f0390d Mon Sep 17 00:00:00 2001
2 From: Nils Philippsen <nils@redhat.com>
3 Date: Mon, 23 Sep 2013 16:11:31 +0200
4 Subject: [PATCH] patch: lcms2
6 Squashed commit of the following:
8 commit f975accf7e1a08438b63580ea848457d373200f5
9 Author: Nils Philippsen <nils@redhat.com>
10 Date: Mon Sep 23 14:53:45 2013 +0200
12 Add support for lcms 2.x.
14 configure.in | 22 ++++++++++++++----
15 include/config.h.in | 8 ++++++-
16 src/xsane-preview.c | 6 +++--
17 src/xsane-save.c | 38 ++++++++++++++++++++++++++-----
18 src/xsane-viewer.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++---
19 src/xsane.h | 8 ++++++-
20 6 files changed, 130 insertions(+), 17 deletions(-)
22 diff --git a/configure.in b/configure.in
23 index df7b114..3659c97 100644
26 @@ -130,7 +130,17 @@ if test "${USE_TIFF}" = "yes"; then
29 if test "${USE_LCMS}" = "yes"; then
30 - AC_CHECK_LIB(lcms, cmsOpenProfileFromFile)
31 + AC_SEARCH_LIBS(cmsOpenProfileFromFile, [lcms2 lcms])
32 + if test "${ac_cv_search_cmsOpenProfileFromFile}" != "no"; then
33 + AC_DEFINE(HAVE_LIBLCMS, 1, [Define if LCMS is to be used.])
35 + if test "${ac_cv_search_cmsOpenProfileFromFile}" == "-llcms2"; then
36 + AC_DEFINE(HAVE_LIBLCMS2, 1, [Define if you have liblcms2.])
38 + if test "${ac_cv_search_cmsOpenProfileFromFile}" == "-llcms"; then
39 + AC_DEFINE(HAVE_LIBLCMS1, 1, [Define if you have liblcms.])
44 dnl Checks for library functions.
45 @@ -294,10 +304,14 @@ else
46 echo "* - PNG support deactivated *"
49 -if test "${ac_cv_lib_lcms_cmsOpenProfileFromFile}" = "yes"; then
50 - echo "* - LCMS (color management) support activated *"
51 +if test "${ac_cv_search_cmsOpenProfileFromFile}" = "-llcms2"; then
52 + echo "* - LCMS (color management) support activated (lcms2) *"
54 - echo "* - LCMS (color management) support deactivated *"
55 + if test "${ac_cv_search_cmsOpenProfileFromFile}" = "-llcms"; then
56 + echo "* - LCMS (color management) support activated (lcms) *"
58 + echo "* - LCMS (color management) support deactivated *"
63 diff --git a/include/config.h.in b/include/config.h.in
64 index ecc9637..f9a3e40 100755
65 --- a/include/config.h.in
66 +++ b/include/config.h.in
68 /* Define if you have libtiff. */
71 -/* Define if you have liblcms. */
72 +/* Define if LCMS is to be used. */
75 +/* Define if you have liblcms. */
78 +/* Define if you have liblcms2. */
81 #ifndef HAVE_STRNCASECMP
83 # define strncasecmp(a, b, c) strnicmp(a, b, c)
84 diff --git a/src/xsane-preview.c b/src/xsane-preview.c
85 index 6327ca7..6eaf687 100644
86 --- a/src/xsane-preview.c
87 +++ b/src/xsane-preview.c
88 @@ -6346,8 +6346,8 @@ int preview_do_color_correction(Preview *p)
89 cmsHPROFILE hOutProfile = NULL;
90 cmsHPROFILE hProofProfile = NULL;
91 cmsHTRANSFORM hTransform = NULL;
92 - DWORD input_format, output_format;
93 - DWORD cms_flags = 0;
94 + cmsUInt32Number input_format, output_format;
95 + cmsUInt32Number cms_flags = 0;
97 char *cms_proof_icm_profile = NULL;
99 @@ -6355,7 +6355,9 @@ int preview_do_color_correction(Preview *p)
101 DBG(DBG_proc, "preview_do_color_correction\n");
103 +#ifdef HAVE_LIBLCMS1
104 cmsErrorAction(LCMS_ERROR_SHOW);
107 if (preferences.cms_bpc)
109 diff --git a/src/xsane-save.c b/src/xsane-save.c
110 index 75e0a63..2d0e44b 100644
111 --- a/src/xsane-save.c
112 +++ b/src/xsane-save.c
113 @@ -832,9 +832,9 @@ cmsHTRANSFORM xsane_create_cms_transform(Image_info *image_info, int cms_functio
114 cmsHPROFILE hInProfile = NULL;
115 cmsHPROFILE hOutProfile = NULL;
116 cmsHTRANSFORM hTransform = NULL;
117 - DWORD cms_input_format;
118 - DWORD cms_output_format;
119 - DWORD cms_flags = 0;
120 + cmsUInt32Number cms_input_format;
121 + cmsUInt32Number cms_output_format;
122 + cmsUInt32Number cms_flags = 0;
124 if (cms_function == XSANE_CMS_FUNCTION_EMBED_SCANNER_ICM_PROFILE)
126 @@ -843,7 +843,9 @@ cmsHTRANSFORM xsane_create_cms_transform(Image_info *image_info, int cms_functio
128 DBG(DBG_info, "Prepare CMS transform\n");
130 +#ifdef HAVE_LIBLCMS1
131 cmsErrorAction(LCMS_ERROR_SHOW);
136 @@ -890,10 +892,18 @@ cmsHTRANSFORM xsane_create_cms_transform(Image_info *image_info, int cms_functio
137 if (image_info->channels == 1) /* == 1 (grayscale) */
140 +# ifdef HAVE_LIBLCMS2
141 + cmsToneCurve *Gamma = cmsBuildGamma(NULL, 2.2);
143 LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2);
146 hOutProfile = cmsCreateGrayProfile(cmsD50_xyY(), Gamma);
147 +# ifdef HAVE_LIBLCMS2
148 + cmsFreeToneCurve(Gamma);
155 @@ -2896,7 +2906,11 @@ static int xsane_write_CSA(FILE *outfile, char *input_profile, int intent)
159 +#ifdef HAVE_LIBLCMS2
160 + n = cmsGetPostScriptCSA(NULL, hProfile, intent, 0, NULL, 0);
162 n = cmsGetPostScriptCSA(hProfile, intent, NULL, 0);
167 @@ -2908,7 +2922,11 @@ static int xsane_write_CSA(FILE *outfile, char *input_profile, int intent)
171 +#ifdef HAVE_LIBLCMS2
172 + cmsGetPostScriptCSA(NULL, hProfile, intent, 0, buffer, n);
174 cmsGetPostScriptCSA(hProfile, intent, buffer, n);
178 fprintf(outfile, "%s", buffer);
179 @@ -2927,7 +2945,7 @@ static int xsane_write_CRD(FILE *outfile, char *output_profile, int intent, int
180 cmsHPROFILE hProfile;
183 - DWORD flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
184 + cmsUInt32Number flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
186 hProfile = cmsOpenProfileFromFile(output_profile, "r");
188 @@ -2940,7 +2958,11 @@ static int xsane_write_CRD(FILE *outfile, char *output_profile, int intent, int
189 flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
192 +#ifdef HAVE_LIBLCMS2
193 + n = cmsGetPostScriptCRD(NULL, hProfile, intent, flags, NULL, 0);
195 n = cmsGetPostScriptCRDEx(hProfile, intent, flags, NULL, 0);
200 @@ -2952,7 +2974,11 @@ static int xsane_write_CRD(FILE *outfile, char *output_profile, int intent, int
204 +#ifdef HAVE_LIBLCMS2
205 + cmsGetPostScriptCRD(NULL, hProfile, intent, flags, buffer, n);
207 cmsGetPostScriptCRDEx(hProfile, intent, flags, buffer, n);
211 fprintf(outfile, "%s", buffer);
212 @@ -4349,7 +4375,7 @@ static void xsane_jpeg_embed_scanner_icm_profile(j_compress_ptr cinfo_ptr, const
215 size_t size, embed_len;
216 - LPBYTE embed_buffer;
217 + cmsUInt8Number *embed_buffer;
219 DBG(DBG_proc, "xsane_jpeg_embed_scanner_icm_profile(%s)\n", icm_filename);
221 @@ -4363,7 +4389,7 @@ static void xsane_jpeg_embed_scanner_icm_profile(j_compress_ptr cinfo_ptr, const
222 size = ftell(icm_profile);
223 fseek(icm_profile, 0, SEEK_SET);
225 - embed_buffer = (LPBYTE) malloc(size + 1);
226 + embed_buffer = (cmsUInt8Number *) malloc(size + 1);
229 embed_len = fread(embed_buffer, 1, size, icm_profile);
230 diff --git a/src/xsane-viewer.c b/src/xsane-viewer.c
231 index 69a444d..844c077 100644
232 --- a/src/xsane-viewer.c
233 +++ b/src/xsane-viewer.c
234 @@ -1795,6 +1795,9 @@ static void xsane_viewer_set_cms_gamut_alarm_color_callback(GtkWidget *widget, g
236 Viewer *v = (Viewer *) data;
238 +#ifdef HAVE_LIBLCMS2
239 + cmsUInt16Number alarm_codes[cmsMAXCHANNELS];
242 g_signal_handlers_block_by_func(GTK_OBJECT(v->cms_gamut_alarm_color_widget[0]), (GtkSignalFunc) xsane_viewer_set_cms_gamut_alarm_color_callback, v);
243 g_signal_handlers_block_by_func(GTK_OBJECT(v->cms_gamut_alarm_color_widget[1]), (GtkSignalFunc) xsane_viewer_set_cms_gamut_alarm_color_callback, v);
244 @@ -1811,6 +1814,49 @@ static void xsane_viewer_set_cms_gamut_alarm_color_callback(GtkWidget *widget, g
245 v->cms_gamut_alarm_color = val;
246 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(v->cms_gamut_alarm_color_widget[v->cms_gamut_alarm_color]), TRUE);
248 +#ifdef HAVE_LIBLCMS2
249 + switch(v->cms_gamut_alarm_color)
252 + case 0: /* black */
253 + alarm_codes[0] = (cmsUInt16Number) 0;
254 + alarm_codes[1] = (cmsUInt16Number) 0;
255 + alarm_codes[2] = (cmsUInt16Number) 0;
259 + alarm_codes[0] = (cmsUInt16Number) 128;
260 + alarm_codes[1] = (cmsUInt16Number) 128;
261 + alarm_codes[2] = (cmsUInt16Number) 128;
264 + case 2: /* white */
265 + alarm_codes[0] = (cmsUInt16Number) 255;
266 + alarm_codes[1] = (cmsUInt16Number) 255;
267 + alarm_codes[2] = (cmsUInt16Number) 255;
271 + alarm_codes[0] = (cmsUInt16Number) 255;
272 + alarm_codes[1] = (cmsUInt16Number) 0;
273 + alarm_codes[2] = (cmsUInt16Number) 0;
276 + case 4: /* green */
277 + alarm_codes[0] = (cmsUInt16Number) 0;
278 + alarm_codes[1] = (cmsUInt16Number) 255;
279 + alarm_codes[2] = (cmsUInt16Number) 0;
283 + alarm_codes[0] = (cmsUInt16Number) 0;
284 + alarm_codes[1] = (cmsUInt16Number) 0;
285 + alarm_codes[2] = (cmsUInt16Number) 255;
289 + cmsSetAlarmCodes(alarm_codes);
291 switch(v->cms_gamut_alarm_color)
294 @@ -1838,6 +1884,7 @@ static void xsane_viewer_set_cms_gamut_alarm_color_callback(GtkWidget *widget, g
295 cmsSetAlarmCodes(0, 0, 255);
300 g_signal_handlers_unblock_by_func(GTK_OBJECT(v->cms_gamut_alarm_color_widget[0]), (GtkSignalFunc) xsane_viewer_set_cms_gamut_alarm_color_callback, v);
301 g_signal_handlers_unblock_by_func(GTK_OBJECT(v->cms_gamut_alarm_color_widget[1]), (GtkSignalFunc) xsane_viewer_set_cms_gamut_alarm_color_callback, v);
302 @@ -2172,9 +2219,9 @@ static int xsane_viewer_read_image(Viewer *v)
303 cmsHTRANSFORM hTransform = NULL;
305 char *cms_proof_icm_profile = NULL;
306 - DWORD cms_input_format;
307 - DWORD cms_output_format;
308 - DWORD cms_flags = 0;
309 + cmsUInt32Number cms_input_format;
310 + cmsUInt32Number cms_output_format;
311 + cmsUInt32Number cms_flags = 0;
315 @@ -2203,7 +2250,9 @@ static int xsane_viewer_read_image(Viewer *v)
317 if ((v->enable_color_management) && (v->cms_enable))
319 +#ifdef HAVE_LIBLCMS1
320 cmsErrorAction(LCMS_ERROR_SHOW);
325 @@ -2801,6 +2850,9 @@ Viewer *xsane_viewer_new(char *filename, char *selection_filetype, int allow_red
326 GtkWidget *scrolled_window;
327 GtkWidget *zoom_option_menu, *zoom_menu, *zoom_menu_item;
329 +#ifdef HAVE_LIBLCMS2
330 + cmsUInt16Number alarm_codes[cmsMAXCHANNELS];
333 DBG(DBG_proc, "viewer_new(%s)\n", filename);
335 @@ -2830,8 +2882,15 @@ Viewer *xsane_viewer_new(char *filename, char *selection_filetype, int allow_red
336 v->cms_proofing_intent = INTENT_ABSOLUTE_COLORIMETRIC;
337 v->cms_gamut_check = 0;
338 v->cms_gamut_alarm_color = 3; /* red */
339 +#ifdef HAVE_LIBLCMS2
340 + alarm_codes[0] = (cmsUInt16Number) 255;
341 + alarm_codes[1] = (cmsUInt16Number) 0;
342 + alarm_codes[2] = (cmsUInt16Number) 0;
343 + cmsSetAlarmCodes(alarm_codes);
345 cmsSetAlarmCodes(255, 0, 0);
348 if (selection_filetype)
350 v->selection_filetype = strdup(selection_filetype);
351 diff --git a/src/xsane.h b/src/xsane.h
352 index 4067d61..adcc0ed 100644
359 -# include <lcms/lcms.h>
360 +# ifdef HAVE_LIBLCMS2
361 +# include <lcms2/lcms2.h>
363 +# include <lcms/lcms.h>
364 +typedef BYTE cmsUInt8Number;
365 +typedef DWORD cmsUInt32Number;
368 # define cmsHTRANSFORM void *