[gimp/alxsa-anyrgb-color-selectors] libgimpwidgets: Add profile to color selectors




commit cc5c85c5d2f2d0d815cc6095c6e3fc0d27554ab1
Author: Alx Sa <cmyk student gmail com>
Date:   Tue Aug 16 19:40:33 2022 +0000

    libgimpwidgets: Add profile to color selectors
    
    The image's color profile is now passed to the various ColorSelectors
    to enable selecting colors outside of sRGB.

 app/widgets/gimpcolordialog.c       |  22 +++++++
 libgimpwidgets/gimpcolornotebook.c  |  27 ++++++++
 libgimpwidgets/gimpcolornotebook.h  |   2 +
 libgimpwidgets/gimpcolorscale.c     |  69 ++++++++++++++++++--
 libgimpwidgets/gimpcolorscale.h     |   2 +
 libgimpwidgets/gimpcolorscales.c    |  40 ++++++++++++
 libgimpwidgets/gimpcolorselect.c    |  92 ++++++++++++++++++++++++--
 libgimpwidgets/gimpcolorselection.c |  21 ++++++
 libgimpwidgets/gimpcolorselection.h |   3 +
 libgimpwidgets/gimpcolorselector.c  |  24 +++++++
 libgimpwidgets/gimpcolorselector.h  |   5 ++
 libgimpwidgets/gimpwidgets.def      |   4 ++
 modules/color-selector-cmyk.c       | 125 ++++++++++++++++++++++++++++--------
 13 files changed, 397 insertions(+), 39 deletions(-)
---
diff --git a/app/widgets/gimpcolordialog.c b/app/widgets/gimpcolordialog.c
index 47a5156b70..978a17d184 100644
--- a/app/widgets/gimpcolordialog.c
+++ b/app/widgets/gimpcolordialog.c
@@ -106,6 +106,8 @@ static void   gimp_color_dialog_history_selected (GimpColorHistory   *history,
 static void   gimp_color_dialog_image_changed    (GimpContext        *context,
                                                   GimpImage          *image,
                                                   GimpColorDialog    *dialog);
+static void   gimp_color_dialog_update_profile   (GimpImage          *image,
+                                                  GimpColorDialog    *dialog);
 static void   gimp_color_dialog_update_simulation(GimpImage          *image,
                                                   GimpColorDialog    *dialog);
 static void   gimp_color_dialog_update           (GimpColorDialog    *dialog);
@@ -715,6 +717,9 @@ gimp_color_dialog_image_changed (GimpContext     *context,
           g_signal_handlers_disconnect_by_func (dialog->active_image,
                                                 G_CALLBACK (gimp_color_dialog_update),
                                                 dialog);
+          g_signal_handlers_disconnect_by_func (dialog->active_image,
+                                                gimp_color_dialog_update_profile,
+                                                dialog);
           g_signal_handlers_disconnect_by_func (dialog->active_image,
                                                 gimp_color_dialog_update_simulation,
                                                 dialog);
@@ -727,6 +732,9 @@ gimp_color_dialog_image_changed (GimpContext     *context,
           g_signal_connect_swapped (image, "notify::base-type",
                                     G_CALLBACK (gimp_color_dialog_update),
                                     dialog);
+          g_signal_connect (image, "profile-changed",
+                            G_CALLBACK (gimp_color_dialog_update_profile),
+                            dialog);
           g_signal_connect (image, "simulation-profile-changed",
                             G_CALLBACK (gimp_color_dialog_update_simulation),
                             dialog);
@@ -737,12 +745,26 @@ gimp_color_dialog_image_changed (GimpContext     *context,
                             G_CALLBACK (gimp_color_dialog_update_simulation),
                             dialog);
 
+          gimp_color_dialog_update_profile (image, dialog);
           gimp_color_dialog_update_simulation (image, dialog);
         }
       gimp_color_dialog_update (dialog);
     }
 }
 
+static void
+gimp_color_dialog_update_profile (GimpImage       *image,
+                                  GimpColorDialog *dialog)
+{
+  g_return_if_fail (GIMP_IS_COLOR_DIALOG (dialog));
+
+  if (image && GIMP_IS_COLOR_DIALOG (dialog))
+    {
+      gimp_color_selection_set_profile (GIMP_COLOR_SELECTION (dialog->selection),
+                                        gimp_image_get_color_profile (image));
+    }
+}
+
 static void
 gimp_color_dialog_update_simulation (GimpImage       *image,
                                      GimpColorDialog *dialog)
diff --git a/libgimpwidgets/gimpcolornotebook.c b/libgimpwidgets/gimpcolornotebook.c
index 1fe2ef7138..94905586bc 100644
--- a/libgimpwidgets/gimpcolornotebook.c
+++ b/libgimpwidgets/gimpcolornotebook.c
@@ -596,6 +596,33 @@ gimp_color_notebook_get_current_selector (GimpColorNotebook *notebook)
   return notebook->priv->cur_page;
 }
 
+/**
+ * gimp_color_notebook_set_profile:
+ * @notebook:  A #GimpColorNotebook widget.
+ * @profile:   A #GimpColorProfile object.
+ *
+ * Updates all selectors with the current color profile.
+ *
+ * Since: 3.0
+ **/
+void
+gimp_color_notebook_set_profile (GimpColorNotebook *notebook,
+                                 GimpColorProfile  *profile)
+{
+  GList *list;
+
+  g_return_if_fail (GIMP_IS_COLOR_NOTEBOOK (notebook));
+  g_return_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile));
+
+  for (list = notebook->priv->selectors; list; list = g_list_next (list))
+    {
+      GimpColorSelector *selector = list->data;
+
+      if (selector)
+        gimp_color_selector_set_profile (selector, profile);
+    }
+}
+
 /**
  * gimp_color_notebook_set_simulation:
  * @notebook:  A #GimpColorNotebook widget.
diff --git a/libgimpwidgets/gimpcolornotebook.h b/libgimpwidgets/gimpcolornotebook.h
index 6a36578ad2..48317f6a83 100644
--- a/libgimpwidgets/gimpcolornotebook.h
+++ b/libgimpwidgets/gimpcolornotebook.h
@@ -77,6 +77,8 @@ GtkWidget         * gimp_color_notebook_set_has_page         (GimpColorNotebook
 GtkWidget         * gimp_color_notebook_get_notebook         (GimpColorNotebook *notebook);
 GList             * gimp_color_notebook_get_selectors        (GimpColorNotebook *notebook);
 GimpColorSelector * gimp_color_notebook_get_current_selector (GimpColorNotebook *notebook);
+void                gimp_color_notebook_set_profile          (GimpColorNotebook *notebook,
+                                                              GimpColorProfile  *profile);
 void                gimp_color_notebook_set_simulation       (GimpColorNotebook *notebook,
                                                               GimpColorProfile  *profile,
                                                               GimpColorRenderingIntent intent,
diff --git a/libgimpwidgets/gimpcolorscale.c b/libgimpwidgets/gimpcolorscale.c
index 9aeab7b8d9..518d82d6e8 100644
--- a/libgimpwidgets/gimpcolorscale.c
+++ b/libgimpwidgets/gimpcolorscale.c
@@ -66,6 +66,7 @@ struct _GimpColorScalePrivate
 {
   GimpColorConfig          *config;
   GimpColorTransform       *transform;
+  GimpColorProfile         *profile;
   guchar                    oog_color[3];
 
   GimpColorSelectorChannel  channel;
@@ -334,12 +335,21 @@ gimp_color_scale_draw (GtkWidget *widget,
     gimp_color_scale_create_transform (scale);
 
   if (priv->transform)
-    {
-      const Babl *format = babl_format ("cairo-RGB24");
-      guchar     *buf    = g_new (guchar, priv->rowstride * priv->height);
-      guchar     *src    = priv->buf;
-      guchar     *dest   = buf;
-      guint       i;
+    {      
+      const Babl       *space   = NULL;
+      const Babl       *format  = babl_format ("cairo-RGB24");
+      guchar           *buf     = g_new (guchar, priv->rowstride * priv->height);
+      guchar           *src     = priv->buf;
+      guchar           *dest    = buf;
+      guint             i;
+
+      if (scale->priv->profile)
+        {
+          space = gimp_color_profile_get_space (scale->priv->profile,
+                                                GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                                NULL);
+          format = babl_format_with_space ("cairo-RGB24", space);
+        }
 
       for (i = 0; i < priv->height; i++)
         {
@@ -617,6 +627,42 @@ gimp_color_scale_set_color_config (GimpColorScale  *scale,
     }
 }
 
+/**
+ * gimp_color_scale_set_profile:
+ * @scale:   a #GimpColorScale widget.
+ * @profile: a #GimpColorProfile object.
+ *
+ * Sets the color profile to use with this color scale.
+ *
+ * Since: 3.0
+ */
+void
+gimp_color_scale_set_profile (GimpColorScale   *scale,
+                              GimpColorProfile *profile)
+{
+  GimpColorScalePrivate *priv;
+  const Babl            *space         = NULL;
+
+  g_return_if_fail (GIMP_IS_COLOR_SCALE (scale));
+  g_return_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile));
+
+  priv = GET_PRIVATE (scale);
+  
+  g_set_object (&priv->profile, profile);
+  
+  if (profile)
+    space = gimp_color_profile_get_space (profile,
+                                          GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                          NULL);
+
+  fish_rgb_to_lch = babl_fish (babl_format_with_space ("R'G'B'A double", space),
+                               babl_format ("CIE LCH(ab) double"));
+  fish_lch_to_rgb = babl_fish (babl_format ("CIE LCH(ab) double"),
+                               babl_format_with_space ("R'G'B' double", space));
+
+  if (priv->config)
+    gimp_color_scale_notify_config (priv->config, NULL, scale);
+}
 
 /* as in gtkrange.c */
 static gboolean
@@ -932,8 +978,17 @@ gimp_color_scale_create_transform (GimpColorScale *scale)
   if (priv->config)
     {
       static GimpColorProfile *profile = NULL;
+      const Babl *space                = NULL;
+      const Babl *format               = babl_format ("cairo-RGB24");
 
-      const Babl *format = babl_format ("cairo-RGB24");
+      if (scale->priv->profile)
+        {
+          profile = scale->priv->profile;
+          space = gimp_color_profile_get_space (profile,
+                                                GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                                NULL);
+          format = babl_format_with_space ("cairo-RGB24", space);
+        }
 
       if (G_UNLIKELY (! profile))
         profile = gimp_color_profile_new_rgb_srgb ();
diff --git a/libgimpwidgets/gimpcolorscale.h b/libgimpwidgets/gimpcolorscale.h
index f31fbdd504..091efd06c5 100644
--- a/libgimpwidgets/gimpcolorscale.h
+++ b/libgimpwidgets/gimpcolorscale.h
@@ -76,6 +76,8 @@ void        gimp_color_scale_set_color        (GimpColorScale           *scale,
 
 void        gimp_color_scale_set_color_config (GimpColorScale           *scale,
                                                GimpColorConfig          *config);
+void        gimp_color_scale_set_profile      (GimpColorScale           *scale,
+                                               GimpColorProfile         *profile);
 
 
 G_END_DECLS
diff --git a/libgimpwidgets/gimpcolorscales.c b/libgimpwidgets/gimpcolorscales.c
index 0e06b5eea6..d49b695ec0 100644
--- a/libgimpwidgets/gimpcolorscales.c
+++ b/libgimpwidgets/gimpcolorscales.c
@@ -114,6 +114,8 @@ struct _GimpColorScales
   GtkWidget         *dummy_u8_toggle;
   GtkWidget         *toggles[14];
   GtkWidget         *scales[14];
+
+  GimpColorProfile  *profile;
 };
 
 struct _GimpColorScalesClass
@@ -150,6 +152,8 @@ static void   gimp_color_scales_set_model_visible
                                                 gboolean           visible);
 static void   gimp_color_scales_set_config     (GimpColorSelector *selector,
                                                 GimpColorConfig   *config);
+static void   gimp_color_scales_set_profile    (GimpColorSelector *selector,
+                                                GimpColorProfile  *profile);
 
 static void   gimp_color_scales_update_visible (GimpColorScales   *scales);
 static void   gimp_color_scales_update_scales  (GimpColorScales   *scales,
@@ -212,6 +216,7 @@ gimp_color_scales_class_init (GimpColorScalesClass *klass)
   selector_class->set_channel           = gimp_color_scales_set_channel;
   selector_class->set_model_visible     = gimp_color_scales_set_model_visible;
   selector_class->set_config            = gimp_color_scales_set_config;
+  selector_class->set_profile           = gimp_color_scales_set_profile;
 
   g_object_class_install_property (object_class, PROP_SHOW_RGB_U8,
                                    g_param_spec_boolean ("show-rgb-u8",
@@ -482,6 +487,7 @@ gimp_color_scales_dispose (GObject *object)
   GimpColorScales *scales = GIMP_COLOR_SCALES (object);
 
   g_clear_object (&scales->dummy_u8_toggle);
+  g_clear_object (&scales->profile);
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -611,6 +617,40 @@ gimp_color_scales_set_config (GimpColorSelector *selector,
     }
 }
 
+static void
+gimp_color_scales_set_profile (GimpColorSelector *selector,
+                               GimpColorProfile  *profile)
+{
+  GimpColorScales  *scales        = GIMP_COLOR_SCALES (selector);
+  GimpColorProfile *color_profile = NULL;
+  const Babl       *space         = NULL;
+  gint              i;
+
+  g_set_object (&scales->profile, profile);
+
+  if (scales->profile)
+    color_profile = scales->profile;
+
+  if (color_profile)
+    space = gimp_color_profile_get_space (color_profile,
+                                          GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                          NULL);
+
+  fish_rgb_to_lch    = babl_fish (babl_format_with_space ("R'G'B'A double", space),
+                                  babl_format ("CIE LCH(ab) double"));
+  fish_lch_to_rgb    = babl_fish (babl_format ("CIE LCH(ab) double"),
+                                  babl_format_with_space ("R'G'B'A double", space));
+
+  for (i = 0; i < G_N_ELEMENTS (scale_defs); i++)
+    {
+      if (scales->scales[i])
+        gimp_color_scale_set_profile (GIMP_COLOR_SCALE (gimp_scale_entry_get_range (GIMP_SCALE_ENTRY 
(scales->scales[i]))),
+                                      color_profile);
+    }
+
+  gimp_color_scales_set_color (selector, &selector->rgb, &selector->hsv);
+}
+
 
 /*  public functions  */
 
diff --git a/libgimpwidgets/gimpcolorselect.c b/libgimpwidgets/gimpcolorselect.c
index 8a21ad9daf..861937b896 100644
--- a/libgimpwidgets/gimpcolorselect.c
+++ b/libgimpwidgets/gimpcolorselect.c
@@ -129,6 +129,7 @@ struct _GimpColorSelect
   GimpColorSelector    parent_instance;
 
   GtkWidget           *toggle_box[3];
+  GtkWidget           *profile_label;
 
   GtkWidget           *xy_color;
   ColorSelectFillType  xy_color_fill;
@@ -151,6 +152,7 @@ struct _GimpColorSelect
   ColorSelectDragMode  drag_mode;
 
   GimpColorConfig     *config;
+  GimpColorProfile    *profile;
   GimpColorTransform  *transform;
   guchar               oog_color[3];
 };
@@ -197,6 +199,8 @@ static void   gimp_color_select_set_model_visible
                                                  gboolean            visible);
 static void   gimp_color_select_set_config      (GimpColorSelector  *selector,
                                                  GimpColorConfig    *config);
+static void   gimp_color_select_set_profile     (GimpColorSelector *selector,
+                                                 GimpColorProfile  *profile);
 
 static void   gimp_color_select_channel_toggled (GtkWidget          *widget,
                                                  GimpColorSelect    *select);
@@ -328,6 +332,7 @@ gimp_color_select_class_init (GimpColorSelectClass *klass)
   selector_class->set_channel           = gimp_color_select_set_channel;
   selector_class->set_model_visible     = gimp_color_select_set_model_visible;
   selector_class->set_config            = gimp_color_select_set_config;
+  selector_class->set_profile           = gimp_color_select_set_profile;
 
   gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "GimpColorSelect");
 
@@ -361,10 +366,14 @@ gimp_color_select_init (GimpColorSelect *select)
   gtk_box_pack_start (GTK_BOX (select), hbox, TRUE, TRUE, 0);
   gtk_widget_show (hbox);
 
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+  gtk_widget_show (vbox);
+
   /*  The x/y component preview  */
   frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
   gtk_widget_show (frame);
 
   select->xy_color = gtk_event_box_new ();
@@ -388,6 +397,15 @@ gimp_color_select_init (GimpColorSelect *select)
                     G_CALLBACK (gimp_color_select_xy_events),
                     select);
 
+  select->profile_label = gtk_label_new (NULL);
+  gtk_label_set_xalign (GTK_LABEL (select->profile_label), 0.0);
+  gtk_label_set_ellipsize (GTK_LABEL (select->profile_label), PANGO_ELLIPSIZE_END);
+  gimp_label_set_attributes (GTK_LABEL (select->profile_label),
+                             PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
+                             -1);
+  gtk_box_pack_start (GTK_BOX (vbox), select->profile_label, FALSE, FALSE, 0);
+  gtk_widget_show (select->profile_label);
+
 #if 0
   gimp_dnd_color_dest_add (select->xy_color, gimp_color_select_drop_color,
                            select);
@@ -512,6 +530,8 @@ gimp_color_select_finalize (GObject *object)
   select->z_height    = 0;
   select->z_rowstride = 0;
 
+  g_clear_object (&select->profile);
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -653,6 +673,49 @@ gimp_color_select_set_config (GimpColorSelector *selector,
     }
 }
 
+static void
+gimp_color_select_set_profile (GimpColorSelector *selector,
+                               GimpColorProfile  *profile)
+{
+  GimpColorSelect  *select        = GIMP_COLOR_SELECT (selector);
+  GimpColorProfile *color_profile = NULL;
+  const Babl       *space         = NULL;
+  gchar            *text;
+
+  gtk_label_set_text (GTK_LABEL (select->profile_label), _("Image Profile: (none)"));
+  gimp_help_set_help_data (select->profile_label, NULL, NULL);
+
+  g_set_object (&select->profile, profile);
+
+  if (select->profile)
+    color_profile = select->profile;
+
+  if (color_profile)
+    {
+      text = g_strdup_printf (_("Image Profile: %s"),
+                              gimp_color_profile_get_label (color_profile));
+      gtk_label_set_text (GTK_LABEL (select->profile_label), text);
+      g_free (text);
+
+      gimp_help_set_help_data (select->profile_label,
+                              gimp_color_profile_get_summary (color_profile),
+                              NULL);
+
+      space = gimp_color_profile_get_space (color_profile,
+                                            GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                            NULL);
+    }
+
+  fish_rgb_to_lch    = babl_fish (babl_format_with_space ("R'G'B'A double", space),
+                                  babl_format ("CIE LCH(ab) double"));
+  fish_lch_to_rgb    = babl_fish (babl_format ("CIE LCH(ab) double"),
+                                  babl_format_with_space ("R'G'B'A double", space));
+  fish_lch_to_rgb_u8 = babl_fish (babl_format_with_space ("R'G'B'A double", space),
+                                  babl_format ("R'G'B' u8"));
+
+  gimp_color_select_set_color (selector, &selector->rgb, &selector->hsv);
+}
+
 static void
 gimp_color_select_channel_toggled (GtkWidget       *widget,
                                    GimpColorSelect *select)
@@ -892,10 +955,16 @@ gimp_color_select_xy_draw (GtkWidget       *widget,
                            cairo_t         *cr,
                            GimpColorSelect *select)
 {
+  const Babl    *space      = NULL;
   GtkAllocation  allocation;
   GdkPixbuf     *pixbuf;
   gint           x, y;
 
+  if (select->profile)
+    space = gimp_color_profile_get_space (select->profile,
+                                          GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                          NULL);
+
   if (! select->xy_buf)
     return FALSE;
 
@@ -920,7 +989,7 @@ gimp_color_select_xy_draw (GtkWidget       *widget,
 
   if (select->transform)
     {
-      const Babl *format = babl_format ("R'G'B' u8");
+      const Babl *format = babl_format_with_space ("R'G'B' u8", space);
       guchar     *buf    = g_new (guchar,
                                   select->xy_rowstride * select->xy_height);
       guchar     *src    = select->xy_buf;
@@ -1089,6 +1158,7 @@ gimp_color_select_z_draw (GtkWidget       *widget,
                           cairo_t         *cr,
                           GimpColorSelect *select)
 {
+  const Babl    *space      = NULL;
   GtkAllocation  allocation;
   GdkPixbuf     *pixbuf;
   gint           y;
@@ -1096,6 +1166,11 @@ gimp_color_select_z_draw (GtkWidget       *widget,
   if (! select->z_buf)
     return FALSE;
 
+  if (select->profile)
+    space = gimp_color_profile_get_space (select->profile,
+                                          GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                          NULL);
+
   if (select->z_needs_render)
     {
       GimpColorSelector *selector = GIMP_COLOR_SELECTOR (select);
@@ -1119,7 +1194,7 @@ gimp_color_select_z_draw (GtkWidget       *widget,
 
   if (select->transform)
     {
-      const Babl *format = babl_format ("R'G'B' u8");
+      const Babl *format = babl_format_with_space ("R'G'B' u8", space);
       guchar     *buf    = g_new (guchar,
                                   select->z_rowstride * select->z_height);
       guchar     *src    = select->z_buf;
@@ -1946,8 +2021,17 @@ gimp_color_select_create_transform (GimpColorSelect *select)
   if (select->config)
     {
       static GimpColorProfile *profile = NULL;
+      const Babl *space                = NULL;
+      const Babl *format               = babl_format ("cairo-RGB24");
 
-      const Babl *format = babl_format ("cairo-RGB24");
+      if (select->profile)
+        {
+          profile = select->profile;
+          space = gimp_color_profile_get_space (profile,
+                                                GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                                NULL);
+          format = babl_format_with_space ("cairo-RGB24", space);
+        }
 
       if (G_UNLIKELY (! profile))
         profile = gimp_color_profile_new_rgb_srgb ();
diff --git a/libgimpwidgets/gimpcolorselection.c b/libgimpwidgets/gimpcolorselection.c
index 6ae29a44d4..374a025d9a 100644
--- a/libgimpwidgets/gimpcolorselection.c
+++ b/libgimpwidgets/gimpcolorselection.c
@@ -560,6 +560,27 @@ gimp_color_selection_color_changed (GimpColorSelection *selection)
   g_signal_emit (selection, selection_signals[COLOR_CHANGED], 0);
 }
 
+/**
+ * gimp_color_selection_set_profile:
+ * @selection: A #GimpColorSelection widget.
+ * @profile:   A #GimpColorProfile object.
+ *
+ * Sets the color profile to use with this color selection.
+ *
+ * Since: 3.0
+ */
+void
+gimp_color_selection_set_profile (GimpColorSelection *selection,
+                                  GimpColorProfile   *profile)
+{
+  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
+
+  gimp_color_notebook_set_profile (GIMP_COLOR_NOTEBOOK (selection->priv->notebook),
+                                   profile);
+
+  g_signal_emit (selection, selection_signals[COLOR_CHANGED], 0);
+}
+
 /**
  * gimp_color_selection_set_simulation:
  * @selection: A #GimpColorSelection widget.
diff --git a/libgimpwidgets/gimpcolorselection.h b/libgimpwidgets/gimpcolorselection.h
index 4d9f0033f8..dc0fa9f69f 100644
--- a/libgimpwidgets/gimpcolorselection.h
+++ b/libgimpwidgets/gimpcolorselection.h
@@ -89,6 +89,9 @@ void        gimp_color_selection_reset          (GimpColorSelection *selection);
 
 void        gimp_color_selection_color_changed  (GimpColorSelection *selection);
 
+void        gimp_color_selection_set_profile    (GimpColorSelection *selection,
+                                                 GimpColorProfile   *profile);
+
 void        gimp_color_selection_set_simulation (GimpColorSelection *selection,
                                                  GimpColorProfile   *profile,
                                                  GimpColorRenderingIntent intent,
diff --git a/libgimpwidgets/gimpcolorselector.c b/libgimpwidgets/gimpcolorselector.c
index 0f15e92f86..e85552f5a8 100644
--- a/libgimpwidgets/gimpcolorselector.c
+++ b/libgimpwidgets/gimpcolorselector.c
@@ -639,6 +639,30 @@ gimp_color_selector_set_config (GimpColorSelector *selector,
     selector_class->set_config (selector, config);
 }
 
+/**
+ * gimp_color_selector_set_profile:
+ * @selector: a #GimpColorSelector widget.
+ * @profile:  a #GimpColorProfile object.
+ *
+ * Sets the color profile to use with this color selector.
+ *
+ * Since: 3.0
+ */
+void
+gimp_color_selector_set_profile (GimpColorSelector *selector,
+                                 GimpColorProfile  *profile)
+{
+  GimpColorSelectorClass *selector_class;
+
+  g_return_if_fail (GIMP_IS_COLOR_SELECTOR (selector));
+  g_return_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile));
+
+  selector_class = GIMP_COLOR_SELECTOR_GET_CLASS (selector);
+
+  if (selector_class->set_profile)
+    selector_class->set_profile (selector, profile);
+}
+
 /**
  * gimp_color_selector_set_simulation
  * @selector: a #GimpColorSelector widget.
diff --git a/libgimpwidgets/gimpcolorselector.h b/libgimpwidgets/gimpcolorselector.h
index 214f364fee..774e41788a 100644
--- a/libgimpwidgets/gimpcolorselector.h
+++ b/libgimpwidgets/gimpcolorselector.h
@@ -105,6 +105,9 @@ struct _GimpColorSelectorClass
   void (* set_config)            (GimpColorSelector        *selector,
                                   GimpColorConfig          *config);
 
+  void (* set_profile)           (GimpColorSelector        *selector,
+                                  GimpColorProfile         *profile);
+
   void (* set_simulation)        (GimpColorSelector        *selector,
                                   GimpColorProfile         *profile,
                                   GimpColorRenderingIntent  intent,
@@ -176,6 +179,8 @@ void     gimp_color_selector_emit_model_visible_changed (GimpColorSelector *sele
 void     gimp_color_selector_set_config            (GimpColorSelector *selector,
                                                     GimpColorConfig   *config);
 
+void     gimp_color_selector_set_profile           (GimpColorSelector *selector,
+                                                    GimpColorProfile  *profile);
 void     gimp_color_selector_set_simulation        (GimpColorSelector *selector,
                                                     GimpColorProfile  *profile,
                                                     GimpColorRenderingIntent intent,
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index 5b0b17a45b..a208375f5e 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -84,6 +84,7 @@ EXPORTS
        gimp_color_notebook_get_selectors
        gimp_color_notebook_get_type
        gimp_color_notebook_set_has_page
+       gimp_color_notebook_set_profile
        gimp_color_notebook_set_simulation
        gimp_color_profile_chooser_dialog_get_type
        gimp_color_profile_chooser_dialog_new
@@ -107,6 +108,7 @@ EXPORTS
        gimp_color_scale_set_channel
        gimp_color_scale_set_color
        gimp_color_scale_set_color_config
+       gimp_color_scale_set_profile
        gimp_color_scales_get_show_rgb_u8
        gimp_color_scales_get_type
        gimp_color_scales_set_show_rgb_u8
@@ -123,6 +125,7 @@ EXPORTS
        gimp_color_selection_set_color
        gimp_color_selection_set_config
        gimp_color_selection_set_old_color
+       gimp_color_selection_set_profile
        gimp_color_selection_set_show_alpha
        gimp_color_selection_set_simulation
        gimp_color_selector_channel_get_type
@@ -142,6 +145,7 @@ EXPORTS
        gimp_color_selector_set_color
        gimp_color_selector_set_config
        gimp_color_selector_set_model_visible
+       gimp_color_selector_set_profile
        gimp_color_selector_set_show_alpha
        gimp_color_selector_set_simulation
        gimp_color_selector_set_toggles_sensitive
diff --git a/modules/color-selector-cmyk.c b/modules/color-selector-cmyk.c
index b8af09190b..60d58dd1d7 100644
--- a/modules/color-selector-cmyk.c
+++ b/modules/color-selector-cmyk.c
@@ -45,6 +45,7 @@ struct _ColorselCmyk
   GimpColorSelector   parent_instance;
 
   GimpColorConfig          *config;
+  GimpColorProfile         *profile;
   GimpColorProfile         *simulation_profile;
   GimpColorRenderingIntent  simulation_intent;
   gboolean                  simulation_bpc;
@@ -52,6 +53,7 @@ struct _ColorselCmyk
   GimpCMYK            cmyk;
   GtkWidget          *scales[4];
   GtkWidget          *name_label;
+  GtkWidget          *proof_label;
 
   gboolean            in_destruction;
 };
@@ -71,6 +73,8 @@ static void   colorsel_cmyk_set_color      (GimpColorSelector *selector,
                                             const GimpHSV     *hsv);
 static void   colorsel_cmyk_set_config     (GimpColorSelector *selector,
                                             GimpColorConfig   *config);
+static void   colorsel_cmyk_set_profile    (GimpColorSelector *selector,
+                                            GimpColorProfile  *profile);
 static void   colorsel_cmyk_set_simulation (GimpColorSelector *selector,
                                             GimpColorProfile  *profile,
                                             GimpColorRenderingIntent intent,
@@ -123,6 +127,7 @@ colorsel_cmyk_class_init (ColorselCmykClass *klass)
   selector_class->icon_name              = GIMP_ICON_COLOR_SELECTOR_CMYK;
   selector_class->set_color              = colorsel_cmyk_set_color;
   selector_class->set_config             = colorsel_cmyk_set_config;
+  selector_class->set_profile            = colorsel_cmyk_set_profile;
   selector_class->set_simulation         = colorsel_cmyk_set_simulation;
 
   gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "ColorselCmyk");
@@ -192,6 +197,15 @@ colorsel_cmyk_init (ColorselCmyk *module)
                              -1);
   gtk_box_pack_start (GTK_BOX (module), module->name_label, FALSE, FALSE, 0);
   gtk_widget_show (module->name_label);
+
+  module->proof_label = gtk_label_new (NULL);
+  gtk_label_set_xalign (GTK_LABEL (module->proof_label), 0.0);
+  gtk_label_set_ellipsize (GTK_LABEL (module->proof_label), PANGO_ELLIPSIZE_END);
+  gimp_label_set_attributes (GTK_LABEL (module->proof_label),
+                             PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
+                             -1);
+  gtk_box_pack_start (GTK_BOX (module), module->proof_label, FALSE, FALSE, 0);
+  gtk_widget_show (module->proof_label);
 }
 
 static void
@@ -202,6 +216,7 @@ colorsel_cmyk_dispose (GObject *object)
   module->in_destruction = TRUE;
 
   colorsel_cmyk_set_config (GIMP_COLOR_SELECTOR (object), NULL);
+  g_clear_object (&module->profile);
   g_clear_object (&module->simulation_profile);
 
   G_OBJECT_CLASS (colorsel_cmyk_parent_class)->dispose (object);
@@ -212,14 +227,19 @@ colorsel_cmyk_set_color (GimpColorSelector *selector,
                          const GimpRGB     *rgb,
                          const GimpHSV     *hsv)
 {
-  GimpColorProfile        *cmyk_profile = NULL;
-  GimpColorRenderingIntent intent       = GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC;
-  const Babl              *fish         = NULL;
-  const Babl              *space        = NULL;
-  ColorselCmyk            *module       = COLORSEL_CMYK (selector);
+  GimpColorProfile        *color_profile = NULL;
+  GimpColorProfile        *cmyk_profile  = NULL;
+  GimpColorRenderingIntent intent        = GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC;
+  const Babl              *fish          = NULL;
+  const Babl              *space         = NULL;
+  const Babl              *proof_space   = NULL;
+  ColorselCmyk            *module        = COLORSEL_CMYK (selector);
   gfloat                   values[4];
   gint                     i;
 
+  if (module->profile)
+    color_profile = module->profile;
+
   /* Try Image Soft-proofing profile first, then default CMYK profile */
   if (module->simulation_profile)
     cmyk_profile = module->simulation_profile;
@@ -228,16 +248,21 @@ colorsel_cmyk_set_color (GimpColorSelector *selector,
     cmyk_profile = gimp_color_config_get_cmyk_color_profile (GIMP_COLOR_CONFIG (module->config),
                                                              NULL);
 
+  if (color_profile)
+    space = gimp_color_profile_get_space (color_profile,
+                                          GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                          NULL);
+
   if (cmyk_profile && gimp_color_profile_is_cmyk (cmyk_profile))
     {
       intent = module->simulation_intent;
 
-      space = gimp_color_profile_get_space (cmyk_profile, intent,
-                                            NULL);
+      proof_space = gimp_color_profile_get_space (cmyk_profile, intent,
+                                                  NULL);
     }
 
-  fish = babl_fish (babl_format ("R'G'B'A double"),
-                    babl_format_with_space ("CMYK float", space));
+  fish = babl_fish (babl_format_with_space ("R'G'B'A double", space),
+                    babl_format_with_space ("CMYK float", proof_space));
 
   babl_process (fish, rgb, values, 1);
 
@@ -283,6 +308,41 @@ colorsel_cmyk_set_config (GimpColorSelector *selector,
     }
 }
 
+static void
+colorsel_cmyk_set_profile (GimpColorSelector *selector,
+                           GimpColorProfile  *profile)
+{
+  ColorselCmyk     *module = COLORSEL_CMYK (selector);
+  GimpColorProfile *color_profile = NULL;
+  gchar            *text;
+
+  gtk_label_set_text (GTK_LABEL (module->name_label), _("Image Profile: (none)"));
+  gimp_help_set_help_data (module->name_label, NULL, NULL);
+
+  g_set_object (&module->profile, profile);
+
+  if (module->profile)
+    color_profile = module->profile;
+
+  if (color_profile)
+    {
+      text = g_strdup_printf (_("Image Profile: %s"),
+                              gimp_color_profile_get_label (color_profile));
+      gtk_label_set_text (GTK_LABEL (module->name_label), text);
+      g_free (text);
+
+      gimp_help_set_help_data (module->name_label,
+                              gimp_color_profile_get_summary (color_profile),
+                              NULL);
+    }
+
+  if (! module->in_destruction)
+    colorsel_cmyk_set_color (selector, &selector->rgb, &selector->hsv);
+
+  if (color_profile && ! module->profile)
+    g_object_unref (color_profile);
+}
+
 static void
 colorsel_cmyk_set_simulation (GimpColorSelector *selector,
                               GimpColorProfile  *profile,
@@ -293,8 +353,8 @@ colorsel_cmyk_set_simulation (GimpColorSelector *selector,
   GimpColorProfile *cmyk_profile = NULL;
   gchar            *text;
 
-  gtk_label_set_text (GTK_LABEL (module->name_label), _("Profile: (none)"));
-  gimp_help_set_help_data (module->name_label, NULL, NULL);
+  gtk_label_set_text (GTK_LABEL (module->proof_label), _("Proof Profile: (none)"));
+  gimp_help_set_help_data (module->proof_label, NULL, NULL);
 
   g_set_object (&module->simulation_profile, profile);
 
@@ -306,12 +366,12 @@ colorsel_cmyk_set_simulation (GimpColorSelector *selector,
 
   if (cmyk_profile && gimp_color_profile_is_cmyk (cmyk_profile))
     {
-      text = g_strdup_printf (_("Profile: %s"),
+      text = g_strdup_printf (_("Proof Profile: %s"),
                               gimp_color_profile_get_label (cmyk_profile));
-      gtk_label_set_text (GTK_LABEL (module->name_label), text);
+      gtk_label_set_text (GTK_LABEL (module->proof_label), text);
       g_free (text);
 
-      gimp_help_set_help_data (module->name_label,
+      gimp_help_set_help_data (module->proof_label,
                               gimp_color_profile_get_summary (cmyk_profile),
                               NULL);
     }
@@ -327,11 +387,13 @@ static void
 colorsel_cmyk_scale_update (GimpLabelSpin *scale,
                             ColorselCmyk  *module)
 {
-  GimpColorProfile        *cmyk_profile = NULL;
-  GimpColorSelector       *selector     = GIMP_COLOR_SELECTOR (module);
-  GimpColorRenderingIntent intent       = GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC;
-  const Babl              *fish         = NULL;
-  const Babl              *space        = NULL;
+  GimpColorProfile        *color_profile = NULL;
+  GimpColorProfile        *cmyk_profile  = NULL;
+  GimpColorSelector       *selector      = GIMP_COLOR_SELECTOR (module);
+  GimpColorRenderingIntent intent        = GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC;
+  const Babl              *fish          = NULL;
+  const Babl              *space         = NULL;
+  const Babl              *proof_space   = NULL;
   gfloat                   cmyk_values[4];
   gfloat                   rgb_values[3];
   gint                     i;
@@ -339,22 +401,29 @@ colorsel_cmyk_scale_update (GimpLabelSpin *scale,
   for (i = 0; i < 4; i++)
     cmyk_values[i] = gimp_label_spin_get_value (GIMP_LABEL_SPIN (module->scales[i])) / 100.0;
 
+  if (module->profile)
+    color_profile = module->profile;
+
   if (module->simulation_profile)
     cmyk_profile = module->simulation_profile;
 
   if (! cmyk_profile && GIMP_IS_COLOR_CONFIG (module->config))
     cmyk_profile = gimp_color_config_get_cmyk_color_profile (GIMP_COLOR_CONFIG (module->config),
                                                              NULL);
+  if (color_profile)
+    space = gimp_color_profile_get_space (color_profile,
+                                          GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                          NULL);
   if (cmyk_profile)
     {
       intent = module->simulation_intent;
 
-      space = gimp_color_profile_get_space (cmyk_profile, intent,
-                                            NULL);
+      proof_space = gimp_color_profile_get_space (cmyk_profile, intent,
+                                                  NULL);
     }
 
-  fish = babl_fish (babl_format_with_space ("CMYK float", space),
-                    babl_format ("R'G'B'A float"));
+  fish = babl_fish (babl_format_with_space ("CMYK float", proof_space),
+                    babl_format_with_space ("R'G'B'A float", space));
 
   babl_process (fish, cmyk_values, rgb_values, 1);
 
@@ -379,8 +448,8 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
   GimpColorProfile        *cmyk_profile = NULL;
   gchar                   *text;
 
-  gtk_label_set_text (GTK_LABEL (module->name_label), _("Profile: (none)"));
-  gimp_help_set_help_data (module->name_label, NULL, NULL);
+  gtk_label_set_text (GTK_LABEL (module->proof_label), _("Profile: (none)"));
+  gimp_help_set_help_data (module->proof_label, NULL, NULL);
 
   if (! config)
     goto out;
@@ -397,12 +466,12 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
 
   rgb_profile = gimp_color_profile_new_rgb_srgb ();
 
-  text = g_strdup_printf (_("Profile: %s"),
+  text = g_strdup_printf (_("Proof Profile: %s"),
                           gimp_color_profile_get_label (cmyk_profile));
-  gtk_label_set_text (GTK_LABEL (module->name_label), text);
+  gtk_label_set_text (GTK_LABEL (module->proof_label), text);
   g_free (text);
 
-  gimp_help_set_help_data (module->name_label,
+  gimp_help_set_help_data (module->proof_label,
                            gimp_color_profile_get_summary (cmyk_profile),
                            NULL);
 


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