[gimp/alxsa-softproof-in-xcf] core: Save/load soft-proofing profile in Image




commit aa3b5e1af188d1ba17a5274d231d0f529571b011
Author: Alx Sa <cmyk student gmail com>
Date:   Tue Jul 26 12:18:40 2022 +0000

    core: Save/load soft-proofing profile in Image
    
    Adds a parasite to .xcf that stores the soft-proofing profile.
    Existing color profile saving/loading functions now take in a
    parasite name parameter so they can be used for either profile.

 app/core/gimpimage-color-profile.c | 100 ++++++++++++++++++++++++++++++-------
 app/core/gimpimage-color-profile.h |  14 ++++--
 app/core/gimpimage-new.c           |   4 +-
 app/core/gimpimage.c               |  15 ++++--
 4 files changed, 108 insertions(+), 25 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index 64f868818d..0bbe3cef97 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -181,6 +181,7 @@ _gimp_image_set_hidden_profile (GimpImage        *image,
 gboolean
 gimp_image_validate_icc_parasite (GimpImage           *image,
                                   const GimpParasite  *icc_parasite,
+                                  const gchar         *profile_type,
                                   gboolean            *is_builtin,
                                   GError             **error)
 {
@@ -192,11 +193,19 @@ gimp_image_validate_icc_parasite (GimpImage           *image,
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   if (strcmp (gimp_parasite_get_name (icc_parasite),
-              GIMP_ICC_PROFILE_PARASITE_NAME) != 0)
+              profile_type) != 0)
     {
+      gchar *invalid_parasite_name;
+
+      invalid_parasite_name =
+        g_strdup_printf (_("ICC profile validation failed: "
+                           "Parasite's name is not '%s'"),
+                           profile_type);
+
       g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("ICC profile validation failed: "
-                             "Parasite's name is not 'icc-profile'"));
+                           invalid_parasite_name);
+
+      g_free (invalid_parasite_name);
       return FALSE;
     }
 
@@ -210,7 +219,14 @@ gimp_image_validate_icc_parasite (GimpImage           *image,
     }
 
   data = gimp_parasite_get_data (icc_parasite, &data_size);
-  return gimp_image_validate_icc_profile (image, data, data_size, is_builtin, error);
+
+  if (strcmp (gimp_parasite_get_name (icc_parasite),
+              GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+    return gimp_image_validate_icc_profile (image, data, data_size,
+                                            profile_type, is_builtin, error);
+
+  return gimp_image_validate_icc_profile (image, data, data_size,
+                                          profile_type, is_builtin, error);
 }
 
 const GimpParasite *
@@ -223,20 +239,22 @@ gimp_image_get_icc_parasite (GimpImage *image)
 
 void
 gimp_image_set_icc_parasite (GimpImage          *image,
-                             const GimpParasite *icc_parasite)
+                             const GimpParasite *icc_parasite,
+                             const gchar        *profile_type)
 {
   g_return_if_fail (GIMP_IS_IMAGE (image));
 
   if (icc_parasite)
     {
       g_return_if_fail (gimp_image_validate_icc_parasite (image, icc_parasite,
+                                                          profile_type,
                                                           NULL, NULL) == TRUE);
 
       gimp_image_parasite_attach (image, icc_parasite, TRUE);
     }
   else
     {
-      gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME, TRUE);
+      gimp_image_parasite_detach (image, profile_type, TRUE);
     }
 }
 
@@ -244,6 +262,7 @@ gboolean
 gimp_image_validate_icc_profile (GimpImage     *image,
                                  const guint8  *data,
                                  gsize          length,
+                                 const gchar   *profile_type,
                                  gboolean      *is_builtin,
                                  GError       **error)
 {
@@ -257,14 +276,25 @@ gimp_image_validate_icc_profile (GimpImage     *image,
 
   if (! profile)
     {
-      g_prefix_error (error, _("ICC profile validation failed: "));
+      if (g_strcmp0 (profile_type, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
+        g_prefix_error (error, _("ICC profile validation failed: "));
+      else if (g_strcmp0 (profile_type, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+        g_prefix_error (error, _("Simulation ICC profile validation failed: "));
+
       return FALSE;
     }
 
-  if (! gimp_image_validate_color_profile (image, profile, is_builtin, error))
+  if (g_strcmp0 (profile_type, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
     {
-      g_object_unref (profile);
-      return FALSE;
+      if (! gimp_image_validate_color_profile (image, profile, is_builtin, error))
+        {
+          g_object_unref (profile);
+          return FALSE;
+        }
+    }
+  else
+    {
+      *is_builtin = FALSE;
     }
 
   g_object_unref (profile);
@@ -305,6 +335,7 @@ gboolean
 gimp_image_set_icc_profile (GimpImage     *image,
                             const guint8  *data,
                             gsize          length,
+                            const gchar   *profile_type,
                             GError       **error)
 {
   GimpParasite *parasite = NULL;
@@ -317,13 +348,13 @@ gimp_image_set_icc_profile (GimpImage     *image,
     {
       gboolean is_builtin;
 
-      parasite = gimp_parasite_new (GIMP_ICC_PROFILE_PARASITE_NAME,
+      parasite = gimp_parasite_new (profile_type,
                                     GIMP_PARASITE_PERSISTENT |
                                     GIMP_PARASITE_UNDOABLE,
                                     length, data);
 
-      if (! gimp_image_validate_icc_parasite (image, parasite, &is_builtin,
-                                              error))
+      if (! gimp_image_validate_icc_parasite (image, parasite, profile_type,
+                                              &is_builtin, error))
         {
           gimp_parasite_free (parasite);
           return FALSE;
@@ -337,7 +368,7 @@ gimp_image_set_icc_profile (GimpImage     *image,
         }
     }
 
-  gimp_image_set_icc_parasite (image, parasite);
+  gimp_image_set_icc_parasite (image, parasite, profile_type);
 
   if (parasite)
     gimp_parasite_free (parasite);
@@ -388,7 +419,9 @@ gimp_image_set_color_profile (GimpImage         *image,
   if (profile)
     data = gimp_color_profile_get_icc_profile (profile, &length);
 
-  return gimp_image_set_icc_profile (image, data, length, error);
+  return gimp_image_set_icc_profile (image, data, length,
+                                     GIMP_ICC_PROFILE_PARASITE_NAME,
+                                     error);
 }
 
 GimpColorProfile *
@@ -399,14 +432,17 @@ gimp_image_get_simulation_profile (GimpImage *image)
   return GIMP_IMAGE_GET_PRIVATE (image)->simulation_profile;
 }
 
-void
+gboolean
 gimp_image_set_simulation_profile (GimpImage         *image,
                                    GimpColorProfile  *profile)
 {
   GimpImagePrivate *private;
+  const guint8     *data   = NULL;
+  gsize             length = 0;
 
-  g_return_if_fail (GIMP_IS_IMAGE (image));
-  g_return_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile));
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile),
+                        FALSE);
 
   private = GIMP_IMAGE_GET_PRIVATE (image);
 
@@ -415,6 +451,13 @@ gimp_image_set_simulation_profile (GimpImage         *image,
       g_set_object (&private->simulation_profile, profile);
       gimp_color_managed_simulation_profile_changed (GIMP_COLOR_MANAGED (image));
     }
+
+  if (profile)
+    data = gimp_color_profile_get_icc_profile (profile, &length);
+
+  return gimp_image_set_icc_profile (image, data, length,
+                                     GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME,
+                                     NULL);
 }
 
 gboolean
@@ -861,6 +904,27 @@ _gimp_image_update_color_profile (GimpImage          *image,
   gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
 }
 
+void
+_gimp_image_update_simulation_profile (GimpImage          *image,
+                                       const GimpParasite *icc_parasite)
+{
+  GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  g_clear_object (&private->simulation_profile);
+
+  if (icc_parasite)
+    {
+      const guint8 *data;
+      guint32       data_size;
+
+      data = gimp_parasite_get_data (icc_parasite, &data_size);
+      private->simulation_profile =
+        gimp_color_profile_new_from_icc_profile (data, data_size, NULL);
+    }
+
+  gimp_color_managed_simulation_profile_changed (GIMP_COLOR_MANAGED (image));
+}
+
 
 /*  private functions  */
 
diff --git a/app/core/gimpimage-color-profile.h b/app/core/gimpimage-color-profile.h
index 6548d36c1e..4302045502 100644
--- a/app/core/gimpimage-color-profile.h
+++ b/app/core/gimpimage-color-profile.h
@@ -22,7 +22,8 @@
 #define __GIMP_IMAGE_COLOR_PROFILE_H__
 
 
-#define GIMP_ICC_PROFILE_PARASITE_NAME "icc-profile"
+#define GIMP_ICC_PROFILE_PARASITE_NAME            "icc-profile"
+#define GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME "simulation-icc-profile"
 
 
 gboolean             gimp_image_get_use_srgb_profile   (GimpImage           *image,
@@ -37,15 +38,18 @@ void                 _gimp_image_set_hidden_profile    (GimpImage           *ima
 
 gboolean             gimp_image_validate_icc_parasite  (GimpImage           *image,
                                                         const GimpParasite  *icc_parasite,
+                                                        const gchar         *profile_type,
                                                         gboolean            *is_builtin,
                                                         GError             **error);
 const GimpParasite * gimp_image_get_icc_parasite       (GimpImage           *image);
 void                 gimp_image_set_icc_parasite       (GimpImage           *image,
-                                                        const GimpParasite  *icc_parasite);
+                                                        const GimpParasite  *icc_parasite,
+                                                        const gchar         *profile_type);
 
 gboolean             gimp_image_validate_icc_profile   (GimpImage           *image,
                                                         const guint8        *data,
                                                         gsize                length,
+                                                        const gchar         *profile_type,
                                                         gboolean            *is_builtin,
                                                         GError             **error);
 const guint8       * gimp_image_get_icc_profile        (GimpImage           *image,
@@ -53,6 +57,7 @@ const guint8       * gimp_image_get_icc_profile        (GimpImage           *ima
 gboolean             gimp_image_set_icc_profile        (GimpImage           *image,
                                                         const guint8        *data,
                                                         gsize                length,
+                                                        const gchar         *profile_type,
                                                         GError             **error);
 
 gboolean             gimp_image_validate_color_profile (GimpImage           *image,
@@ -65,7 +70,7 @@ gboolean             gimp_image_set_color_profile      (GimpImage           *ima
                                                         GError             **error);
 
 GimpColorProfile   * gimp_image_get_simulation_profile (GimpImage           *image);
-void                 gimp_image_set_simulation_profile (GimpImage           *image,
+gboolean             gimp_image_set_simulation_profile (GimpImage           *image,
                                                         GimpColorProfile    *profile);
 
 gboolean             gimp_image_validate_color_profile_by_format
@@ -122,6 +127,9 @@ void                 _gimp_image_free_color_profile    (GimpImage           *ima
 void                 _gimp_image_free_color_transforms (GimpImage           *image);
 void                 _gimp_image_update_color_profile  (GimpImage           *image,
                                                         const GimpParasite  *icc_parasite);
+void                 _gimp_image_update_simulation_profile
+                                                       (GimpImage           *image,
+                                                        const GimpParasite  *icc_parasite);
 
 
 #endif /* __GIMP_IMAGE_COLOR_PROFILE_H__ */
diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c
index bc8d50cdcf..bd442d1072 100644
--- a/app/core/gimpimage-new.c
+++ b/app/core/gimpimage-new.c
@@ -556,7 +556,9 @@ gimp_image_new_from_pixbuf (Gimp        *gimp,
   icc_data = gimp_pixbuf_get_icc_profile (pixbuf, &icc_len);
   if (icc_data)
     {
-      gimp_image_set_icc_profile (new_image, icc_data, icc_len, NULL);
+      gimp_image_set_icc_profile (new_image, icc_data, icc_len,
+                                  GIMP_ICC_PROFILE_PARASITE_NAME,
+                                  NULL);
       g_free (icc_data);
     }
 
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 1e5d4d9b00..3adeb390f8 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -4180,9 +4180,11 @@ gimp_image_parasite_validate (GimpImage           *image,
 
   name = gimp_parasite_get_name (parasite);
 
-  if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
+  if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0 ||
+      strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
     {
-      return gimp_image_validate_icc_parasite (image, parasite, NULL, error);
+      return gimp_image_validate_icc_parasite (image, parasite,
+                                               name, NULL, error);
     }
   else if (strcmp (name, "gimp-comment") == 0)
     {
@@ -4228,7 +4230,8 @@ gimp_image_parasite_attach (GimpImage          *image,
   name = gimp_parasite_get_name (parasite);
 
   /*  this is so ugly and is only for the PDB  */
-  if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
+  if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0 ||
+      strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
     {
       GimpColorProfile *profile;
       GimpColorProfile *builtin;
@@ -4283,6 +4286,9 @@ gimp_image_parasite_attach (GimpImage          *image,
   if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
     _gimp_image_update_color_profile (image, parasite);
 
+  if (strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+    _gimp_image_update_simulation_profile (image, parasite);
+
   g_signal_emit (image, gimp_image_signals[PARASITE_ATTACHED], 0,
                  name);
 }
@@ -4313,6 +4319,9 @@ gimp_image_parasite_detach (GimpImage   *image,
   if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
     _gimp_image_update_color_profile (image, NULL);
 
+  if (strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+    _gimp_image_update_simulation_profile (image, NULL);
+
   g_signal_emit (image, gimp_image_signals[PARASITE_DETACHED], 0,
                  name);
 }


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