[gtk/wip/otte/color-profiles: 58/60] cms: Add lcms to the build




commit 67aa2ed9dd90bda35a4d326b27eaccf56a2b59c1
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 20 09:24:27 2021 +0200

    cms: Add lcms to the build
    
    ... and use it to generate the ICC profile for sRGB.

 gdk/gdkcolorprofile.c | 16 ++++++++++++++++
 gdk/meson.build       |  1 +
 meson.build           |  2 ++
 3 files changed, 19 insertions(+)
---
diff --git a/gdk/gdkcolorprofile.c b/gdk/gdkcolorprofile.c
index 084031bb7e..549af4ab87 100644
--- a/gdk/gdkcolorprofile.c
+++ b/gdk/gdkcolorprofile.c
@@ -40,11 +40,14 @@
 
 #include "gdkintl.h"
 
+#include <lcms2.h>
+
 struct _GdkColorProfile
 {
   GObject parent_instance;
 
   GBytes *icc_profile;
+  cmsHPROFILE lcms_profile;
 };
 
 struct _GdkColorProfileClass
@@ -109,6 +112,7 @@ gdk_color_profile_dispose (GObject *object)
   GdkColorProfile *self = GDK_COLOR_PROFILE (object);
 
   g_clear_pointer (&self->icc_profile, g_bytes_unref);
+  g_clear_pointer (&self->lcms_profile, cmsCloseProfile);
 
   G_OBJECT_CLASS (gdk_color_profile_parent_class)->dispose (object);
 }
@@ -166,9 +170,21 @@ gdk_color_profile_get_srgb (void)
   if (g_once_init_enter (&srgb_profile))
     {
       GdkColorProfile *new_profile;
+      cmsUInt32Number size;
+      guchar *data;
 
       new_profile = g_object_new (GDK_TYPE_COLOR_PROFILE, NULL);
 
+      new_profile->lcms_profile = cmsCreate_sRGBProfile ();
+      size = 0;
+      if (cmsSaveProfileToMem (new_profile->lcms_profile, NULL, &size))
+        {
+          data = g_malloc (size);
+          if (cmsSaveProfileToMem (new_profile->lcms_profile, data, &size))
+            new_profile->icc_profile = g_bytes_new_take (data, size);
+        }
+      g_assert (new_profile->icc_profile);
+
       g_once_init_leave (&srgb_profile, new_profile);
     }
 
diff --git a/gdk/meson.build b/gdk/meson.build
index d6332a9849..31713fe1a8 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -205,6 +205,7 @@ gdk_deps = [
   fontconfig_dep,
   platform_gio_dep,
   pangocairo_dep,
+  lcms2_dep,
   vulkan_dep,
   png_dep,
   tiff_dep,
diff --git a/meson.build b/meson.build
index e85daf88f5..8b151bcc6e 100644
--- a/meson.build
+++ b/meson.build
@@ -16,6 +16,7 @@ fribidi_req        = '>= 0.19.7'
 cairo_req          = '>= 1.14.0'
 gdk_pixbuf_req     = '>= 2.30.0'
 introspection_req  = '>= 1.39.0'
+lcms2_req          = '>= 2.8'
 wayland_proto_req  = '>= 1.21'
 wayland_req        = '>= 1.16.91'
 graphene_req       = '>= 1.9.1'
@@ -379,6 +380,7 @@ pango_dep      = dependency('pango', version: pango_req,
                             fallback : ['pango', 'libpango_dep'])
 fribidi_dep    = dependency('fribidi', version: fribidi_req,
                             fallback : ['fribidi', 'libfribidi_dep'])
+lcms2_dep      = dependency('lcms2', version: lcms2_req)
 
 # Require PangoFT2 if on X11 or wayland
 require_pangoft2 = wayland_enabled or x11_enabled


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