[gimp/gimp-2-10] app: GimpFgBgEditor displays the out-of-gamut color for indexed images.



commit e48c239459786566e1b5352f49847e1b86b45c6b
Author: Jehan <jehan girinstud io>
Date:   Wed Feb 13 15:19:07 2019 +0100

    app: GimpFgBgEditor displays the out-of-gamut color for indexed images.
    
    If a color is not within the indexed image's palette, we can consider it
    to be out-of-gamut too (the gamut of such image being its palette).
    
    This is a first step towards fixing #2938. Basically currently opening
    indexed images is not made obvious and you can end up thinking GIMP is
    broken as when you try to paint with a given FG or BG color, you may get
    a completely different color on the canvas. And it is not obvious to
    realize why. Now at least, the FG/BG color will tell you when the color
    you are trying to paint with is not within the accepted palette.
    
    (cherry picked from commit 7b4c96d03d863c021b2386168b07cc65ee6577f2)

 app/widgets/gimpfgbgeditor.c | 51 +++++++++++++++++++++++++++++++++++++++-----
 app/widgets/gimpfgbgeditor.h |  2 ++
 2 files changed, 48 insertions(+), 5 deletions(-)
---
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 07c434d70c..f0f34aa96c 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -35,7 +35,10 @@
 
 #include "core/gimp.h"
 #include "core/gimpcontext.h"
+#include "core/gimpimage.h"
+#include "core/gimpimage-colormap.h"
 #include "core/gimpmarshal.h"
+#include "core/gimppalette.h"
 
 #include "gimpdnd.h"
 #include "gimpfgbgeditor.h"
@@ -98,6 +101,8 @@ static void     gimp_fg_bg_editor_drop_color        (GtkWidget        *widget,
 static void     gimp_fg_bg_editor_create_transform  (GimpFgBgEditor   *editor);
 static void     gimp_fg_bg_editor_destroy_transform (GimpFgBgEditor   *editor);
 
+static void     gimp_fg_bg_editor_image_changed     (GimpFgBgEditor   *editor,
+                                                     GimpImage        *image);
 
 G_DEFINE_TYPE (GimpFgBgEditor, gimp_fg_bg_editor, GTK_TYPE_EVENT_BOX)
 
@@ -257,6 +262,7 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
   GtkStyle       *style  = gtk_widget_get_style (widget);
   GdkWindow      *window = gtk_widget_get_window (widget);
   cairo_t        *cr;
+  GimpPalette    *colormap_palette = NULL;
   GtkAllocation   allocation;
   gint            width, height;
   gint            default_w, default_h;
@@ -331,6 +337,10 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
   if (! editor->transform)
     gimp_fg_bg_editor_create_transform (editor);
 
+  if (gimp_context_get_image (editor->context) &&
+      gimp_image_get_base_type (gimp_context_get_image (editor->context)) == GIMP_INDEXED)
+    colormap_palette = gimp_image_get_colormap_palette (editor->active_image);
+
   /*  draw the background area  */
 
   if (editor->context)
@@ -356,10 +366,12 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
                        rect_h);
       cairo_fill (cr);
 
+
       if (editor->color_config &&
-          (color.r < 0.0 || color.r > 1.0 ||
-           color.g < 0.0 || color.g > 1.0 ||
-           color.b < 0.0 || color.b > 1.0))
+          ((color.r < 0.0 || color.r > 1.0 ||
+            color.g < 0.0 || color.g > 1.0 ||
+            color.b < 0.0 || color.b > 1.0) ||
+           (colormap_palette && ! gimp_palette_find_entry (colormap_palette, &color, NULL))))
         {
           gint side = MIN (rect_w, rect_h) * 2 / 3;
 
@@ -407,9 +419,10 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
       cairo_fill (cr);
 
       if (editor->color_config &&
-          (color.r < 0.0 || color.r > 1.0 ||
+          ((color.r < 0.0 || color.r > 1.0 ||
            color.g < 0.0 || color.g > 1.0 ||
-           color.b < 0.0 || color.b > 1.0))
+           color.b < 0.0 || color.b > 1.0) ||
+           (colormap_palette && ! gimp_palette_find_entry (colormap_palette, &color, NULL))))
         {
           gint side = MIN (rect_w, rect_h) * 2 / 3;
 
@@ -633,6 +646,9 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
           g_signal_handlers_disconnect_by_func (editor->context,
                                                 gtk_widget_queue_draw,
                                                 editor);
+          g_signal_handlers_disconnect_by_func (editor->context,
+                                                G_CALLBACK (gimp_fg_bg_editor_image_changed),
+                                                editor);
           g_object_unref (editor->context);
 
           g_signal_handlers_disconnect_by_func (editor->color_config,
@@ -653,6 +669,9 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
           g_signal_connect_swapped (context, "background-changed",
                                     G_CALLBACK (gtk_widget_queue_draw),
                                     editor);
+          g_signal_connect_swapped (context, "image-changed",
+                                    G_CALLBACK (gimp_fg_bg_editor_image_changed),
+                                    editor);
 
           editor->color_config = g_object_ref (context->gimp->config->color_management);
 
@@ -756,3 +775,25 @@ gimp_fg_bg_editor_destroy_transform (GimpFgBgEditor *editor)
 
   gtk_widget_queue_draw (GTK_WIDGET (editor));
 }
+
+static void
+gimp_fg_bg_editor_image_changed (GimpFgBgEditor *editor,
+                                 GimpImage      *image)
+{
+  gtk_widget_queue_draw (GTK_WIDGET (editor));
+
+  if (editor->active_image)
+    g_signal_handlers_disconnect_by_func (editor->active_image,
+                                          G_CALLBACK (gtk_widget_queue_draw),
+                                          editor);
+  editor->active_image = image;
+  if (image)
+    {
+      g_signal_connect_swapped (image, "notify::base-type",
+                                G_CALLBACK (gtk_widget_queue_draw),
+                                editor);
+      g_signal_connect_swapped (image, "colormap-changed",
+                                G_CALLBACK (gtk_widget_queue_draw),
+                                editor);
+    }
+}
diff --git a/app/widgets/gimpfgbgeditor.h b/app/widgets/gimpfgbgeditor.h
index 7c425afc7d..43113d50ca 100644
--- a/app/widgets/gimpfgbgeditor.h
+++ b/app/widgets/gimpfgbgeditor.h
@@ -52,6 +52,8 @@ struct _GimpFgBgEditor
 
   GimpActiveColor     active_color;
 
+  GimpImage          *active_image;
+
   GdkPixbuf          *default_icon;
   GdkPixbuf          *swap_icon;
 


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