[gimp] app: correctly deal with color profiles when converting from/to GRAY



commit b3dbb968c90065e1d6f260f936538c91ddac44a0
Author: Michael Natterer <mitch gimp org>
Date:   Fri Dec 25 23:07:26 2015 +0100

    app: correctly deal with color profiles when converting from/to GRAY
    
    Convert the layers to the new GimpImageBaseType's builtin color
    profile because the converted image will have its color profile
    removed.

 app/core/gimpimage-convert-type.c |    8 +++++---
 app/core/gimplayer.c              |   36 +++++++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 12 deletions(-)
---
diff --git a/app/core/gimpimage-convert-type.c b/app/core/gimpimage-convert-type.c
index 2118523..12f4e0a 100644
--- a/app/core/gimpimage-convert-type.c
+++ b/app/core/gimpimage-convert-type.c
@@ -1092,7 +1092,10 @@ gimp_image_convert_type (GimpImage               *image,
       break;
     }
 
-  /* TODO: attach or remove the ICC profile */
+  /*  When converting to/from GRAY, remove the profile.
+   *  gimp_layer_convert_type() has converted the layers to
+   *  new_type's builtin profile.
+   */
   switch (new_type)
     {
     case GIMP_RGB:
@@ -1100,11 +1103,10 @@ gimp_image_convert_type (GimpImage               *image,
       if (old_type == GIMP_GRAY)
         gimp_image_set_color_profile (image, NULL, NULL);
       break;
+
     case GIMP_GRAY:
       gimp_image_set_color_profile (image, NULL, NULL);
       break;
-    default:
-      break;
     }
 
   /*  Delete the quantizer object, if there is one */
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 1fce1ce..dab1df6 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -173,7 +173,7 @@ static void       gimp_layer_convert_type       (GimpDrawable       *drawable,
                                                  GimpPrecision       new_precision,
                                                  gint                layer_dither_type,
                                                  gint                mask_dither_type,
-                                                 gboolean            convert_type,
+                                                 gboolean            convert_profile,
                                                  gboolean            push_undo,
                                                  GimpProgress       *progress);
 static void    gimp_layer_invalidate_boundary   (GimpDrawable       *drawable);
@@ -1122,14 +1122,16 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
         {
           const Babl *src_format = gimp_drawable_get_format (drawable);
 
-          /* when converting between linear and gamma, we create a new
-           * profile using the original profile's chromacities and
-           * whitepoint, but a linear/sRGB-gamma TRC.
-           * gimp_image_convert_precision() will use the same profile.
-           */
           if (gimp_babl_format_get_linear (src_format) !=
               gimp_babl_format_get_linear (new_format))
             {
+              /* when converting between linear and gamma, we create a
+               * new profile using the original profile's chromacities
+               * and whitepoint, but a linear/sRGB-gamma TRC.
+               * gimp_image_convert_precision() will use the same
+               * profile.
+               */
+
               src_profile =
                 gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (layer));
 
@@ -1144,9 +1146,9 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
                     gimp_color_profile_new_srgb_gamma_from_color_profile (src_profile);
                 }
 
-              /* if a new profile cannot be be generated, convert to the
-               * builtin profile, which is better than leaving the user
-               * with broken colors
+              /* if a new profile cannot be be generated, convert to
+               * the builtin profile, which is better than leaving the
+               * user with broken colors
                */
               if (! dest_profile)
                 {
@@ -1155,6 +1157,22 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
                   g_object_ref (dest_profile);
                 }
             }
+          else if (gimp_drawable_get_base_type (drawable) != new_base_type &&
+                   (gimp_drawable_get_base_type (drawable) == GIMP_GRAY ||
+                    new_base_type                          == GIMP_GRAY))
+            {
+              /* when converting to/from GRAY, convert to the new
+               * type's builtin profile because the conversion will
+               * get rid of the profile, see gimp_image_convert_type().
+               */
+
+              src_profile =
+                gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (layer));
+
+              dest_profile =
+                gimp_image_get_builtin_color_profile (dest_image);
+              g_object_ref (dest_profile);
+           }
         }
     }
 


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