[gimp] Bug 723392 - Pasting an image replaces color profile with default one



commit 235b4a5a678ad915f7441b29379fa97bb25eb6d2
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 16 16:00:32 2015 +0200

    Bug 723392 - Pasting an image replaces color profile with default one
    
    gimp_layer_convert_type(): implement color profile conversion. This
    should fix all DND operations between images with different profiles.

 app/core/gimplayer.c |   53 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 43 insertions(+), 10 deletions(-)
---
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index b4c15f3..fa11e75 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -34,6 +34,7 @@
 #include "config/gimpcoreconfig.h" /* FIXME profile convert config */
 
 #include "gegl/gimp-gegl-apply-operation.h"
+#include "gegl/gimp-gegl-loops.h"
 #include "gegl/gimp-gegl-nodes.h"
 
 #include "gimp.h" /* FIXME profile convert config */
@@ -1027,33 +1028,65 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
                          gboolean           push_undo)
 {
   GimpLayer  *layer = GIMP_LAYER (drawable);
+  GeglBuffer *src_buffer;
   GeglBuffer *dest_buffer;
 
-  dest_buffer =
-    gegl_buffer_new (GEGL_RECTANGLE (0, 0,
-                                     gimp_item_get_width  (GIMP_ITEM (drawable)),
-                                     gimp_item_get_height (GIMP_ITEM (drawable))),
-                     new_format);
-
   if (layer_dither_type == 0)
     {
-      gegl_buffer_copy (gimp_drawable_get_buffer (drawable), NULL,
-                        GEGL_ABYSS_NONE,
-                        dest_buffer, NULL);
+      src_buffer = g_object_ref (gimp_drawable_get_buffer (drawable));
     }
   else
     {
       gint bits;
 
+      src_buffer =
+        gegl_buffer_new (GEGL_RECTANGLE (0, 0,
+                                         gimp_item_get_width  (GIMP_ITEM (drawable)),
+                                         gimp_item_get_height (GIMP_ITEM (drawable))),
+                         gimp_drawable_get_format (drawable));
+
       bits = (babl_format_get_bytes_per_pixel (new_format) * 8 /
               babl_format_get_n_components (new_format));
 
       gimp_gegl_apply_color_reduction (gimp_drawable_get_buffer (drawable),
                                        NULL, NULL,
-                                       dest_buffer, bits, layer_dither_type);
+                                       src_buffer, bits, layer_dither_type);
+    }
+
+  dest_buffer =
+    gegl_buffer_new (GEGL_RECTANGLE (0, 0,
+                                     gimp_item_get_width  (GIMP_ITEM (drawable)),
+                                     gimp_item_get_height (GIMP_ITEM (drawable))),
+                     new_format);
+
+  if (convert_profile)
+    {
+      GimpImage        *src_image = gimp_item_get_image (GIMP_ITEM (layer));
+      GimpColorProfile *src_profile;
+      GimpColorProfile *dest_profile;
+
+      src_profile =
+        gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (src_image));
+
+      dest_profile =
+        gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (dest_image));
+
+      gimp_gegl_convert_color_profile (src_buffer,  NULL, src_profile,
+                                       dest_buffer, NULL, dest_profile,
+                                       GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
+                                       FALSE);
+
+      g_object_unref (src_profile);
+      g_object_unref (dest_profile);
+    }
+  else
+    {
+      gegl_buffer_copy (src_buffer, NULL, GEGL_ABYSS_NONE, dest_buffer, NULL);
     }
 
   gimp_drawable_set_buffer (drawable, push_undo, NULL, dest_buffer);
+
+  g_object_unref (src_buffer);
   g_object_unref (dest_buffer);
 
   if (layer->mask &&


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