[gimp] modules: rename color-selector-cmyk-lcms.c to color-selector-cmyk.c



commit 71b189e4da10969f5376d4e4fd418a137cef0722
Author: Michael Natterer <mitch gimp org>
Date:   Sun Nov 3 22:06:51 2013 +0100

    modules: rename color-selector-cmyk-lcms.c to color-selector-cmyk.c
    
    overwriting the old color-selector-cmyk.c

 modules/Makefile.am                |    2 +-
 modules/color-selector-cmyk-lcms.c |  474 ------------------------------------
 modules/color-selector-cmyk.c      |  332 ++++++++++++++++++++-----
 po-libgimp/POTFILES.in             |    1 -
 4 files changed, 272 insertions(+), 537 deletions(-)
---
diff --git a/modules/Makefile.am b/modules/Makefile.am
index 9b000b8..c097cd2 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -51,7 +51,7 @@ color_selector_libadd = $(libgimpcolor) $(modules_libadd)
 display_filter_libadd = $(libgimpbase) $(libgimpconfig) $(libgimpcolor) $(modules_libadd) $(GEGL_LIBS)
 controller_libadd = $(modules_libadd)
 
-libcolor_selector_cmyk_la_SOURCES = color-selector-cmyk-lcms.c
+libcolor_selector_cmyk_la_SOURCES = color-selector-cmyk.c
 libcolor_selector_cmyk_la_LDFLAGS = -avoid-version -module $(no_undefined)
 libcolor_selector_cmyk_la_CFLAGS = $(LCMS_CFLAGS)
 libcolor_selector_cmyk_la_LIBADD = $(libgimpconfig) $(color_selector_libadd) $(LCMS_LIBS)
diff --git a/modules/color-selector-cmyk.c b/modules/color-selector-cmyk.c
index 3e55d10..20eb3f9 100644
--- a/modules/color-selector-cmyk.c
+++ b/modules/color-selector-cmyk.c
@@ -1,5 +1,5 @@
-/* GIMP CMYK ColorSelector
- * Copyright (C) 2003  Sven Neumann <sven gimp org>
+/* GIMP CMYK ColorSelector using littleCMS
+ * Copyright (C) 2006  Sven Neumann <sven gimp org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,10 +17,15 @@
 
 #include "config.h"
 
+#include <glib.h>  /* lcms.h uses the "inline" keyword */
+
+#include <lcms2.h>
+
 #include <gegl.h>
 #include <gtk/gtk.h>
 
 #include "libgimpcolor/gimpcolor.h"
+#include "libgimpconfig/gimpconfig.h"
 #include "libgimpmodule/gimpmodule.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -43,9 +48,15 @@ struct _ColorselCmyk
 {
   GimpColorSelector  parent_instance;
 
+  GimpColorConfig   *config;
+  cmsHTRANSFORM      rgb2cmyk;
+  cmsHTRANSFORM      cmyk2rgb;
+
   GimpCMYK           cmyk;
-  gdouble            pullout;
-  GtkAdjustment     *adj[5];
+  GtkAdjustment     *adj[4];
+  GtkWidget         *name_label;
+
+  gboolean           in_destruction;
 };
 
 struct _ColorselCmykClass
@@ -54,25 +65,29 @@ struct _ColorselCmykClass
 };
 
 
-GType         colorsel_cmyk_get_type       (void);
+static GType  colorsel_cmyk_get_type       (void);
+
+static void   colorsel_cmyk_dispose        (GObject           *object);
 
 static void   colorsel_cmyk_set_color      (GimpColorSelector *selector,
                                             const GimpRGB     *rgb,
                                             const GimpHSV     *hsv);
+static void   colorsel_cmyk_set_config     (GimpColorSelector *selector,
+                                            GimpColorConfig   *config);
+
 static void   colorsel_cmyk_adj_update     (GtkAdjustment     *adj,
                                             ColorselCmyk      *module);
-static void   colorsel_cmyk_pullout_update (GtkAdjustment     *adj,
-                                            ColorselCmyk      *module);
+static void   colorsel_cmyk_config_changed (ColorselCmyk      *module);
 
 
 static const GimpModuleInfo colorsel_cmyk_info =
 {
   GIMP_MODULE_ABI_VERSION,
-  N_("CMYK color selector"),
+  N_("CMYK color selector (using color profile)"),
   "Sven Neumann <sven gimp org>",
-  "v0.2",
-  "(c) 2003, released under the GPL",
-  "July 2003"
+  "v0.1",
+  "(c) 2006, released under the GPL",
+  "September 2006"
 };
 
 
@@ -97,12 +112,16 @@ gimp_module_register (GTypeModule *module)
 static void
 colorsel_cmyk_class_init (ColorselCmykClass *klass)
 {
+  GObjectClass           *object_class   = G_OBJECT_CLASS (klass);
   GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
 
-  selector_class->name      = _("CMYK");
-  selector_class->help_id   = "gimp-colorselector-cmyk";
-  selector_class->stock_id  = GTK_STOCK_PRINT;  /* FIXME */
-  selector_class->set_color = colorsel_cmyk_set_color;
+  object_class->dispose      = colorsel_cmyk_dispose;
+
+  selector_class->name       = _("CMYK");
+  selector_class->help_id    = "gimp-colorselector-cmyk";
+  selector_class->stock_id   = GTK_STOCK_PRINT;  /* FIXME */
+  selector_class->set_color  = colorsel_cmyk_set_color;
+  selector_class->set_config = colorsel_cmyk_set_config;
 }
 
 static void
@@ -114,8 +133,6 @@ static void
 colorsel_cmyk_init (ColorselCmyk *module)
 {
   GtkWidget *table;
-  GtkWidget *label;
-  GtkWidget *spinbutton;
   GtkObject *adj;
   gint       i;
 
@@ -138,16 +155,20 @@ colorsel_cmyk_init (ColorselCmyk *module)
     N_("Black")
   };
 
-  module->pullout = 1.0;
+  module->config   = NULL;
+  module->rgb2cmyk = NULL;
+  module->cmyk2rgb = NULL;
 
-  table = gtk_table_new (5, 4, FALSE);
+  gtk_box_set_spacing (GTK_BOX (module), 6);
+
+  table = gtk_table_new (4, 4, FALSE);
 
   gtk_table_set_row_spacings (GTK_TABLE (table), 1);
   gtk_table_set_col_spacings (GTK_TABLE (table), 2);
   gtk_table_set_col_spacing (GTK_TABLE (table), 0, 0);
-  gtk_table_set_row_spacing (GTK_TABLE (table), 3, 4);
 
-  gtk_box_pack_start (GTK_BOX (module), table, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (module), table, FALSE, FALSE, 0);
+  gtk_widget_show (table);
 
   for (i = 0; i < 4; i++)
     {
@@ -169,34 +190,26 @@ colorsel_cmyk_init (ColorselCmyk *module)
       module->adj[i] = GTK_ADJUSTMENT (adj);
     }
 
-  label = gtk_label_new_with_mnemonic (_("Black _pullout:"));
-  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
-  gtk_table_attach (GTK_TABLE (table), label,
-                    1, 3, i, i + 1,
-                    GTK_FILL, GTK_FILL, 0, 0);
-  gtk_widget_show (label);
-
-  spinbutton = gimp_spin_button_new (&adj, module->pullout * 100.0,
-                                     0.0, 100.0, 1.0, 10.0, 0.0,
-                                     1.0, 0);
-
-  gtk_table_attach (GTK_TABLE (table), spinbutton,
-                    3, 4, i, i + 1,
-                    GTK_SHRINK, GTK_SHRINK, 0, 0);
-  gtk_widget_show (spinbutton);
+  module->name_label = gtk_label_new (NULL);
+  gtk_misc_set_alignment (GTK_MISC (module->name_label), 0.0, 0.5);
+  gtk_label_set_ellipsize (GTK_LABEL (module->name_label), PANGO_ELLIPSIZE_END);
+  gimp_label_set_attributes (GTK_LABEL (module->name_label),
+                             PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
+                             -1);
+  gtk_box_pack_start (GTK_BOX (module), module->name_label, FALSE, FALSE, 0);
+  gtk_widget_show (module->name_label);
+}
 
-  gimp_help_set_help_data (spinbutton,
-                           _("The percentage of black to pull out "
-                             "of the colored inks."), NULL);
-  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
+static void
+colorsel_cmyk_dispose (GObject *object)
+{
+  ColorselCmyk *module = COLORSEL_CMYK (object);
 
-  g_signal_connect (adj, "value-changed",
-                    G_CALLBACK (colorsel_cmyk_pullout_update),
-                    module);
+  module->in_destruction = TRUE;
 
-  module->adj[i] = GTK_ADJUSTMENT (adj);
+  colorsel_cmyk_set_config (GIMP_COLOR_SELECTOR (object), NULL);
 
-  gtk_widget_show (table);
+  G_OBJECT_CLASS (colorsel_cmyk_parent_class)->dispose (object);
 }
 
 static void
@@ -205,13 +218,77 @@ colorsel_cmyk_set_color (GimpColorSelector *selector,
                          const GimpHSV     *hsv)
 {
   ColorselCmyk *module = COLORSEL_CMYK (selector);
+  gdouble       values[4];
+  gint          i;
+
+  if (module->rgb2cmyk)
+    {
+      gdouble rgb_values[3];
+      gdouble cmyk_values[4];
+
+      rgb_values[0] = rgb->r;
+      rgb_values[1] = rgb->g;
+      rgb_values[2] = rgb->b;
+
+      cmsDoTransform (module->rgb2cmyk, rgb_values, cmyk_values, 1);
+
+      module->cmyk.c = cmyk_values[0] / 100.0;
+      module->cmyk.m = cmyk_values[1] / 100.0;
+      module->cmyk.y = cmyk_values[2] / 100.0;
+      module->cmyk.k = cmyk_values[3] / 100.0;
+    }
+  else
+    {
+      gimp_rgb_to_cmyk (rgb, 1.0, &module->cmyk);
+    }
+
+  values[0] = module->cmyk.c * 100.0;
+  values[1] = module->cmyk.m * 100.0;
+  values[2] = module->cmyk.y * 100.0;
+  values[3] = module->cmyk.k * 100.0;
+
+  for (i = 0; i < 4; i++)
+    {
+      g_signal_handlers_block_by_func (module->adj[i],
+                                       colorsel_cmyk_adj_update,
+                                       module);
+
+      gtk_adjustment_set_value (module->adj[i], values[i]);
+
+      g_signal_handlers_unblock_by_func (module->adj[i],
+                                         colorsel_cmyk_adj_update,
+                                         module);
+    }
+}
+
+static void
+colorsel_cmyk_set_config (GimpColorSelector *selector,
+                          GimpColorConfig   *config)
+{
+  ColorselCmyk *module = COLORSEL_CMYK (selector);
+
+  if (config == module->config)
+    return;
+
+  if (module->config)
+    {
+      g_signal_handlers_disconnect_by_func (module->config,
+                                            G_CALLBACK (colorsel_cmyk_config_changed),
+                                            module);
+      g_object_unref (module->config);
+    }
 
-  gimp_rgb_to_cmyk (rgb, module->pullout, &module->cmyk);
+  module->config = config;
 
-  gtk_adjustment_set_value (module->adj[0], module->cmyk.c * 100.0);
-  gtk_adjustment_set_value (module->adj[1], module->cmyk.m * 100.0);
-  gtk_adjustment_set_value (module->adj[2], module->cmyk.y * 100.0);
-  gtk_adjustment_set_value (module->adj[3], module->cmyk.k * 100.0);
+  if (module->config)
+    {
+      g_object_ref (module->config);
+      g_signal_connect_swapped (module->config, "notify",
+                                G_CALLBACK (colorsel_cmyk_config_changed),
+                                module);
+    }
+
+  colorsel_cmyk_config_changed (module);
 }
 
 static void
@@ -219,46 +296,179 @@ colorsel_cmyk_adj_update (GtkAdjustment *adj,
                           ColorselCmyk  *module)
 {
   GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
-  gdouble            value;
   gint               i;
+  gdouble            value;
 
   for (i = 0; i < 4; i++)
     if (module->adj[i] == adj)
       break;
 
-  value = gtk_adjustment_get_value (adj);
+  value = gtk_adjustment_get_value (adj) / 100.0;
 
   switch (i)
     {
     case 0:
-      module->cmyk.c = value / 100.0;
+      module->cmyk.c = value;
       break;
     case 1:
-      module->cmyk.m = value / 100.0;
+      module->cmyk.m = value;
       break;
     case 2:
-      module->cmyk.y = value / 100.0;
+      module->cmyk.y = value;
       break;
     case 3:
-      module->cmyk.k = value / 100.0;
+      module->cmyk.k = value;
       break;
     default:
       return;
     }
 
-  gimp_cmyk_to_rgb (&module->cmyk, &selector->rgb);
+  if (module->cmyk2rgb)
+    {
+      gdouble cmyk_values[4];
+      gdouble rgb_values[3];
+
+      cmyk_values[0] = module->cmyk.c * 100.0;
+      cmyk_values[1] = module->cmyk.m * 100.0;
+      cmyk_values[2] = module->cmyk.y * 100.0;
+      cmyk_values[3] = module->cmyk.k * 100.0;
+
+      cmsDoTransform (module->cmyk2rgb, cmyk_values, rgb_values, 1);
+
+      selector->rgb.r = rgb_values[0];
+      selector->rgb.g = rgb_values[1];
+      selector->rgb.b = rgb_values[2];
+    }
+  else
+    {
+      gimp_cmyk_to_rgb (&module->cmyk, &selector->rgb);
+    }
+
   gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
 
   gimp_color_selector_color_changed (selector);
 }
 
+static cmsHPROFILE
+color_config_get_rgb_profile (GimpColorConfig *config)
+{
+  cmsHPROFILE  profile = NULL;
+
+  if (config->rgb_profile)
+    profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
+
+  return profile ? profile : cmsCreate_sRGBProfile ();
+}
+
 static void
-colorsel_cmyk_pullout_update (GtkAdjustment *adj,
-                              ColorselCmyk  *module)
+colorsel_cmyk_config_changed (ColorselCmyk *module)
 {
   GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
+  GimpColorConfig   *config   = module->config;
+  cmsUInt32Number    flags    = 0;
+  cmsUInt32Number    descSize = 0;
+  cmsHPROFILE        rgb_profile;
+  cmsHPROFILE        cmyk_profile;
+  gchar             *descData;
+  const gchar       *name     = NULL;
+  gchar             *text;
+
+  if (module->rgb2cmyk)
+    {
+      cmsDeleteTransform (module->rgb2cmyk);
+      module->rgb2cmyk = NULL;
+    }
+
+  if (module->cmyk2rgb)
+    {
+      cmsDeleteTransform (module->cmyk2rgb);
+      module->cmyk2rgb = NULL;
+    }
+
+  gtk_label_set_text (GTK_LABEL (module->name_label), _("Profile: (none)"));
+  gimp_help_set_help_data (module->name_label, NULL, NULL);
+
+  if (! config)
+    goto out;
+
+  if (! config->cmyk_profile ||
+      ! (cmyk_profile = cmsOpenProfileFromFile (config->cmyk_profile, "r")))
+    goto out;
+
+  descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoDescription,
+                                     "en", "US", NULL, 0);
+  if (descSize > 0)
+    {
+      descData = g_new (gchar, descSize + 1);
+      descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoDescription,
+                                         "en", "US", descData, descSize);
+      if (descSize > 0)
+        {
+          name = descData;
+        }
+      else
+        {
+          g_free (descData);
+          descData = NULL;
+        }
+    }
 
-  module->pullout = gtk_adjustment_get_value (adj) / 100.0;
+  if (name && ! g_utf8_validate (name, -1, NULL))
+    name = _("(invalid UTF-8 string)");
+
+  if (! name)
+    {
+      descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoModel,
+                                         "en", "US", NULL, 0);
+      if (descSize > 0)
+        {
+          descData = g_new (gchar, descSize + 1);
+          descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoModel,
+                                             "en", "US", descData, descSize);
+          if (descSize > 0)
+            {
+              name = descData;
+            }
+          else
+            {
+              g_free (descData);
+              descData = NULL;
+            }
+        }
+
+      if (name && ! g_utf8_validate (name, -1, NULL))
+        name = _("(invalid UTF-8 string)");
+    }
+
+  text = g_strdup_printf (_("Profile: %s"), name);
+  gtk_label_set_text (GTK_LABEL (module->name_label), text);
+  gimp_help_set_help_data (module->name_label, text, NULL);
+  g_free (text);
+
+  if (descData)
+    g_free (descData);
+
+  rgb_profile = color_config_get_rgb_profile (config);
+
+  if (config->display_intent ==
+      GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC)
+    {
+      flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
+    }
 
-  gimp_color_selector_set_color (selector, &selector->rgb, &selector->hsv);
+  module->rgb2cmyk = cmsCreateTransform (rgb_profile,  TYPE_RGB_DBL,
+                                         cmyk_profile, TYPE_CMYK_DBL,
+                                         config->display_intent,
+                                         flags);
+  module->cmyk2rgb = cmsCreateTransform (cmyk_profile, TYPE_CMYK_DBL,
+                                         rgb_profile,  TYPE_RGB_DBL,
+                                         config->display_intent,
+                                         flags);
+
+  cmsCloseProfile (rgb_profile);
+  cmsCloseProfile (cmyk_profile);
+
+ out:
+  if (! module->in_destruction)
+    colorsel_cmyk_set_color (selector, &selector->rgb, &selector->hsv);
 }
diff --git a/po-libgimp/POTFILES.in b/po-libgimp/POTFILES.in
index f93b15b..12201b2 100644
--- a/po-libgimp/POTFILES.in
+++ b/po-libgimp/POTFILES.in
@@ -62,7 +62,6 @@ libgimpwidgets/gimpwidgets.c
 libgimpwidgets/gimpwidgets-private.c
 libgimpwidgets/gimpwidgetsenums.c
 
-modules/color-selector-cmyk-lcms.c
 modules/color-selector-cmyk.c
 modules/color-selector-water.c
 modules/color-selector-wheel.c


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