summaryrefslogtreecommitdiff
path: root/debian/patches/lcms2.patch
blob: 497fccb54113672f75891c26bb7eebbdbdbb3dbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
Subject: Add support for lcms 2
Author: Nils Philippsen <nils@redhat.com>
Bug-Debian: https://bugs.debian.org/745524
Last-Update: Mon, 23 Sep 2013 16:11:31 +0200

---
 configure.in        | 22 ++++++++++++++----
 include/config.h.in |  8 ++++++-
 src/xsane-preview.c |  6 +++--
 src/xsane-save.c    | 38 ++++++++++++++++++++++++++-----
 src/xsane-viewer.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 src/xsane.h         |  8 ++++++-
 6 files changed, 130 insertions(+), 17 deletions(-)

--- a/configure.in
+++ b/configure.in
@@ -130,7 +130,17 @@
 fi
 
 if test "${USE_LCMS}" = "yes"; then
-  AC_CHECK_LIB(lcms, cmsOpenProfileFromFile)
+  AC_SEARCH_LIBS(cmsOpenProfileFromFile, [lcms2 lcms])
+  if test "${ac_cv_search_cmsOpenProfileFromFile}" != "no"; then
+    AC_DEFINE(HAVE_LIBLCMS, 1, [Define if LCMS is to be used.])
+  fi
+  if test "${ac_cv_search_cmsOpenProfileFromFile}" == "-llcms2"; then
+    AC_DEFINE(HAVE_LIBLCMS2, 1, [Define if you have liblcms2.])
+  else
+    if test "${ac_cv_search_cmsOpenProfileFromFile}" == "-llcms"; then
+      AC_DEFINE(HAVE_LIBLCMS1, 1, [Define if you have liblcms.])
+    fi
+  fi
 fi
 
 dnl Checks for library functions.
@@ -294,10 +304,14 @@
   echo "* - PNG  support deactivated                                   *"
 fi
 
-if test "${ac_cv_lib_lcms_cmsOpenProfileFromFile}" = "yes"; then
-  echo "* - LCMS (color management) support activated                  *"
+if test "${ac_cv_search_cmsOpenProfileFromFile}" = "-llcms2"; then
+  echo "* - LCMS (color management) support activated (lcms2)          *"
 else
-  echo "* - LCMS (color management) support deactivated                *"
+  if test "${ac_cv_search_cmsOpenProfileFromFile}" = "-llcms"; then
+    echo "* - LCMS (color management) support activated (lcms)           *"
+  else
+    echo "* - LCMS (color management) support deactivated                *"
+  fi
 fi
 
 echo "*                                                              *"
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -290,9 +290,15 @@
 /* Define if you have libtiff.  */
 #undef HAVE_LIBTIFF
 
-/* Define if you have liblcms.  */
+/* Define if LCMS is to be used. */
 #undef HAVE_LIBLCMS
 
+/* Define if you have liblcms. */
+#undef HAVE_LIBLCMS1
+
+/* Define if you have liblcms2. */
+#undef HAVE_LIBLCMS2
+
 #ifndef HAVE_STRNCASECMP
   /* OS/2 needs this */
 # define strncasecmp(a, b, c) strnicmp(a, b, c)
--- a/src/xsane-preview.c
+++ b/src/xsane-preview.c
@@ -6346,8 +6346,8 @@
  cmsHPROFILE hOutProfile = NULL;
  cmsHPROFILE hProofProfile = NULL;
  cmsHTRANSFORM hTransform = NULL;
- DWORD input_format, output_format;
- DWORD cms_flags = 0;
+ cmsUInt32Number input_format, output_format;
+ cmsUInt32Number cms_flags = 0;
  int proof = 0;
  char *cms_proof_icm_profile = NULL;
  int linesize = 0;
@@ -6355,7 +6355,9 @@
 
   DBG(DBG_proc, "preview_do_color_correction\n");
 
+#ifdef HAVE_LIBLCMS1
   cmsErrorAction(LCMS_ERROR_SHOW);
+#endif
 
   if (preferences.cms_bpc)
   {
--- a/src/xsane-save.c
+++ b/src/xsane-save.c
@@ -832,9 +832,9 @@
  cmsHPROFILE hInProfile = NULL;
  cmsHPROFILE hOutProfile = NULL;
  cmsHTRANSFORM hTransform = NULL;
- DWORD cms_input_format;
- DWORD cms_output_format;
- DWORD cms_flags = 0;
+ cmsUInt32Number cms_input_format;
+ cmsUInt32Number cms_output_format;
+ cmsUInt32Number cms_flags = 0;
 
   if (cms_function == XSANE_CMS_FUNCTION_EMBED_SCANNER_ICM_PROFILE)
   {
@@ -843,7 +843,9 @@
 
   DBG(DBG_info, "Prepare CMS transform\n");
 
+#ifdef HAVE_LIBLCMS1
   cmsErrorAction(LCMS_ERROR_SHOW);
+#endif
 
   if (cms_bpc)
   {
@@ -890,10 +892,18 @@
     if (image_info->channels == 1) /* == 1 (grayscale) */
     {
 #if 1 /* xxx oli */
+# ifdef HAVE_LIBLCMS2
+     cmsToneCurve *Gamma = cmsBuildGamma(NULL, 2.2);
+# else
      LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2);
+# endif
 
       hOutProfile = cmsCreateGrayProfile(cmsD50_xyY(), Gamma);
+# ifdef HAVE_LIBLCMS2
+      cmsFreeToneCurve(Gamma);
+# else
       cmsFreeGamma(Gamma);
+# endif
 #endif
     }
     else
@@ -2904,7 +2914,11 @@
     return -1;
   }
 
+#ifdef HAVE_LIBLCMS2
+  n = cmsGetPostScriptCSA(NULL, hProfile, intent, 0, NULL, 0);
+#else
   n = cmsGetPostScriptCSA(hProfile, intent, NULL, 0);
+#endif
   if (n == 0)
   {
     return -2;
@@ -2916,7 +2930,11 @@
     return -3;
   }
 
+#ifdef HAVE_LIBLCMS2
+  cmsGetPostScriptCSA(NULL, hProfile, intent, 0, buffer, n);
+#else
   cmsGetPostScriptCSA(hProfile, intent, buffer, n);
+#endif
   buffer[n] = 0;
 
   fprintf(outfile, "%s", buffer);
@@ -2935,7 +2953,7 @@
  cmsHPROFILE hProfile;
  size_t n;
  char* buffer;
- DWORD flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
+ cmsUInt32Number flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
 
   hProfile = cmsOpenProfileFromFile(output_profile, "r");
   if (!hProfile)
@@ -2948,7 +2966,11 @@
     flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
   }
 
+#ifdef HAVE_LIBLCMS2
+  n = cmsGetPostScriptCRD(NULL, hProfile, intent, flags, NULL, 0);
+#else
   n = cmsGetPostScriptCRDEx(hProfile, intent, flags, NULL, 0);
+#endif
   if (n == 0)
   {
     return -2;
@@ -2960,7 +2982,11 @@
     return -3;
   }
 
+#ifdef HAVE_LIBLCMS2
+  cmsGetPostScriptCRD(NULL, hProfile, intent, flags, buffer, n);
+#else
   cmsGetPostScriptCRDEx(hProfile, intent, flags, buffer, n);
+#endif
   buffer[n] = 0;
 
   fprintf(outfile, "%s", buffer);
@@ -4352,7 +4378,7 @@
 {
  FILE *icm_profile;
  size_t size, embed_len;
- LPBYTE embed_buffer;
+ cmsUInt8Number *embed_buffer;
 
   DBG(DBG_proc, "xsane_jpeg_embed_scanner_icm_profile(%s)\n", icm_filename);
 
@@ -4366,7 +4392,7 @@
   size = ftell(icm_profile);
   fseek(icm_profile, 0, SEEK_SET);
 
-  embed_buffer = (LPBYTE) malloc(size + 1);
+  embed_buffer = (cmsUInt8Number *) malloc(size + 1);
   if (embed_buffer)
   {
     embed_len = fread(embed_buffer, 1, size, icm_profile);
--- a/src/xsane-viewer.c
+++ b/src/xsane-viewer.c
@@ -1795,6 +1795,9 @@
 {
  Viewer *v = (Viewer *) data;
  int val;
+#ifdef HAVE_LIBLCMS2
+ cmsUInt16Number alarm_codes[cmsMAXCHANNELS];
+#endif
 
   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);
   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);
@@ -1811,6 +1814,49 @@
   v->cms_gamut_alarm_color = val;
   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(v->cms_gamut_alarm_color_widget[v->cms_gamut_alarm_color]), TRUE);
 
+#ifdef HAVE_LIBLCMS2
+  switch(v->cms_gamut_alarm_color)
+  {
+    default:
+    case 0: /* black */
+      alarm_codes[0] = (cmsUInt16Number) 0;
+      alarm_codes[1] = (cmsUInt16Number) 0;
+      alarm_codes[2] = (cmsUInt16Number) 0;
+     break;
+
+    case 1: /* gray */
+      alarm_codes[0] = (cmsUInt16Number) 128;
+      alarm_codes[1] = (cmsUInt16Number) 128;
+      alarm_codes[2] = (cmsUInt16Number) 128;
+     break;
+
+    case 2: /* white */
+      alarm_codes[0] = (cmsUInt16Number) 255;
+      alarm_codes[1] = (cmsUInt16Number) 255;
+      alarm_codes[2] = (cmsUInt16Number) 255;
+     break;
+
+    case 3: /* red */
+      alarm_codes[0] = (cmsUInt16Number) 255;
+      alarm_codes[1] = (cmsUInt16Number) 0;
+      alarm_codes[2] = (cmsUInt16Number) 0;
+     break;
+
+    case 4: /* green */
+      alarm_codes[0] = (cmsUInt16Number) 0;
+      alarm_codes[1] = (cmsUInt16Number) 255;
+      alarm_codes[2] = (cmsUInt16Number) 0;
+     break;
+
+    case 5: /* blue */
+      alarm_codes[0] = (cmsUInt16Number) 0;
+      alarm_codes[1] = (cmsUInt16Number) 0;
+      alarm_codes[2] = (cmsUInt16Number) 255;
+     break;
+  }
+
+  cmsSetAlarmCodes(alarm_codes);
+#else
   switch(v->cms_gamut_alarm_color)
   {
     default:
@@ -1838,6 +1884,7 @@
       cmsSetAlarmCodes(0, 0, 255);
      break;
   }
+#endif
 
   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);
   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);
@@ -2172,9 +2219,9 @@
  cmsHTRANSFORM hTransform = NULL;
  int proof = 0;
  char *cms_proof_icm_profile = NULL;
- DWORD cms_input_format;
- DWORD cms_output_format;
- DWORD cms_flags = 0;
+ cmsUInt32Number cms_input_format;
+ cmsUInt32Number cms_output_format;
+ cmsUInt32Number cms_flags = 0;
 #endif
 
   /* open imagefile */
@@ -2203,7 +2250,9 @@
 
   if ((v->enable_color_management) && (v->cms_enable))
   {
+#ifdef HAVE_LIBLCMS1
     cmsErrorAction(LCMS_ERROR_SHOW);
+#endif
 
     if (v->cms_bpc)
     {
@@ -2801,6 +2850,9 @@
  GtkWidget *scrolled_window;
  GtkWidget *zoom_option_menu, *zoom_menu, *zoom_menu_item;
  int i, selection;
+#ifdef HAVE_LIBLCMS2
+ cmsUInt16Number alarm_codes[cmsMAXCHANNELS];
+#endif
 
   DBG(DBG_proc, "viewer_new(%s)\n", filename);
 
@@ -2830,8 +2882,15 @@
   v->cms_proofing_intent = INTENT_ABSOLUTE_COLORIMETRIC;
   v->cms_gamut_check = 0;
   v->cms_gamut_alarm_color = 3; /* red */
+#ifdef HAVE_LIBLCMS2
+  alarm_codes[0] = (cmsUInt16Number) 255;
+  alarm_codes[1] = (cmsUInt16Number) 0;
+  alarm_codes[2] = (cmsUInt16Number) 0;
+  cmsSetAlarmCodes(alarm_codes);
+#else
   cmsSetAlarmCodes(255, 0, 0);
 #endif
+#endif
   if (selection_filetype)
   {
     v->selection_filetype = strdup(selection_filetype);
--- a/src/xsane.h
+++ b/src/xsane.h
@@ -70,7 +70,13 @@
 #include <gtk/gtk.h>
 
 #ifdef HAVE_LIBLCMS
-# include "lcms.h"
+# ifdef HAVE_LIBLCMS2
+#  include "lcms2.h"
+# else
+#  include "lcms.h"
+typedef BYTE cmsUInt8Number;
+typedef DWORD cmsUInt32Number;
+# endif
 #else
 # define cmsHTRANSFORM void *
 #endif