[babl/wip/pippin/inverted-cmyk: 7/9] lcms experiments



commit 877b77c8fc467182cb95b616122cc955efe183b0
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Nov 1 17:07:22 2018 +0100

    lcms experiments

 babl/Makefile.am     |  5 ++---
 babl/babl-icc.c      | 30 +++++++++++++++++++++++++++++-
 babl/babl-internal.h |  2 ++
 babl/babl-space.c    | 34 ++++++++++++++++++++++++++++++++++
 babl/babl-space.h    | 10 ++++++++++
 configure.ac         | 18 ++++++++++++++++++
 extensions/CMYK.c    |  9 +++++----
 7 files changed, 100 insertions(+), 8 deletions(-)
---
diff --git a/babl/Makefile.am b/babl/Makefile.am
index 98b822b..75345f2 100644
--- a/babl/Makefile.am
+++ b/babl/Makefile.am
@@ -92,18 +92,17 @@ AM_CPPFLAGS =                               \
 lib_LTLIBRARIES= libbabl-@BABL_API_VERSION@.la
 
 libbabl_@BABL_API_VERSION@_la_SOURCES= $(h_sources) $(c_sources)
-libbabl_@BABL_API_VERSION@_la_CFLAGS= $(SSE2_EXTRA_CFLAGS)
+libbabl_@BABL_API_VERSION@_la_CFLAGS= $(SSE2_EXTRA_CFLAGS) $(LCMS_CFLAGS)
 
 libbabl_@BABL_API_VERSION@_la_LIBADD=  \
        base/libbase.la                 \
        @LTLIBOBJS@
 
-libbabl_la_LDFLAGS=                    \
-       $(MATH_LIB) $(THREAD_LIB) $(LOG_LIB)
 
 libbabl_@BABL_API_VERSION@_la_LDFLAGS=                 \
        ${win32_no_undefined}                           \
        $(MATH_LIB) $(THREAD_LIB) $(LOG_LIB)            \
+       $(LCMS_LIBS) \
        -export-symbols $(top_srcdir)/export-symbols    \
        -version-info $(BABL_LIBRARY_VERSION)
 
diff --git a/babl/babl-icc.c b/babl/babl-icc.c
index 1ffe415..9f4fe80 100644
--- a/babl/babl-icc.c
+++ b/babl/babl-icc.c
@@ -16,7 +16,7 @@
  * <https://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#include "../config.h"
 #include "babl-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -827,6 +827,34 @@ babl_space_from_icc (const char   *icc_data,
 
   if (*error)
   {
+#ifdef HAVE_LCMS
+    {
+       ret = _babl_space_for_lcms (icc_data, icc_length);
+       if (ret->space.icc_profile)
+         return ret;
+
+       fprintf (stderr, "warning: %s,.. but we got lcms2\n", *error);
+
+       ret->space.icc_length = icc_length;
+       ret->space.icc_profile = malloc (icc_length);
+       memcpy (ret->space.icc_profile, icc_data, icc_length);
+
+       ret->space.lcms_profile = cmsOpenProfileFromMem(ret->space.icc_profile, ret->space.icc_length);
+       //ret->lcms_profile_rgb = cmsOpenProfileFromMem(ret->space.icc_profile, ret->space.icc_length);
+
+       ret->space.lcms_to_rgba = cmsCreateTransform(ret->space.lcms_profile, TYPE_RGBA_FLT,
+                                              ret->space.lcms_profile, TYPE_RGBA_FLT,
+                                              intent & 7, 0);
+       ret->space.lcms_from_rgba = cmsCreateTransform(ret->space.lcms_profile, TYPE_RGBA_FLT,
+                                                ret->space.lcms_profile, TYPE_RGBA_FLT,
+                                                intent & 7, 0);
+       cmsCloseProfile (ret->space.lcms_profile);
+
+       fprintf (stderr, "did a rig\n");
+       return ret;
+    }
+#endif
+
     babl_free (state);
     return NULL;
   }
diff --git a/babl/babl-internal.h b/babl/babl-internal.h
index 73fe18f..ed91e4d 100644
--- a/babl/babl-internal.h
+++ b/babl/babl-internal.h
@@ -453,5 +453,7 @@ char *babl_space_to_icc (const Babl  *space,
                          const char  *copyright,
                          BablICCFlags flags,
                          int         *icc_length);
+Babl *
+_babl_space_for_lcms (const char *icc_data, int icc_length); // XXX pass profile for dedup?
 
 #endif
diff --git a/babl/babl-space.c b/babl/babl-space.c
index 9a78d38..b4ff1d9 100644
--- a/babl/babl-space.c
+++ b/babl/babl-space.c
@@ -219,6 +219,40 @@ babl_space (const char *name)
   return NULL;
 }
 
+Babl *
+_babl_space_for_lcms (const char *icc_data, int icc_length)
+{
+  int i=0;
+  BablSpace space;
+  space.instance.class_type = BABL_SPACE;
+  space.instance.id         = 0;
+
+  for (i = 0; space_db[i].instance.class_type; i++)
+  {
+    // XXX adjust to use profile directly
+#if 0
+    int offset = ((char*)&space_db[i].xr) - (char*)(&space_db[i]);
+    int size   = ((char*)&space_db[i].trc) + sizeof(space_db[i].trc) - ((char*)&space_db[i].xr);
+
+    if (memcmp ((char*)(&space_db[i]) + offset, ((char*)&space) + offset, size)==0)
+      {
+        return (void*)&space_db[i];
+      }
+#endif
+  }
+  if (i >= MAX_SPACES-1)
+  {
+    babl_log ("too many BablSpaces");
+    return NULL;
+  }
+
+  space_db[i]=space;
+  space_db[i].instance.name = space_db[i].name;
+  snprintf (space_db[i].name, sizeof (space_db[i].name), "space-lcms-%i", i);
+
+  return (Babl*)&space_db[i];
+}
+
 const Babl *
 babl_space_from_rgbxyz_matrix (const char *name,
                                double wx, double wy, double wz,
diff --git a/babl/babl-space.h b/babl/babl-space.h
index 35fd2c3..7e89287 100644
--- a/babl/babl-space.h
+++ b/babl/babl-space.h
@@ -19,11 +19,16 @@
 #ifndef _BABL_SPACE_H
 #define _BABL_SPACE_H
 
+#include "../config.h"
 #include <math.h>
 #include <string.h>
 #include "base/util.h"
 #include "babl-matrix.h"
 
+#ifdef HAVE_LCMS
+#include <lcms2.h>
+#endif
+
 BABL_CLASS_DECLARE (space);
 
 typedef struct
@@ -62,6 +67,11 @@ typedef struct
   char *icc_profile;
   int   icc_length;
 
+#ifdef HAVE_LCMS
+  cmsHPROFILE   lcms_profile;
+  cmsHTRANSFORM lcms_to_rgba;
+  cmsHTRANSFORM lcms_from_rgba;
+#endif
 } BablSpace;
 
 
diff --git a/configure.ac b/configure.ac
index e9cce3e..847067a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -215,6 +215,24 @@ case "$target_or_host" in
     ;;
 esac
 
+################
+# Check for lcms
+################
+
+AC_ARG_WITH(lcms, [  --without-lcms          build without lcms support])
+
+have_lcms="no (lcms support disabled)"
+if test "x$with_lcms" != xno; then
+  have_lcms=yes
+  PKG_CHECK_MODULES(LCMS, lcms2 >= lcms_required_version,
+    AC_DEFINE(HAVE_LCMS, 1, [Define to 1 if lcms is available])
+    LCMS='lcms$(EXEEXT)',
+    have_lcms="no (lcms not found or unusable)")
+fi
+
+AC_SUBST(LCMS)
+AM_CONDITIONAL(HAVE_LCMS, test "x$have_lcms" = xyes)
+
 
 ############################
 # Check how to find plug-ins
diff --git a/extensions/CMYK.c b/extensions/CMYK.c
index b16f8be..45e5192 100644
--- a/extensions/CMYK.c
+++ b/extensions/CMYK.c
@@ -18,8 +18,11 @@
 
 /* This file define the "cmy" and "cmyk" models and related formats these
  * are CMYK formats withthe components stored so that 0 means full coverage
- * and 1.0 means no coverage, making additive compositing/blending work
- * one thep pixel data.
+ * and 1.0 means no coverage which makes additive compositing/blending work
+ * like as if it was RGB
+
+ * conversions should be made with reference to the icc profile in the space
+ * using lcms2 for handling.
  */
 
 #include "config.h"
@@ -97,8 +100,6 @@ int init (void);
 int
 init (void)
 {
-
-
   babl_component_new ("cyan", NULL);
   babl_component_new ("yellow", NULL);
   babl_component_new ("magenta", NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]