[gimp] app: make is impossible to tag the image with a built-in profile



commit a36f37b2f4fc0e6e05740cc56b5f2d1431d515b3
Author: Michael Natterer <mitch gimp org>
Date:   Mon Aug 17 10:37:55 2015 +0200

    app: make is impossible to tag the image with a built-in profile
    
    by moving the code preventing it to more low-level places. The piece
    in gimp_image_parasite_attach() is particularly evil.

 app/core/gimpimage-color-profile.c |   45 ++++++++++++++++++++++-------------
 app/core/gimpimage-color-profile.h |    3 ++
 app/core/gimpimage.c               |   23 +++++++++++++++++-
 3 files changed, 53 insertions(+), 18 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index 982d08a..eee93d3 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -71,6 +71,7 @@ static void   gimp_image_convert_profile_indexed (GimpImage                *imag
 gboolean
 gimp_image_validate_icc_parasite (GimpImage           *image,
                                   const GimpParasite  *icc_parasite,
+                                  gboolean            *is_builtin,
                                   GError             **error)
 {
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
@@ -98,6 +99,7 @@ gimp_image_validate_icc_parasite (GimpImage           *image,
   return gimp_image_validate_icc_profile (image,
                                           gimp_parasite_data (icc_parasite),
                                           gimp_parasite_data_size (icc_parasite),
+                                          is_builtin,
                                           error);
 }
 
@@ -118,7 +120,7 @@ gimp_image_set_icc_parasite (GimpImage          *image,
   if (icc_parasite)
     {
       g_return_if_fail (gimp_image_validate_icc_parasite (image, icc_parasite,
-                                                          NULL) == TRUE);
+                                                          NULL, NULL) == TRUE);
 
       gimp_image_parasite_attach (image, icc_parasite);
     }
@@ -132,6 +134,7 @@ gboolean
 gimp_image_validate_icc_profile (GimpImage     *image,
                                  const guint8  *data,
                                  gsize          length,
+                                 gboolean      *is_builtin,
                                  GError       **error)
 {
   GimpColorProfile *profile;
@@ -149,7 +152,7 @@ gimp_image_validate_icc_profile (GimpImage     *image,
       return FALSE;
     }
 
-  if (! gimp_image_validate_color_profile (image, profile, error))
+  if (! gimp_image_validate_color_profile (image, profile, is_builtin, error))
     {
       g_object_unref (profile);
       return FALSE;
@@ -198,16 +201,26 @@ gimp_image_set_icc_profile (GimpImage     *image,
 
   if (data)
     {
+      gboolean is_builtin;
+
       parasite = gimp_parasite_new (GIMP_ICC_PROFILE_PARASITE_NAME,
                                     GIMP_PARASITE_PERSISTENT |
                                     GIMP_PARASITE_UNDOABLE,
                                     length, data);
 
-      if (! gimp_image_validate_icc_parasite (image, parasite, error))
+      if (! gimp_image_validate_icc_parasite (image, parasite, &is_builtin,
+                                              error))
         {
           gimp_parasite_free (parasite);
           return FALSE;
         }
+
+      /*  don't tag the image with the built-in profile  */
+      if (is_builtin)
+        {
+          gimp_parasite_free (parasite);
+          parasite = NULL;
+        }
     }
 
   gimp_image_set_icc_parasite (image, parasite);
@@ -221,6 +234,7 @@ gimp_image_set_icc_profile (GimpImage     *image,
 gboolean
 gimp_image_validate_color_profile (GimpImage        *image,
                                    GimpColorProfile *profile,
+                                   gboolean         *is_builtin,
                                    GError          **error)
 {
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
@@ -243,6 +257,15 @@ gimp_image_validate_color_profile (GimpImage        *image,
       return FALSE;
     }
 
+  if (is_builtin)
+    {
+      GimpColorProfile *builtin;
+
+      builtin = gimp_image_get_builtin_color_profile (image);
+
+      *is_builtin = gimp_color_profile_is_equal (profile, builtin);
+    }
+
   return TRUE;
 }
 
@@ -323,14 +346,13 @@ gimp_image_convert_color_profile (GimpImage                *image,
                                   GError                  **error)
 {
   GimpColorProfile *src_profile;
-  GimpColorProfile *builtin_profile;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
   g_return_val_if_fail (dest_profile != NULL, FALSE);
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  if (! gimp_image_validate_color_profile (image, dest_profile, error))
+  if (! gimp_image_validate_color_profile (image, dest_profile, NULL, error))
     return FALSE;
 
   src_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
@@ -350,18 +372,7 @@ gimp_image_convert_color_profile (GimpImage                *image,
   gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT,
                                _("Color profile conversion"));
 
-  builtin_profile = gimp_image_get_builtin_color_profile (image);
-
-  if (gimp_color_profile_is_equal (dest_profile, builtin_profile))
-    {
-      /*  don't tag the image with the built-in profile  */
-      gimp_image_set_color_profile (image, NULL, NULL);
-    }
-  else
-    {
-      gimp_image_set_color_profile (image, dest_profile, NULL);
-    }
-
+  gimp_image_set_color_profile (image, dest_profile, NULL);
   /*  omg...  */
   gimp_image_parasite_detach (image, "icc-profile-name");
 
diff --git a/app/core/gimpimage-color-profile.h b/app/core/gimpimage-color-profile.h
index 3ead665..89ad0e5 100644
--- a/app/core/gimpimage-color-profile.h
+++ b/app/core/gimpimage-color-profile.h
@@ -27,6 +27,7 @@
 
 gboolean             gimp_image_validate_icc_parasite  (GimpImage           *image,
                                                         const GimpParasite  *icc_parasite,
+                                                        gboolean            *is_builtin,
                                                         GError             **error);
 const GimpParasite * gimp_image_get_icc_parasite       (GimpImage           *image);
 void                 gimp_image_set_icc_parasite       (GimpImage           *image,
@@ -35,6 +36,7 @@ void                 gimp_image_set_icc_parasite       (GimpImage           *ima
 gboolean             gimp_image_validate_icc_profile   (GimpImage           *image,
                                                         const guint8        *data,
                                                         gsize                length,
+                                                        gboolean            *is_builtin,
                                                         GError             **error);
 const guint8       * gimp_image_get_icc_profile        (GimpImage           *image,
                                                         gsize               *length);
@@ -45,6 +47,7 @@ gboolean             gimp_image_set_icc_profile        (GimpImage           *ima
 
 gboolean             gimp_image_validate_color_profile (GimpImage           *image,
                                                         GimpColorProfile    *profile,
+                                                        gboolean            *is_builtin,
                                                         GError             **error);
 GimpColorProfile   * gimp_image_get_color_profile      (GimpImage           *image);
 gboolean             gimp_image_set_color_profile      (GimpImage           *image,
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 796d7d9..a02ae3f 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -3309,7 +3309,7 @@ gimp_image_parasite_validate (GimpImage           *image,
 
   if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
     {
-      return gimp_image_validate_icc_parasite (image, parasite, error);
+      return gimp_image_validate_icc_parasite (image, parasite, NULL, error);
     }
 
   return TRUE;
@@ -3327,6 +3327,27 @@ gimp_image_parasite_attach (GimpImage          *image,
 
   private = GIMP_IMAGE_GET_PRIVATE (image);
 
+  /*  this is so ugly and is only for the PDB  */
+  if (strcmp (gimp_parasite_name (parasite), GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
+    {
+      GimpColorProfile *profile;
+      GimpColorProfile *builtin;
+
+      profile =
+        gimp_color_profile_new_from_icc_profile (gimp_parasite_data (parasite),
+                                                 gimp_parasite_data_size (parasite),
+                                                 NULL);
+      builtin = gimp_image_get_builtin_color_profile (image);
+
+      if (gimp_color_profile_is_equal (profile, builtin))
+        {
+          gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME);
+          g_object_unref (profile);
+        }
+
+      g_object_unref (profile);
+    }
+
   /*  make a temporary copy of the GimpParasite struct because
    *  gimp_parasite_shift_parent() changes it
    */


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