[gimp/soc/2022/cmyk: 19/20] core: Add softproof profile to GimpImage




commit 831503a114fde0ee84e524064b230c5db105a0c0
Author: Alx Sa <cmyk student gmail com>
Date:   Tue May 31 20:59:31 2022 +0000

    core: Add softproof profile to GimpImage
    
    Adds a simulation_profile to GimpImage to allow plug-ins to access it
    for CMYK import/export.
    Two pdb functions were added to enable this access:
    image_get_simulation_profile () and image_set_simulation_profile()

 app/core/gimpimage-color-profile.c  |  26 ++++
 app/core/gimpimage-color-profile.h  |   4 +
 app/core/gimpimage-private.h        |   1 +
 app/pdb/image-color-profile-cmds.c  | 229 ++++++++++++++++++++++++++++++++++++
 libgimp/gimp.def                    |   3 +
 libgimp/gimpimagecolorprofile.c     |  69 +++++++++++
 libgimp/gimpimagecolorprofile.h     |   4 +
 libgimp/gimpimagecolorprofile_pdb.c | 135 +++++++++++++++++++++
 libgimp/gimpimagecolorprofile_pdb.h |  43 ++++---
 pdb/groups/image_color_profile.pdb  | 142 ++++++++++++++++++++++
 pdb/stddefs.pdb                     |   4 +
 11 files changed, 642 insertions(+), 18 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index f3e5c8dfdd..64f868818d 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -391,6 +391,32 @@ gimp_image_set_color_profile (GimpImage         *image,
   return gimp_image_set_icc_profile (image, data, length, error);
 }
 
+GimpColorProfile *
+gimp_image_get_simulation_profile (GimpImage *image)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  return GIMP_IMAGE_GET_PRIVATE (image)->simulation_profile;
+}
+
+void
+gimp_image_set_simulation_profile (GimpImage         *image,
+                                   GimpColorProfile  *profile)
+{
+  GimpImagePrivate *private;
+
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+  g_return_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile));
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  if (profile != private->simulation_profile)
+    {
+      g_set_object (&private->simulation_profile, profile);
+      gimp_color_managed_simulation_profile_changed (GIMP_COLOR_MANAGED (image));
+    }
+}
+
 gboolean
 gimp_image_validate_color_profile_by_format (const Babl         *format,
                                              GimpColorProfile   *profile,
diff --git a/app/core/gimpimage-color-profile.h b/app/core/gimpimage-color-profile.h
index 863c41bda7..6548d36c1e 100644
--- a/app/core/gimpimage-color-profile.h
+++ b/app/core/gimpimage-color-profile.h
@@ -64,6 +64,10 @@ gboolean             gimp_image_set_color_profile      (GimpImage           *ima
                                                         GimpColorProfile    *profile,
                                                         GError             **error);
 
+GimpColorProfile   * gimp_image_get_simulation_profile (GimpImage           *image);
+void                 gimp_image_set_simulation_profile (GimpImage           *image,
+                                                        GimpColorProfile    *profile);
+
 gboolean             gimp_image_validate_color_profile_by_format
                                                        (const Babl          *format,
                                                         GimpColorProfile    *profile,
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index 80e42dbd32..2beda44946 100644
--- a/app/core/gimpimage-private.h
+++ b/app/core/gimpimage-private.h
@@ -63,6 +63,7 @@ struct _GimpImagePrivate
   GimpColorProfile  *color_profile;         /*  image's color profile        */
   const Babl        *layer_space;           /*  image's Babl layer space     */
   GimpColorProfile  *hidden_profile;        /*  hidden by "use sRGB"         */
+  GimpColorProfile  *simulation_profile;    /*  image's softproof profile    */
 
   /*  Cached color transforms: from layer to sRGB u8 and double, and back    */
   gboolean            color_transforms_created;
diff --git a/app/pdb/image-color-profile-cmds.c b/app/pdb/image-color-profile-cmds.c
index ba57055d31..e9cc4ebb5b 100644
--- a/app/pdb/image-color-profile-cmds.c
+++ b/app/pdb/image-color-profile-cmds.c
@@ -226,6 +226,138 @@ image_set_color_profile_from_file_invoker (GimpProcedure         *procedure,
                                            error ? *error : NULL);
 }
 
+static GimpValueArray *
+image_get_simulation_profile_invoker (GimpProcedure         *procedure,
+                                      Gimp                  *gimp,
+                                      GimpContext           *context,
+                                      GimpProgress          *progress,
+                                      const GimpValueArray  *args,
+                                      GError               **error)
+{
+  gboolean success = TRUE;
+  GimpValueArray *return_vals;
+  GimpImage *image;
+  gint num_bytes = 0;
+  guint8 *profile_data = NULL;
+
+  image = g_value_get_object (gimp_value_array_index (args, 0));
+
+  if (success)
+    {
+      GimpColorProfile *profile;
+
+      profile = gimp_image_get_simulation_profile (image);
+
+      if (profile)
+        {
+          const guint8 *data;
+          gsize         length;
+
+          data = gimp_color_profile_get_icc_profile (profile, &length);
+
+          profile_data = g_memdup2 (data, length);
+          num_bytes = length;
+        }
+    }
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    {
+      g_value_set_int (gimp_value_array_index (return_vals, 1), num_bytes);
+      gimp_value_take_uint8_array (gimp_value_array_index (return_vals, 2), profile_data, num_bytes);
+    }
+
+  return return_vals;
+}
+
+static GimpValueArray *
+image_set_simulation_profile_invoker (GimpProcedure         *procedure,
+                                      Gimp                  *gimp,
+                                      GimpContext           *context,
+                                      GimpProgress          *progress,
+                                      const GimpValueArray  *args,
+                                      GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  gint num_bytes;
+  const guint8 *color_profile;
+
+  image = g_value_get_object (gimp_value_array_index (args, 0));
+  num_bytes = g_value_get_int (gimp_value_array_index (args, 1));
+  color_profile = gimp_value_get_uint8_array (gimp_value_array_index (args, 2));
+
+  if (success)
+    {
+      if (color_profile)
+        {
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_icc_profile (color_profile,
+                                                             num_bytes,
+                                                             error);
+
+          if (profile)
+            {
+              gimp_image_set_simulation_profile (image, profile);
+              g_object_unref (profile);
+            }
+          else
+            success = FALSE;
+        }
+      else
+        {
+          gimp_image_set_simulation_profile (image, NULL);
+        }
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
+image_set_simulation_profile_from_file_invoker (GimpProcedure         *procedure,
+                                                Gimp                  *gimp,
+                                                GimpContext           *context,
+                                                GimpProgress          *progress,
+                                                const GimpValueArray  *args,
+                                                GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  GFile *file;
+
+  image = g_value_get_object (gimp_value_array_index (args, 0));
+  file = g_value_get_object (gimp_value_array_index (args, 1));
+
+  if (success)
+    {
+      if (file)
+        {
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          if (profile)
+            {
+              gimp_image_set_simulation_profile (image, profile);
+              g_object_unref (profile);
+            }
+          else
+            success = FALSE;
+        }
+      else
+        {
+          gimp_image_set_simulation_profile (image, NULL);
+        }
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 static GimpValueArray *
 image_convert_color_profile_invoker (GimpProcedure         *procedure,
                                      Gimp                  *gimp,
@@ -456,6 +588,103 @@ register_image_color_profile_procs (GimpPDB *pdb)
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 
+  /*
+   * gimp-image-get-simulation-profile
+   */
+  procedure = gimp_procedure_new (image_get_simulation_profile_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-get-simulation-profile");
+  gimp_procedure_set_static_help (procedure,
+                                  "Returns the image's simulation color profile",
+                                  "This procedure returns the image's simulation color profile, or NULL if 
the image has no simulation color profile assigned.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Michael Natterer <mitch gimp org>",
+                                         "Michael Natterer",
+                                         "2022");
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image ("image",
+                                                      "image",
+                                                      "The image",
+                                                      FALSE,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_return_value (procedure,
+                                   g_param_spec_int ("num-bytes",
+                                                     "num bytes",
+                                                     "Number of bytes in the color_profile array",
+                                                     0, G_MAXINT32, 0,
+                                                     GIMP_PARAM_READWRITE));
+  gimp_procedure_add_return_value (procedure,
+                                   gimp_param_spec_uint8_array ("profile-data",
+                                                                "profile data",
+                                                                "The image's serialized simulation color 
profile.",
+                                                                GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-image-set-simulation-profile
+   */
+  procedure = gimp_procedure_new (image_set_simulation_profile_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-set-simulation-profile");
+  gimp_procedure_set_static_help (procedure,
+                                  "Sets the image's simulation color profile",
+                                  "This procedure sets the image's simulation color profile, or unsets it if 
NULL is passed as 'color_profile'. This procedure does no color conversion. However, it will change the pixel 
format of all layers to contain the babl space matching the profile. You must call this procedure before 
adding layers to the image.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Michael Natterer <mitch gimp org>",
+                                         "Michael Natterer",
+                                         "2022");
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image ("image",
+                                                      "image",
+                                                      "The image",
+                                                      FALSE,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_int ("num-bytes",
+                                                 "num bytes",
+                                                 "Number of bytes in the color_profile array",
+                                                 0, G_MAXINT32, 0,
+                                                 GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_uint8_array ("color-profile",
+                                                            "color profile",
+                                                            "The new serialized simulation color profile",
+                                                            GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-image-set-simulation-profile-from-file
+   */
+  procedure = gimp_procedure_new (image_set_simulation_profile_from_file_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-set-simulation-profile-from-file");
+  gimp_procedure_set_static_help (procedure,
+                                  "Sets the image's simulation color profile from an ICC file",
+                                  "This procedure sets the image's simulation color profile from a file 
containing an ICC profile, or unsets it if NULL is passed as 'file'. This procedure does no color conversion. 
However, it will change the pixel format of all layers to contain the babl space matching the profile. You 
must call this procedure before adding layers to the image.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Michael Natterer <mitch gimp org>",
+                                         "Michael Natterer",
+                                         "2022");
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image ("image",
+                                                      "image",
+                                                      "The image",
+                                                      FALSE,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_object ("file",
+                                                    "file",
+                                                    "The file containing the new simulation color profile",
+                                                    G_TYPE_FILE,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
   /*
    * gimp-image-convert-color-profile
    */
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index b05044bb11..0cde15376d 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -420,6 +420,7 @@ EXPORTS
        gimp_image_get_sample_point_position
        gimp_image_get_selected_layers
        gimp_image_get_selection
+       gimp_image_get_simulation_profile
        gimp_image_get_tattoo_state
        gimp_image_get_thumbnail
        gimp_image_get_thumbnail_data
@@ -498,6 +499,8 @@ EXPORTS
        gimp_image_set_metadata
        gimp_image_set_resolution
        gimp_image_set_selected_layers
+       gimp_image_set_simulation_profile
+       gimp_image_set_simulation_profile_from_file
        gimp_image_set_tattoo_state
        gimp_image_set_unit
        gimp_image_take_selected_layers
diff --git a/libgimp/gimpimagecolorprofile.c b/libgimp/gimpimagecolorprofile.c
index bb22bd5ce8..6850e410d7 100644
--- a/libgimp/gimpimagecolorprofile.c
+++ b/libgimp/gimpimagecolorprofile.c
@@ -92,6 +92,75 @@ gimp_image_set_color_profile (GimpImage        *image,
   return _gimp_image_set_color_profile (image, length, data);
 }
 
+/**
+ * gimp_image_get_simulation_profile:
+ * @image: The image.
+ *
+ * Returns the image's simulation color profile
+ *
+ * This procedure returns the image's simulation color profile, or NULL if
+ * the image has no simulation color profile assigned.
+ *
+ * Returns: (transfer full): The image's simulation color profile. The
+ *          returned value must be freed with g_object_unref().
+ *
+ * Since: 2.10
+ **/
+GimpColorProfile *
+gimp_image_get_simulation_profile (GimpImage *image)
+{
+  guint8 *data;
+  gint    length;
+
+  data = _gimp_image_get_simulation_profile (image, &length);
+
+  if (data)
+    {
+      GimpColorProfile *profile;
+
+      profile = gimp_color_profile_new_from_icc_profile (data, length, NULL);
+      g_free (data);
+
+      return profile;
+    }
+
+  return NULL;
+}
+
+/**
+ * gimp_image_set_simulation_profile:
+ * @image:   The image.
+ * @profile: A #GimpColorProfile, or %NULL.
+ *
+ * Sets the image's simulation color profile
+ *
+ * This procedure sets the image's simulation color profile.
+ *
+ * Returns: %TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_image_set_simulation_profile (GimpImage        *image,
+                                   GimpColorProfile *profile)
+{
+  const guint8 *data   = NULL;
+  gint          length = 0;
+
+  g_return_val_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile),
+                        FALSE);
+
+  if (profile)
+    {
+      gsize l;
+
+      data = gimp_color_profile_get_icc_profile (profile, &l);
+      length = l;
+    }
+
+  return _gimp_image_set_simulation_profile (image, length, data);
+}
+
 /**
  * gimp_image_get_effective_color_profile:
  * @image: The image.
diff --git a/libgimp/gimpimagecolorprofile.h b/libgimp/gimpimagecolorprofile.h
index 63ae015f04..92e4e60123 100644
--- a/libgimp/gimpimagecolorprofile.h
+++ b/libgimp/gimpimagecolorprofile.h
@@ -34,6 +34,10 @@ GimpColorProfile * gimp_image_get_color_profile           (GimpImage
 gboolean           gimp_image_set_color_profile           (GimpImage                 *image,
                                                            GimpColorProfile          *profile);
 
+GimpColorProfile * gimp_image_get_simulation_profile      (GimpImage                 *image);
+gboolean           gimp_image_set_simulation_profile      (GimpImage                 *image,
+                                                           GimpColorProfile          *profile);
+
 GimpColorProfile * gimp_image_get_effective_color_profile (GimpImage                 *image);
 
 gboolean           gimp_image_convert_color_profile       (GimpImage                 *image,
diff --git a/libgimp/gimpimagecolorprofile_pdb.c b/libgimp/gimpimagecolorprofile_pdb.c
index e2f761d40b..8f5b94ca85 100644
--- a/libgimp/gimpimagecolorprofile_pdb.c
+++ b/libgimp/gimpimagecolorprofile_pdb.c
@@ -220,6 +220,141 @@ gimp_image_set_color_profile_from_file (GimpImage *image,
   return success;
 }
 
+/**
+ * _gimp_image_get_simulation_profile:
+ * @image: The image.
+ * @num_bytes: (out): Number of bytes in the color_profile array.
+ *
+ * Returns the image's simulation color profile
+ *
+ * This procedure returns the image's simulation color profile, or NULL
+ * if the image has no simulation color profile assigned.
+ *
+ * Returns: (array length=num_bytes) (element-type guint8) (transfer full):
+ *          The image's serialized simulation color profile.
+ *          The returned value must be freed with g_free().
+ *
+ * Since: 2.10
+ **/
+guint8 *
+_gimp_image_get_simulation_profile (GimpImage *image,
+                                    gint      *num_bytes)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  guint8 *profile_data = NULL;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          GIMP_TYPE_IMAGE, image,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-image-get-simulation-profile",
+                                              args);
+  gimp_value_array_unref (args);
+
+  *num_bytes = 0;
+
+  if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+    {
+      *num_bytes = GIMP_VALUES_GET_INT (return_vals, 1);
+      profile_data = GIMP_VALUES_DUP_UINT8_ARRAY (return_vals, 2);
+    }
+
+  gimp_value_array_unref (return_vals);
+
+  return profile_data;
+}
+
+/**
+ * _gimp_image_set_simulation_profile:
+ * @image: The image.
+ * @num_bytes: Number of bytes in the color_profile array.
+ * @color_profile: (array length=num_bytes) (element-type guint8): The new serialized simulation color 
profile.
+ *
+ * Sets the image's simulation color profile
+ *
+ * This procedure sets the image's simulation color profile, or unsets
+ * it if NULL is passed as 'color_profile'. This procedure does no
+ * color conversion. However, it will change the pixel format of all
+ * layers to contain the babl space matching the profile. You must call
+ * this procedure before adding layers to the image.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+_gimp_image_set_simulation_profile (GimpImage    *image,
+                                    gint          num_bytes,
+                                    const guint8 *color_profile)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean success = TRUE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          GIMP_TYPE_IMAGE, image,
+                                          G_TYPE_INT, num_bytes,
+                                          GIMP_TYPE_UINT8_ARRAY, NULL,
+                                          G_TYPE_NONE);
+  gimp_value_set_uint8_array (gimp_value_array_index (args, 2), color_profile, num_bytes);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-image-set-simulation-profile",
+                                              args);
+  gimp_value_array_unref (args);
+
+  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+  gimp_value_array_unref (return_vals);
+
+  return success;
+}
+
+/**
+ * gimp_image_set_simulation_profile_from_file:
+ * @image: The image.
+ * @file: The file containing the new simulation color profile.
+ *
+ * Sets the image's simulation color profile from an ICC file
+ *
+ * This procedure sets the image's simulation color profile from a file
+ * containing an ICC profile, or unsets it if NULL is passed as 'file'.
+ * This procedure does no color conversion. However, it will change the
+ * pixel format of all layers to contain the babl space matching the
+ * profile. You must call this procedure before adding layers to the
+ * image.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_image_set_simulation_profile_from_file (GimpImage *image,
+                                             GFile     *file)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean success = TRUE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          GIMP_TYPE_IMAGE, image,
+                                          G_TYPE_FILE, file,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-image-set-simulation-profile-from-file",
+                                              args);
+  gimp_value_array_unref (args);
+
+  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+  gimp_value_array_unref (return_vals);
+
+  return success;
+}
+
 /**
  * _gimp_image_convert_color_profile:
  * @image: The image.
diff --git a/libgimp/gimpimagecolorprofile_pdb.h b/libgimp/gimpimagecolorprofile_pdb.h
index 0731a9eb1e..ac49fc8f9f 100644
--- a/libgimp/gimpimagecolorprofile_pdb.h
+++ b/libgimp/gimpimagecolorprofile_pdb.h
@@ -32,24 +32,31 @@ G_BEGIN_DECLS
 /* For information look into the C source or the html documentation */
 
 
-G_GNUC_INTERNAL guint8*  _gimp_image_get_color_profile              (GimpImage                *image,
-                                                                     gint                     *num_bytes);
-G_GNUC_INTERNAL guint8*  _gimp_image_get_effective_color_profile    (GimpImage                *image,
-                                                                     gint                     *num_bytes);
-G_GNUC_INTERNAL gboolean _gimp_image_set_color_profile              (GimpImage                *image,
-                                                                     gint                      num_bytes,
-                                                                     const guint8             
*color_profile);
-gboolean                 gimp_image_set_color_profile_from_file     (GimpImage                *image,
-                                                                     GFile                    *file);
-G_GNUC_INTERNAL gboolean _gimp_image_convert_color_profile          (GimpImage                *image,
-                                                                     gint                      num_bytes,
-                                                                     const guint8             *color_profile,
-                                                                     GimpColorRenderingIntent  intent,
-                                                                     gboolean                  bpc);
-gboolean                 gimp_image_convert_color_profile_from_file (GimpImage                *image,
-                                                                     GFile                    *file,
-                                                                     GimpColorRenderingIntent  intent,
-                                                                     gboolean                  bpc);
+G_GNUC_INTERNAL guint8*  _gimp_image_get_color_profile               (GimpImage                *image,
+                                                                      gint                     *num_bytes);
+G_GNUC_INTERNAL guint8*  _gimp_image_get_effective_color_profile     (GimpImage                *image,
+                                                                      gint                     *num_bytes);
+G_GNUC_INTERNAL gboolean _gimp_image_set_color_profile               (GimpImage                *image,
+                                                                      gint                      num_bytes,
+                                                                      const guint8             
*color_profile);
+gboolean                 gimp_image_set_color_profile_from_file      (GimpImage                *image,
+                                                                      GFile                    *file);
+G_GNUC_INTERNAL guint8*  _gimp_image_get_simulation_profile          (GimpImage                *image,
+                                                                      gint                     *num_bytes);
+G_GNUC_INTERNAL gboolean _gimp_image_set_simulation_profile          (GimpImage                *image,
+                                                                      gint                      num_bytes,
+                                                                      const guint8             
*color_profile);
+gboolean                 gimp_image_set_simulation_profile_from_file (GimpImage                *image,
+                                                                      GFile                    *file);
+G_GNUC_INTERNAL gboolean _gimp_image_convert_color_profile           (GimpImage                *image,
+                                                                      gint                      num_bytes,
+                                                                      const guint8             
*color_profile,
+                                                                      GimpColorRenderingIntent  intent,
+                                                                      gboolean                  bpc);
+gboolean                 gimp_image_convert_color_profile_from_file  (GimpImage                *image,
+                                                                      GFile                    *file,
+                                                                      GimpColorRenderingIntent  intent,
+                                                                      gboolean                  bpc);
 
 
 G_END_DECLS
diff --git a/pdb/groups/image_color_profile.pdb b/pdb/groups/image_color_profile.pdb
index 1f9231ca13..e50a7fa049 100644
--- a/pdb/groups/image_color_profile.pdb
+++ b/pdb/groups/image_color_profile.pdb
@@ -213,6 +213,145 @@ CODE
     );
 }
 
+sub image_get_simulation_profile {
+    $blurb = "Returns the image's simulation color profile";
+
+    $help = <<'HELP';
+This procedure returns the image's simulation color profile, or NULL if the image
+has no simulation color profile assigned.
+HELP
+
+    &alxsa_pdb_misc('2022', '3.0');
+
+    $lib_private = 1;
+
+    @inargs = (
+        { name => 'image', type => 'image',
+          desc => 'The image' }
+    );
+
+    @outargs = (
+        { name => 'profile_data', type => 'int8array',
+          desc => "The image's serialized simulation color profile.",
+          array => { name => 'num_bytes',
+                     desc => 'Number of bytes in the color_profile array' } }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  GimpColorProfile *profile;
+
+  profile = gimp_image_get_simulation_profile (image);
+
+  if (profile)
+    {
+      const guint8 *data;
+      gsize         length;
+
+      data = gimp_color_profile_get_icc_profile (profile, &length);
+
+      profile_data = g_memdup2 (data, length);
+      num_bytes = length;
+    }
+}
+CODE
+    );
+}
+
+sub image_set_simulation_profile {
+    $blurb = "Sets the image's simulation color profile";
+
+    $help = <<'HELP';
+This procedure sets the image's simulation color profile, or unsets it if NULL is
+passed as 'color_profile'. This procedure does no color conversion.
+HELP
+
+    &alxsa_pdb_misc('2022', '3.0');
+
+    $lib_private = 1;
+
+    @inargs = (
+        { name => 'image', type => 'image',
+          desc => 'The image' },
+        { name => 'color_profile', type => 'int8array',
+          desc => 'The new serialized simulation color profile',
+          array => { name => 'num_bytes',
+                     desc => 'Number of bytes in the color_profile array' } }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  if (color_profile)
+    {
+      GimpColorProfile *profile;
+
+      profile = gimp_color_profile_new_from_icc_profile (color_profile,
+                                                         num_bytes,
+                                                         error);
+
+      if (profile)
+        {
+          gimp_image_set_simulation_profile (image, profile);
+          g_object_unref (profile);
+        }
+      else
+        success = FALSE;
+    }
+  else
+    {
+      gimp_image_set_simulation_profile (image, NULL);
+    }
+}
+CODE
+    );
+}
+
+sub image_set_simulation_profile_from_file {
+    $blurb = "Sets the image's simulation color profile from an ICC file";
+
+    $help = <<'HELP';
+This procedure sets the image's simulation color profile from a file containing
+an ICC profile, or unsets it if NULL is passed as 'file'. This
+procedure does no color conversion.
+HELP
+
+    &alxsa_pdb_misc('2022', '3.0');
+
+    @inargs = (
+        { name => 'image', type => 'image',
+          desc => 'The image' },
+        { name => 'file', type => 'file',
+          desc => 'The file containing the new simulation color profile' }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  if (file)
+    {
+      GimpColorProfile *profile;
+
+      profile = gimp_color_profile_new_from_file (file, error);
+
+      if (profile)
+        {
+          gimp_image_set_simulation_profile (image, profile);
+          g_object_unref (profile);
+        }
+      else
+        success = FALSE;
+    }
+  else
+    {
+      gimp_image_set_simulation_profile (image, NULL);
+    }
+}
+CODE
+    );
+}
+
 sub image_convert_color_profile {
     $blurb = "Convert the image's layers to a color profile";
 
@@ -326,6 +465,9 @@ CODE
             image_get_effective_color_profile
             image_set_color_profile
             image_set_color_profile_from_file
+            image_get_simulation_profile
+            image_set_simulation_profile
+            image_set_simulation_profile_from_file
             image_convert_color_profile
             image_convert_color_profile_from_file);
 
diff --git a/pdb/stddefs.pdb b/pdb/stddefs.pdb
index 9c7a7ac49d..6e9fd4ce9c 100644
--- a/pdb/stddefs.pdb
+++ b/pdb/stddefs.pdb
@@ -165,6 +165,10 @@ sub yosh_pdb_misc {
     contrib_pdb_misc('Manish Singh', '', @_);
 }
 
+sub alxsa_pdb_misc {
+    contrib_pdb_misc('Alex S.', '', @_);
+}
+
 sub std_pdb_deprecated {
     if (@_) {
         $blurb = $help = '';


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