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 Index: trunk/configure.in
23 ===================================================================
24 --- trunk.orig/configure.in
25 +++ trunk/configure.in
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 Index: trunk/include/config.h.in
64 ===================================================================
65 --- trunk.orig/include/config.h.in
66 +++ trunk/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 Index: trunk/src/xsane-preview.c
85 ===================================================================
86 --- trunk.orig/src/xsane-preview.c
87 +++ trunk/src/xsane-preview.c
88 @@ -6346,8 +6346,8 @@ int preview_do_color_correction(Preview
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
101 DBG(DBG_proc, "preview_do_color_correction\n");
103 +#ifdef HAVE_LIBLCMS1
104 cmsErrorAction(LCMS_ERROR_SHOW);
107 if (preferences.cms_bpc)
109 Index: trunk/src/xsane-save.c
110 ===================================================================
111 --- trunk.orig/src/xsane-save.c
112 +++ trunk/src/xsane-save.c
113 @@ -832,9 +832,9 @@ cmsHTRANSFORM xsane_create_cms_transform
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
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
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 @@ -2904,7 +2914,11 @@ static int xsane_write_CSA(FILE *outfile
159 +#ifdef HAVE_LIBLCMS2
160 + n = cmsGetPostScriptCSA(NULL, hProfile, intent, 0, NULL, 0);
162 n = cmsGetPostScriptCSA(hProfile, intent, NULL, 0);
167 @@ -2916,7 +2930,11 @@ static int xsane_write_CSA(FILE *outfile
171 +#ifdef HAVE_LIBLCMS2
172 + cmsGetPostScriptCSA(NULL, hProfile, intent, 0, buffer, n);
174 cmsGetPostScriptCSA(hProfile, intent, buffer, n);
178 fprintf(outfile, "%s", buffer);
179 @@ -2935,7 +2953,7 @@ static int xsane_write_CRD(FILE *outfile
180 cmsHPROFILE hProfile;
183 - DWORD flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
184 + cmsUInt32Number flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
186 hProfile = cmsOpenProfileFromFile(output_profile, "r");
188 @@ -2948,7 +2966,11 @@ static int xsane_write_CRD(FILE *outfile
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 @@ -2960,7 +2982,11 @@ static int xsane_write_CRD(FILE *outfile
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 @@ -4352,7 +4378,7 @@ static void xsane_jpeg_embed_scanner_icm
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 @@ -4366,7 +4392,7 @@ static void xsane_jpeg_embed_scanner_icm
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 Index: trunk/src/xsane-viewer.c
231 ===================================================================
232 --- trunk.orig/src/xsane-viewer.c
233 +++ trunk/src/xsane-viewer.c
234 @@ -1795,6 +1795,9 @@ static void xsane_viewer_set_cms_gamut_a
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_a
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_a
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(Viewe
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(Viewe
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,
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,
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 Index: trunk/src/xsane.h
352 ===================================================================
353 --- trunk.orig/src/xsane.h
354 +++ trunk/src/xsane.h
360 +# ifdef HAVE_LIBLCMS2
364 +typedef BYTE cmsUInt8Number;
365 +typedef DWORD cmsUInt32Number;
368 # define cmsHTRANSFORM void *