[gimp] app: color manage GimpFgBgEditor, as used e.g. in the toolbox



commit 0cd3d7aa7b144913a0c5d2f8d6e29c5356981a12
Author: Michael Natterer <mitch gimp org>
Date:   Thu May 26 22:25:03 2016 +0200

    app: color manage GimpFgBgEditor, as used e.g. in the toolbox

 app/widgets/gimpfgbgeditor.c |  134 +++++++++++++++++++++++++++++++----------
 app/widgets/gimpfgbgeditor.h |   19 ++++---
 2 files changed, 112 insertions(+), 41 deletions(-)
---
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 101cc4f..2eec591 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -30,6 +30,9 @@
 
 #include "widgets-types.h"
 
+#include "config/gimpcoreconfig.h"
+
+#include "core/gimp.h"
 #include "core/gimpcontext.h"
 #include "core/gimpmarshal.h"
 
@@ -61,38 +64,42 @@ typedef enum
 } FgBgTarget;
 
 
-static void     gimp_fg_bg_editor_dispose         (GObject        *object);
-static void     gimp_fg_bg_editor_set_property    (GObject        *object,
-                                                   guint           property_id,
-                                                   const GValue   *value,
-                                                   GParamSpec     *pspec);
-static void     gimp_fg_bg_editor_get_property    (GObject        *object,
-                                                   guint           property_id,
-                                                   GValue         *value,
-                                                   GParamSpec     *pspec);
-
-static void     gimp_fg_bg_editor_style_set       (GtkWidget      *widget,
-                                                   GtkStyle       *prev_style);
-static gboolean gimp_fg_bg_editor_expose          (GtkWidget      *widget,
-                                                   GdkEventExpose *eevent);
-static gboolean gimp_fg_bg_editor_button_press    (GtkWidget      *widget,
-                                                   GdkEventButton *bevent);
-static gboolean gimp_fg_bg_editor_button_release  (GtkWidget      *widget,
-                                                   GdkEventButton *bevent);
-static gboolean gimp_fg_bg_editor_drag_motion     (GtkWidget      *widget,
-                                                   GdkDragContext *context,
-                                                   gint            x,
-                                                   gint            y,
-                                                   guint           time);
-
-static void     gimp_fg_bg_editor_drag_color      (GtkWidget      *widget,
-                                                   GimpRGB        *color,
-                                                   gpointer        data);
-static void     gimp_fg_bg_editor_drop_color      (GtkWidget      *widget,
-                                                   gint            x,
-                                                   gint            y,
-                                                   const GimpRGB  *color,
-                                                   gpointer        data);
+static void     gimp_fg_bg_editor_dispose         (GObject          *object);
+static void     gimp_fg_bg_editor_set_property    (GObject          *object,
+                                                   guint             property_id,
+                                                   const GValue     *value,
+                                                   GParamSpec       *pspec);
+static void     gimp_fg_bg_editor_get_property    (GObject          *object,
+                                                   guint             property_id,
+                                                   GValue           *value,
+                                                   GParamSpec       *pspec);
+
+static void     gimp_fg_bg_editor_style_set       (GtkWidget        *widget,
+                                                   GtkStyle         *prev_style);
+static gboolean gimp_fg_bg_editor_expose          (GtkWidget        *widget,
+                                                   GdkEventExpose   *eevent);
+static gboolean gimp_fg_bg_editor_button_press    (GtkWidget        *widget,
+                                                   GdkEventButton   *bevent);
+static gboolean gimp_fg_bg_editor_button_release  (GtkWidget        *widget,
+                                                   GdkEventButton   *bevent);
+static gboolean gimp_fg_bg_editor_drag_motion     (GtkWidget        *widget,
+                                                   GdkDragContext   *context,
+                                                   gint              x,
+                                                   gint              y,
+                                                   guint             time);
+
+static void     gimp_fg_bg_editor_drag_color      (GtkWidget        *widget,
+                                                   GimpRGB          *color,
+                                                   gpointer          data);
+static void     gimp_fg_bg_editor_drop_color      (GtkWidget        *widget,
+                                                   gint              x,
+                                                   gint              y,
+                                                   const GimpRGB    *color,
+                                                   gpointer          data);
+
+static void     gimp_fg_bg_editor_config_notify   (GimpColorConfig  *config,
+                                                   const GParamSpec *pspec,
+                                                   GimpFgBgEditor   *editor);
 
 
 G_DEFINE_TYPE (GimpFgBgEditor, gimp_fg_bg_editor, GTK_TYPE_DRAWING_AREA)
@@ -323,11 +330,36 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
   editor->rect_height = rect_h;
 
 
+  if (! editor->transform)
+    {
+      static GimpColorProfile *profile = NULL;
+
+      if (G_UNLIKELY (! profile))
+        profile = gimp_color_profile_new_rgb_srgb ();
+
+      editor->transform =
+        gimp_widget_get_color_transform (widget,
+                                         editor->color_config,
+                                         profile,
+                                         babl_format ("R'G'B'A double"),
+                                         babl_format ("R'G'B'A double"));
+    }
+
+
   /*  draw the background area  */
 
   if (editor->context)
     {
       gimp_context_get_background (editor->context, &color);
+
+      if (editor->transform)
+        gimp_color_transform_process_pixels (editor->transform,
+                                             babl_format ("R'G'B'A double"),
+                                             &color,
+                                             babl_format ("R'G'B'A double"),
+                                             &color,
+                                             1);
+
       gimp_cairo_set_source_rgb (cr, &color);
 
       cairo_rectangle (cr,
@@ -352,6 +384,15 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
   if (editor->context)
     {
       gimp_context_get_foreground (editor->context, &color);
+
+      if (editor->transform)
+        gimp_color_transform_process_pixels (editor->transform,
+                                             babl_format ("R'G'B'A double"),
+                                             &color,
+                                             babl_format ("R'G'B'A double"),
+                                             &color,
+                                             1);
+
       gimp_cairo_set_source_rgb (cr, &color);
 
       cairo_rectangle (cr,
@@ -537,7 +578,12 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
                                             gtk_widget_queue_draw,
                                             editor);
       g_object_unref (editor->context);
-      editor->context = NULL;
+
+      g_signal_handlers_disconnect_by_func (editor->color_config,
+                                            gimp_fg_bg_editor_config_notify,
+                                            editor);
+      g_object_unref (editor->color_config);
+      editor->color_config = NULL;
     }
 
   editor->context = context;
@@ -552,8 +598,16 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
       g_signal_connect_swapped (context, "background-changed",
                                 G_CALLBACK (gtk_widget_queue_draw),
                                 editor);
+
+      editor->color_config = g_object_ref (context->gimp->config->color_management);
+
+      g_signal_connect (editor->color_config, "notify",
+                        G_CALLBACK (gimp_fg_bg_editor_config_notify),
+                        editor);
     }
 
+  gimp_fg_bg_editor_config_notify (NULL, NULL, editor);
+
   g_object_notify (G_OBJECT (editor), "context");
 }
 
@@ -619,3 +673,17 @@ gimp_fg_bg_editor_drop_color (GtkWidget     *widget,
         }
     }
 }
+
+static void
+gimp_fg_bg_editor_config_notify (GimpColorConfig  *config,
+                                 const GParamSpec *pspec,
+                                 GimpFgBgEditor   *editor)
+{
+  if (editor->transform)
+    {
+      g_object_unref (editor->transform);
+      editor->transform = NULL;
+    }
+
+  gtk_widget_queue_draw (GTK_WIDGET (editor));
+}
diff --git a/app/widgets/gimpfgbgeditor.h b/app/widgets/gimpfgbgeditor.h
index dad36bf..19b57e5 100644
--- a/app/widgets/gimpfgbgeditor.h
+++ b/app/widgets/gimpfgbgeditor.h
@@ -34,17 +34,20 @@ typedef struct _GimpFgBgEditorClass GimpFgBgEditorClass;
 
 struct _GimpFgBgEditor
 {
-  GtkDrawingArea   parent_instance;
+  GtkDrawingArea      parent_instance;
 
-  GimpContext     *context;
-  GimpActiveColor  active_color;
+  GimpContext        *context;
+  GimpColorConfig    *color_config;
+  GimpColorTransform *transform;
 
-  GdkPixbuf       *default_icon;
-  GdkPixbuf       *swap_icon;
+  GimpActiveColor     active_color;
 
-  gint             rect_width;
-  gint             rect_height;
-  gint             click_target;
+  GdkPixbuf          *default_icon;
+  GdkPixbuf          *swap_icon;
+
+  gint                rect_width;
+  gint                rect_height;
+  gint                click_target;
 };
 
 struct _GimpFgBgEditorClass


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