[gimp] Bug 766988 - Colors applied to images are not color managed



commit e9e1bc1e22edff4e6b924a81e2b58f2e78e33e09
Author: Michael Natterer <mitch gimp org>
Date:   Sun Oct 9 15:53:43 2016 +0200

    Bug 766988 - Colors applied to images are not color managed
    
    We didn't convert patterns to the target drawable's profile when using
    gimp_drawable_fill().
    
    Introduce gimp_drawable_fill_buffer() as single filling utility
    function that does things right and use it from gimp_drawable_fill()
    and gimp_fill_options_create_buffer().

 app/core/gimpdrawable-fill.c |   67 +++++++++++++++++++++++++++++++++--------
 app/core/gimpdrawable-fill.h |   10 +++++-
 app/core/gimpfilloptions.c   |   46 ++++------------------------
 3 files changed, 69 insertions(+), 54 deletions(-)
---
diff --git a/app/core/gimpdrawable-fill.c b/app/core/gimpdrawable-fill.c
index 29e919a..0907328 100644
--- a/app/core/gimpdrawable-fill.c
+++ b/app/core/gimpdrawable-fill.c
@@ -25,7 +25,9 @@
 
 #include "core-types.h"
 
+#include "gegl/gimp-babl.h"
 #include "gegl/gimp-gegl-apply-operation.h"
+#include "gegl/gimp-gegl-loops.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimp-utils.h"
@@ -60,34 +62,73 @@ gimp_drawable_fill (GimpDrawable *drawable,
   if (! gimp_get_fill_params (context, fill_type, &color, &pattern, NULL))
     return;
 
+  gimp_drawable_fill_buffer (drawable,
+                             gimp_drawable_get_buffer (drawable),
+                             &color, pattern, 0, 0);
+
+  gimp_drawable_update (drawable,
+                        0, 0,
+                        gimp_item_get_width  (GIMP_ITEM (drawable)),
+                        gimp_item_get_height (GIMP_ITEM (drawable)));
+}
+
+void
+gimp_drawable_fill_buffer (GimpDrawable  *drawable,
+                           GeglBuffer    *buffer,
+                           const GimpRGB *color,
+                           GimpPattern   *pattern,
+                           gint           pattern_offset_x,
+                           gint           pattern_offset_y)
+{
+  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
+  g_return_if_fail (GEGL_IS_BUFFER (buffer));
+  g_return_if_fail (color != NULL || pattern != NULL);
+  g_return_if_fail (pattern == NULL || GIMP_IS_PATTERN (pattern));
+
   if (pattern)
     {
-      GeglBuffer *src_buffer = gimp_pattern_create_buffer (pattern);
+      const Babl       *format;
+      GeglBuffer       *src_buffer;
+      GeglBuffer       *dest_buffer;
+      GimpColorProfile *src_profile;
+      GimpColorProfile *dest_profile;
+
+      src_buffer = gimp_pattern_create_buffer (pattern);
+      format = gegl_buffer_get_format (src_buffer);
+
+      dest_buffer = gegl_buffer_new (gegl_buffer_get_extent (src_buffer),
+                                     format);
+
+      src_profile  = gimp_babl_format_get_color_profile (format);
+      dest_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (drawable));
+
+      gimp_gegl_convert_color_profile (src_buffer,  NULL, src_profile,
+                                       dest_buffer, NULL, dest_profile,
+                                       GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
+                                       TRUE,
+                                       NULL);
+
+      gegl_buffer_set_pattern (buffer, NULL, dest_buffer,
+                               pattern_offset_x, pattern_offset_y);
 
-      gegl_buffer_set_pattern (gimp_drawable_get_buffer (drawable),
-                               NULL, src_buffer, 0, 0);
       g_object_unref (src_buffer);
+      g_object_unref (dest_buffer);
     }
   else
     {
+      GimpRGB    image_color;
       GeglColor *gegl_color;
 
       gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
-                                         &color, &color);
+                                         color, &image_color);
 
       if (! gimp_drawable_has_alpha (drawable))
-        gimp_rgb_set_alpha (&color, 1.0);
+        gimp_rgb_set_alpha (&image_color, 1.0);
 
-      gegl_color = gimp_gegl_color_new (&color);
-      gegl_buffer_set_color (gimp_drawable_get_buffer (drawable),
-                             NULL, gegl_color);
+      gegl_color = gimp_gegl_color_new (&image_color);
+      gegl_buffer_set_color (buffer, NULL, gegl_color);
       g_object_unref (gegl_color);
     }
-
-  gimp_drawable_update (drawable,
-                        0, 0,
-                        gimp_item_get_width  (GIMP_ITEM (drawable)),
-                        gimp_item_get_height (GIMP_ITEM (drawable)));
 }
 
 void
diff --git a/app/core/gimpdrawable-fill.h b/app/core/gimpdrawable-fill.h
index 65744e5..807d180 100644
--- a/app/core/gimpdrawable-fill.h
+++ b/app/core/gimpdrawable-fill.h
@@ -19,13 +19,19 @@
 #define __GIMP_DRAWABLE_FILL_H__
 
 
-/*  Lowlevel API that is used for initializing the entire drawable
- *  before it is added to the image, doesn't even push an undo.
+/*  Lowlevel API that is used for initializing entire drawables and
+ *  buffers before they are used in images, they don't push an undo.
  */
 
 void       gimp_drawable_fill              (GimpDrawable        *drawable,
                                             GimpContext         *context,
                                             GimpFillType         fill_type);
+void       gimp_drawable_fill_buffer       (GimpDrawable        *drawable,
+                                            GeglBuffer          *buffer,
+                                            const GimpRGB       *color,
+                                            GimpPattern         *pattern,
+                                            gint                 pattern_offset_x,
+                                            gint                 pattern_offset_y);
 
 
 /*  Proper API that is used for actual editing (not just initializing)
diff --git a/app/core/gimpfilloptions.c b/app/core/gimpfilloptions.c
index 5a6c723..9f09542 100644
--- a/app/core/gimpfilloptions.c
+++ b/app/core/gimpfilloptions.c
@@ -24,23 +24,18 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
 
-#include "libgimpbase/gimpbase.h"
 #include "libgimpcolor/gimpcolor.h"
 #include "libgimpconfig/gimpconfig.h"
 
 #include "core-types.h"
 
-#include "gegl/gimp-babl.h"
-#include "gegl/gimp-gegl-loops.h"
-#include "gegl/gimp-gegl-utils.h"
-
 #include "gimp.h"
 #include "gimp-palettes.h"
 #include "gimpdrawable.h"
+#include "gimpdrawable-fill.h"
 #include "gimperror.h"
 #include "gimpfilloptions.h"
 #include "gimppattern.h"
-#include "gimppickable.h"
 
 #include "gimp-intl.h"
 
@@ -433,51 +428,24 @@ gimp_fill_options_create_buffer (GimpFillOptions     *options,
     {
     case GIMP_FILL_STYLE_SOLID:
       {
-        GimpRGB    color;
-        GeglColor *gegl_color;
+        GimpRGB color;
 
         gimp_context_get_foreground (GIMP_CONTEXT (options), &color);
         gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, &color);
 
-        gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
-                                           &color, &color);
-
-        gegl_color = gimp_gegl_color_new (&color);
-        gegl_buffer_set_color (buffer, NULL, gegl_color);
-        g_object_unref (gegl_color);
+        gimp_drawable_fill_buffer (drawable, buffer,
+                                   &color, NULL, 0, 0);
       }
       break;
 
     case GIMP_FILL_STYLE_PATTERN:
       {
-        GimpPattern      *pattern;
-        const Babl       *format;
-        GeglBuffer       *src_buffer;
-        GeglBuffer       *dest_buffer;
-        GimpColorProfile *src_profile;
-        GimpColorProfile *dest_profile;
+        GimpPattern *pattern;
 
         pattern = gimp_context_get_pattern (GIMP_CONTEXT (options));
 
-        src_buffer = gimp_pattern_create_buffer (pattern);
-        format = gegl_buffer_get_format (src_buffer);
-
-        dest_buffer = gegl_buffer_new (gegl_buffer_get_extent (src_buffer),
-                                       gegl_buffer_get_format (src_buffer));
-
-        src_profile  = gimp_babl_format_get_color_profile (format);
-        dest_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (drawable));
-
-        gimp_gegl_convert_color_profile (src_buffer,  NULL, src_profile,
-                                         dest_buffer, NULL, dest_profile,
-                                         GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
-                                         TRUE,
-                                         NULL);
-
-        gegl_buffer_set_pattern (buffer, NULL, dest_buffer, 0, 0);
-
-        g_object_unref (src_buffer);
-        g_object_unref (dest_buffer);
+        gimp_drawable_fill_buffer (drawable, buffer,
+                                   NULL, pattern, 0, 0);
       }
       break;
     }


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