Blame SOURCES/xsane-0.999-lcms2.patch

6d3471
From 30af0e2edbf061b71bed9536d826894449f0390d Mon Sep 17 00:00:00 2001
6d3471
From: Nils Philippsen <nils@redhat.com>
6d3471
Date: Mon, 23 Sep 2013 16:11:31 +0200
6d3471
Subject: [PATCH] patch: lcms2
6d3471
6d3471
Squashed commit of the following:
6d3471
6d3471
commit f975accf7e1a08438b63580ea848457d373200f5
6d3471
Author: Nils Philippsen <nils@redhat.com>
6d3471
Date:   Mon Sep 23 14:53:45 2013 +0200
6d3471
6d3471
    Add support for lcms 2.x.
6d3471
---
6d3471
 configure.in        | 22 ++++++++++++++----
6d3471
 include/config.h.in |  8 ++++++-
6d3471
 src/xsane-preview.c |  6 +++--
6d3471
 src/xsane-save.c    | 38 ++++++++++++++++++++++++++-----
6d3471
 src/xsane-viewer.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++---
6d3471
 src/xsane.h         |  8 ++++++-
6d3471
 6 files changed, 130 insertions(+), 17 deletions(-)
6d3471
6d3471
diff --git a/configure.in b/configure.in
6d3471
index df7b114..3659c97 100644
6d3471
--- a/configure.in
6d3471
+++ b/configure.in
6d3471
@@ -130,7 +130,17 @@ if test "${USE_TIFF}" = "yes"; then
6d3471
 fi
6d3471
 
6d3471
 if test "${USE_LCMS}" = "yes"; then
6d3471
-  AC_CHECK_LIB(lcms, cmsOpenProfileFromFile)
6d3471
+  AC_SEARCH_LIBS(cmsOpenProfileFromFile, [lcms2 lcms])
6d3471
+  if test "${ac_cv_search_cmsOpenProfileFromFile}" != "no"; then
6d3471
+    AC_DEFINE(HAVE_LIBLCMS, 1, [Define if LCMS is to be used.])
6d3471
+  fi
6d3471
+  if test "${ac_cv_search_cmsOpenProfileFromFile}" == "-llcms2"; then
6d3471
+    AC_DEFINE(HAVE_LIBLCMS2, 1, [Define if you have liblcms2.])
6d3471
+  else
6d3471
+    if test "${ac_cv_search_cmsOpenProfileFromFile}" == "-llcms"; then
6d3471
+      AC_DEFINE(HAVE_LIBLCMS1, 1, [Define if you have liblcms.])
6d3471
+    fi
6d3471
+  fi
6d3471
 fi
6d3471
 
6d3471
 dnl Checks for library functions.
6d3471
@@ -294,10 +304,14 @@ else
6d3471
   echo "* - PNG  support deactivated                                   *"
6d3471
 fi
6d3471
 
6d3471
-if test "${ac_cv_lib_lcms_cmsOpenProfileFromFile}" = "yes"; then
6d3471
-  echo "* - LCMS (color management) support activated                  *"
6d3471
+if test "${ac_cv_search_cmsOpenProfileFromFile}" = "-llcms2"; then
6d3471
+  echo "* - LCMS (color management) support activated (lcms2)          *"
6d3471
 else
6d3471
-  echo "* - LCMS (color management) support deactivated                *"
6d3471
+  if test "${ac_cv_search_cmsOpenProfileFromFile}" = "-llcms"; then
6d3471
+    echo "* - LCMS (color management) support activated (lcms)           *"
6d3471
+  else
6d3471
+    echo "* - LCMS (color management) support deactivated                *"
6d3471
+  fi
6d3471
 fi
6d3471
 
6d3471
 echo "*                                                              *"
6d3471
diff --git a/include/config.h.in b/include/config.h.in
6d3471
index ecc9637..f9a3e40 100755
6d3471
--- a/include/config.h.in
6d3471
+++ b/include/config.h.in
6d3471
@@ -290,9 +290,15 @@
6d3471
 /* Define if you have libtiff.  */
6d3471
 #undef HAVE_LIBTIFF
6d3471
 
6d3471
-/* Define if you have liblcms.  */
6d3471
+/* Define if LCMS is to be used. */
6d3471
 #undef HAVE_LIBLCMS
6d3471
 
6d3471
+/* Define if you have liblcms. */
6d3471
+#undef HAVE_LIBLCMS1
6d3471
+
6d3471
+/* Define if you have liblcms2. */
6d3471
+#undef HAVE_LIBLCMS2
6d3471
+
6d3471
 #ifndef HAVE_STRNCASECMP
6d3471
   /* OS/2 needs this */
6d3471
 # define strncasecmp(a, b, c) strnicmp(a, b, c)
6d3471
diff --git a/src/xsane-preview.c b/src/xsane-preview.c
6d3471
index 6327ca7..6eaf687 100644
6d3471
--- a/src/xsane-preview.c
6d3471
+++ b/src/xsane-preview.c
6d3471
@@ -6346,8 +6346,8 @@ int preview_do_color_correction(Preview *p)
6d3471
  cmsHPROFILE hOutProfile = NULL;
6d3471
  cmsHPROFILE hProofProfile = NULL;
6d3471
  cmsHTRANSFORM hTransform = NULL;
6d3471
- DWORD input_format, output_format;
6d3471
- DWORD cms_flags = 0;
6d3471
+ cmsUInt32Number input_format, output_format;
6d3471
+ cmsUInt32Number cms_flags = 0;
6d3471
  int proof = 0;
6d3471
  char *cms_proof_icm_profile = NULL;
6d3471
  int linesize = 0;
6d3471
@@ -6355,7 +6355,9 @@ int preview_do_color_correction(Preview *p)
6d3471
 
6d3471
   DBG(DBG_proc, "preview_do_color_correction\n");
6d3471
 
6d3471
+#ifdef HAVE_LIBLCMS1
6d3471
   cmsErrorAction(LCMS_ERROR_SHOW);
6d3471
+#endif
6d3471
 
6d3471
   if (preferences.cms_bpc)
6d3471
   {
6d3471
diff --git a/src/xsane-save.c b/src/xsane-save.c
6d3471
index 75e0a63..2d0e44b 100644
6d3471
--- a/src/xsane-save.c
6d3471
+++ b/src/xsane-save.c
6d3471
@@ -832,9 +832,9 @@ cmsHTRANSFORM xsane_create_cms_transform(Image_info *image_info, int cms_functio
6d3471
  cmsHPROFILE hInProfile = NULL;
6d3471
  cmsHPROFILE hOutProfile = NULL;
6d3471
  cmsHTRANSFORM hTransform = NULL;
6d3471
- DWORD cms_input_format;
6d3471
- DWORD cms_output_format;
6d3471
- DWORD cms_flags = 0;
6d3471
+ cmsUInt32Number cms_input_format;
6d3471
+ cmsUInt32Number cms_output_format;
6d3471
+ cmsUInt32Number cms_flags = 0;
6d3471
 
6d3471
   if (cms_function == XSANE_CMS_FUNCTION_EMBED_SCANNER_ICM_PROFILE)
6d3471
   {
6d3471
@@ -843,7 +843,9 @@ cmsHTRANSFORM xsane_create_cms_transform(Image_info *image_info, int cms_functio
6d3471
 
6d3471
   DBG(DBG_info, "Prepare CMS transform\n");
6d3471
 
6d3471
+#ifdef HAVE_LIBLCMS1
6d3471
   cmsErrorAction(LCMS_ERROR_SHOW);
6d3471
+#endif
6d3471
 
6d3471
   if (cms_bpc)
6d3471
   {
6d3471
@@ -890,10 +892,18 @@ cmsHTRANSFORM xsane_create_cms_transform(Image_info *image_info, int cms_functio
6d3471
     if (image_info->channels == 1) /* == 1 (grayscale) */
6d3471
     {
6d3471
 #if 1 /* xxx oli */
6d3471
+# ifdef HAVE_LIBLCMS2
6d3471
+     cmsToneCurve *Gamma = cmsBuildGamma(NULL, 2.2);
6d3471
+# else
6d3471
      LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2);
6d3471
+# endif
6d3471
 
6d3471
       hOutProfile = cmsCreateGrayProfile(cmsD50_xyY(), Gamma);
6d3471
+# ifdef HAVE_LIBLCMS2
6d3471
+      cmsFreeToneCurve(Gamma);
6d3471
+# else
6d3471
       cmsFreeGamma(Gamma);
6d3471
+# endif
6d3471
 #endif
6d3471
     }
6d3471
     else
6d3471
@@ -2896,7 +2906,11 @@ static int xsane_write_CSA(FILE *outfile, char *input_profile, int intent)
6d3471
     return -1;
6d3471
   }
6d3471
 
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+  n = cmsGetPostScriptCSA(NULL, hProfile, intent, 0, NULL, 0);
6d3471
+#else
6d3471
   n = cmsGetPostScriptCSA(hProfile, intent, NULL, 0);
6d3471
+#endif
6d3471
   if (n == 0)
6d3471
   {
6d3471
     return -2;
6d3471
@@ -2908,7 +2922,11 @@ static int xsane_write_CSA(FILE *outfile, char *input_profile, int intent)
6d3471
     return -3;
6d3471
   }
6d3471
 
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+  cmsGetPostScriptCSA(NULL, hProfile, intent, 0, buffer, n);
6d3471
+#else
6d3471
   cmsGetPostScriptCSA(hProfile, intent, buffer, n);
6d3471
+#endif
6d3471
   buffer[n] = 0;
6d3471
 
6d3471
   fprintf(outfile, "%s", buffer);
6d3471
@@ -2927,7 +2945,7 @@ static int xsane_write_CRD(FILE *outfile, char *output_profile, int intent, int
6d3471
  cmsHPROFILE hProfile;
6d3471
  size_t n;
6d3471
  char* buffer;
6d3471
- DWORD flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
6d3471
+ cmsUInt32Number flags = cmsFLAGS_NODEFAULTRESOURCEDEF;
6d3471
 
6d3471
   hProfile = cmsOpenProfileFromFile(output_profile, "r");
6d3471
   if (!hProfile)
6d3471
@@ -2940,7 +2958,11 @@ static int xsane_write_CRD(FILE *outfile, char *output_profile, int intent, int
6d3471
     flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
6d3471
   }
6d3471
 
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+  n = cmsGetPostScriptCRD(NULL, hProfile, intent, flags, NULL, 0);
6d3471
+#else
6d3471
   n = cmsGetPostScriptCRDEx(hProfile, intent, flags, NULL, 0);
6d3471
+#endif
6d3471
   if (n == 0)
6d3471
   {
6d3471
     return -2;
6d3471
@@ -2952,7 +2974,11 @@ static int xsane_write_CRD(FILE *outfile, char *output_profile, int intent, int
6d3471
     return -3;
6d3471
   }
6d3471
 
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+  cmsGetPostScriptCRD(NULL, hProfile, intent, flags, buffer, n);
6d3471
+#else
6d3471
   cmsGetPostScriptCRDEx(hProfile, intent, flags, buffer, n);
6d3471
+#endif
6d3471
   buffer[n] = 0;
6d3471
 
6d3471
   fprintf(outfile, "%s", buffer);
6d3471
@@ -4349,7 +4375,7 @@ static void xsane_jpeg_embed_scanner_icm_profile(j_compress_ptr cinfo_ptr, const
6d3471
 {
6d3471
  FILE *icm_profile;
6d3471
  size_t size, embed_len;
6d3471
- LPBYTE embed_buffer;
6d3471
+ cmsUInt8Number *embed_buffer;
6d3471
 
6d3471
   DBG(DBG_proc, "xsane_jpeg_embed_scanner_icm_profile(%s)\n", icm_filename);
6d3471
 
6d3471
@@ -4363,7 +4389,7 @@ static void xsane_jpeg_embed_scanner_icm_profile(j_compress_ptr cinfo_ptr, const
6d3471
   size = ftell(icm_profile);
6d3471
   fseek(icm_profile, 0, SEEK_SET);
6d3471
 
6d3471
-  embed_buffer = (LPBYTE) malloc(size + 1);
6d3471
+  embed_buffer = (cmsUInt8Number *) malloc(size + 1);
6d3471
   if (embed_buffer)
6d3471
   {
6d3471
     embed_len = fread(embed_buffer, 1, size, icm_profile);
6d3471
diff --git a/src/xsane-viewer.c b/src/xsane-viewer.c
6d3471
index 69a444d..844c077 100644
6d3471
--- a/src/xsane-viewer.c
6d3471
+++ b/src/xsane-viewer.c
6d3471
@@ -1795,6 +1795,9 @@ static void xsane_viewer_set_cms_gamut_alarm_color_callback(GtkWidget *widget, g
6d3471
 {
6d3471
  Viewer *v = (Viewer *) data;
6d3471
  int val;
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+ cmsUInt16Number alarm_codes[cmsMAXCHANNELS];
6d3471
+#endif
6d3471
 
6d3471
   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);
6d3471
   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);
6d3471
@@ -1811,6 +1814,49 @@ static void xsane_viewer_set_cms_gamut_alarm_color_callback(GtkWidget *widget, g
6d3471
   v->cms_gamut_alarm_color = val;
6d3471
   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(v->cms_gamut_alarm_color_widget[v->cms_gamut_alarm_color]), TRUE);
6d3471
 
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+  switch(v->cms_gamut_alarm_color)
6d3471
+  {
6d3471
+    default:
6d3471
+    case 0: /* black */
6d3471
+      alarm_codes[0] = (cmsUInt16Number) 0;
6d3471
+      alarm_codes[1] = (cmsUInt16Number) 0;
6d3471
+      alarm_codes[2] = (cmsUInt16Number) 0;
6d3471
+     break;
6d3471
+
6d3471
+    case 1: /* gray */
6d3471
+      alarm_codes[0] = (cmsUInt16Number) 128;
6d3471
+      alarm_codes[1] = (cmsUInt16Number) 128;
6d3471
+      alarm_codes[2] = (cmsUInt16Number) 128;
6d3471
+     break;
6d3471
+
6d3471
+    case 2: /* white */
6d3471
+      alarm_codes[0] = (cmsUInt16Number) 255;
6d3471
+      alarm_codes[1] = (cmsUInt16Number) 255;
6d3471
+      alarm_codes[2] = (cmsUInt16Number) 255;
6d3471
+     break;
6d3471
+
6d3471
+    case 3: /* red */
6d3471
+      alarm_codes[0] = (cmsUInt16Number) 255;
6d3471
+      alarm_codes[1] = (cmsUInt16Number) 0;
6d3471
+      alarm_codes[2] = (cmsUInt16Number) 0;
6d3471
+     break;
6d3471
+
6d3471
+    case 4: /* green */
6d3471
+      alarm_codes[0] = (cmsUInt16Number) 0;
6d3471
+      alarm_codes[1] = (cmsUInt16Number) 255;
6d3471
+      alarm_codes[2] = (cmsUInt16Number) 0;
6d3471
+     break;
6d3471
+
6d3471
+    case 5: /* blue */
6d3471
+      alarm_codes[0] = (cmsUInt16Number) 0;
6d3471
+      alarm_codes[1] = (cmsUInt16Number) 0;
6d3471
+      alarm_codes[2] = (cmsUInt16Number) 255;
6d3471
+     break;
6d3471
+  }
6d3471
+
6d3471
+  cmsSetAlarmCodes(alarm_codes);
6d3471
+#else
6d3471
   switch(v->cms_gamut_alarm_color)
6d3471
   {
6d3471
     default:
6d3471
@@ -1838,6 +1884,7 @@ static void xsane_viewer_set_cms_gamut_alarm_color_callback(GtkWidget *widget, g
6d3471
       cmsSetAlarmCodes(0, 0, 255);
6d3471
      break;
6d3471
   }
6d3471
+#endif
6d3471
 
6d3471
   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);
6d3471
   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);
6d3471
@@ -2172,9 +2219,9 @@ static int xsane_viewer_read_image(Viewer *v)
6d3471
  cmsHTRANSFORM hTransform = NULL;
6d3471
  int proof = 0;
6d3471
  char *cms_proof_icm_profile = NULL;
6d3471
- DWORD cms_input_format;
6d3471
- DWORD cms_output_format;
6d3471
- DWORD cms_flags = 0;
6d3471
+ cmsUInt32Number cms_input_format;
6d3471
+ cmsUInt32Number cms_output_format;
6d3471
+ cmsUInt32Number cms_flags = 0;
6d3471
 #endif
6d3471
 
6d3471
   /* open imagefile */
6d3471
@@ -2203,7 +2250,9 @@ static int xsane_viewer_read_image(Viewer *v)
6d3471
 
6d3471
   if ((v->enable_color_management) && (v->cms_enable))
6d3471
   {
6d3471
+#ifdef HAVE_LIBLCMS1
6d3471
     cmsErrorAction(LCMS_ERROR_SHOW);
6d3471
+#endif
6d3471
 
6d3471
     if (v->cms_bpc)
6d3471
     {
6d3471
@@ -2801,6 +2850,9 @@ Viewer *xsane_viewer_new(char *filename, char *selection_filetype, int allow_red
6d3471
  GtkWidget *scrolled_window;
6d3471
  GtkWidget *zoom_option_menu, *zoom_menu, *zoom_menu_item;
6d3471
  int i, selection;
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+ cmsUInt16Number alarm_codes[cmsMAXCHANNELS];
6d3471
+#endif
6d3471
 
6d3471
   DBG(DBG_proc, "viewer_new(%s)\n", filename);
6d3471
 
6d3471
@@ -2830,8 +2882,15 @@ Viewer *xsane_viewer_new(char *filename, char *selection_filetype, int allow_red
6d3471
   v->cms_proofing_intent = INTENT_ABSOLUTE_COLORIMETRIC;
6d3471
   v->cms_gamut_check = 0;
6d3471
   v->cms_gamut_alarm_color = 3; /* red */
6d3471
+#ifdef HAVE_LIBLCMS2
6d3471
+  alarm_codes[0] = (cmsUInt16Number) 255;
6d3471
+  alarm_codes[1] = (cmsUInt16Number) 0;
6d3471
+  alarm_codes[2] = (cmsUInt16Number) 0;
6d3471
+  cmsSetAlarmCodes(alarm_codes);
6d3471
+#else
6d3471
   cmsSetAlarmCodes(255, 0, 0);
6d3471
 #endif
6d3471
+#endif
6d3471
   if (selection_filetype)
6d3471
   {
6d3471
     v->selection_filetype = strdup(selection_filetype);
6d3471
diff --git a/src/xsane.h b/src/xsane.h
6d3471
index 4067d61..adcc0ed 100644
6d3471
--- a/src/xsane.h
6d3471
+++ b/src/xsane.h
6d3471
@@ -70,7 +70,13 @@
6d3471
 #include <gtk/gtk.h>
6d3471
 
6d3471
 #ifdef HAVE_LIBLCMS
6d3471
-# include "lcms.h"
6d3471
+# ifdef HAVE_LIBLCMS2
6d3471
+#  include "lcms2.h"
6d3471
+# else
6d3471
+#  include "lcms.h"
6d3471
+typedef BYTE cmsUInt8Number;
6d3471
+typedef DWORD cmsUInt32Number;
6d3471
+# endif
6d3471
 #else
6d3471
 # define cmsHTRANSFORM void *
6d3471
 #endif
6d3471
-- 
6d3471
1.8.3.1
6d3471