[gimp] pdb, libgimp: add gimp_image_set_color_profile_from_file()



commit b0735c9448a793da8445f6be5606bc30dcb8e89a
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 28 23:01:18 2015 +0200

    pdb, libgimp: add gimp_image_set_color_profile_from_file()
    
    which sets the profile from a file containing an ICC profile.

 app/pdb/image-color-profile-cmds.c       |   76 +++++++++++++++++++++++++++++-
 app/pdb/internal-procs.c                 |    2 +-
 libgimp/gimp.def                         |    1 +
 libgimp/gimpimagecolorprofile_pdb.c      |   39 +++++++++++++++-
 libgimp/gimpimagecolorprofile_pdb.h      |    2 +
 tools/pdbgen/pdb/image_color_profile.pdb |   50 +++++++++++++++++++-
 6 files changed, 166 insertions(+), 4 deletions(-)
---
diff --git a/app/pdb/image-color-profile-cmds.c b/app/pdb/image-color-profile-cmds.c
index dad6f89..111006a 100644
--- a/app/pdb/image-color-profile-cmds.c
+++ b/app/pdb/image-color-profile-cmds.c
@@ -180,6 +180,50 @@ image_set_color_profile_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
+image_set_color_profile_from_file_invoker (GimpProcedure         *procedure,
+                                           Gimp                  *gimp,
+                                           GimpContext           *context,
+                                           GimpProgress          *progress,
+                                           const GimpValueArray  *args,
+                                           GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  const gchar *uri;
+
+  image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
+  uri = g_value_get_string (gimp_value_array_index (args, 1));
+
+  if (success)
+    {
+      if (uri)
+        {
+          GFile            *file = g_file_new_for_uri (uri);
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          if (profile)
+            {
+              success = gimp_image_set_color_profile (image, profile, error);
+              g_object_unref (profile);
+            }
+          else
+            success = FALSE;
+
+          g_object_unref (file);
+        }
+      else
+        {
+          success = gimp_image_set_color_profile (image, NULL, error);
+        }
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 image_convert_color_profile_invoker (GimpProcedure         *procedure,
                                      Gimp                  *gimp,
                                      GimpContext           *context,
@@ -310,7 +354,7 @@ register_image_color_profile_procs (GimpPDB *pdb)
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-image-set-color-profile",
                                      "Sets the image's color profile",
-                                     "This procedure sets the image's color profile, or unsets it if NULL is 
passed as 'color_profile'.",
+                                     "This procedure sets the image's color profile, or unsets it if NULL is 
passed as 'color_profile'. This procedure does no color conversion.",
                                      "Michael Natterer <mitch gimp org>",
                                      "Michael Natterer",
                                      "2015",
@@ -336,6 +380,36 @@ register_image_color_profile_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-image-set-color-profile-from-file
+   */
+  procedure = gimp_procedure_new (image_set_color_profile_from_file_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-set-color-profile-from-file");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-image-set-color-profile-from-file",
+                                     "Sets the image's color profile from an ICC file",
+                                     "This procedure sets the image's color profile from a file containing 
an ICC profile, or unsets it if NULL is passed as 'uri'. This procedure does no color conversion.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2015",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image_id ("image",
+                                                         "image",
+                                                         "The image",
+                                                         pdb->gimp, FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_string ("uri",
+                                                       "uri",
+                                                       "The URI of the file containing the new color 
profile",
+                                                       FALSE, FALSE, FALSE,
+                                                       NULL,
+                                                       GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-image-convert-color-profile
    */
   procedure = gimp_procedure_new (image_convert_color_profile_invoker);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 06970ed..a7f2dda 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 766 procedures registered total */
+/* 767 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index de42af0..3649c30 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -498,6 +498,7 @@ EXPORTS
        gimp_image_set_active_vectors
        gimp_image_set_cmap
        gimp_image_set_color_profile
+       gimp_image_set_color_profile_from_file
        gimp_image_set_colormap
        gimp_image_set_component_active
        gimp_image_set_component_visible
diff --git a/libgimp/gimpimagecolorprofile_pdb.c b/libgimp/gimpimagecolorprofile_pdb.c
index cd4c5d9..cbf7a90 100644
--- a/libgimp/gimpimagecolorprofile_pdb.c
+++ b/libgimp/gimpimagecolorprofile_pdb.c
@@ -137,7 +137,8 @@ _gimp_image_get_effective_color_profile (gint32  image_ID,
  * Sets the image's color profile
  *
  * This procedure sets the image's color profile, or unsets it if NULL
- * is passed as 'color_profile'.
+ * is passed as 'color_profile'. This procedure does no color
+ * conversion.
  *
  * Returns: TRUE on success.
  *
@@ -167,6 +168,42 @@ _gimp_image_set_color_profile (gint32        image_ID,
 }
 
 /**
+ * gimp_image_set_color_profile_from_file:
+ * @image_ID: The image.
+ * @uri: The URI of the file containing the new color profile.
+ *
+ * Sets the image's color profile from an ICC file
+ *
+ * This procedure sets the image's color profile from a file containing
+ * an ICC profile, or unsets it if NULL is passed as 'uri'. This
+ * procedure does no color conversion.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_image_set_color_profile_from_file (gint32       image_ID,
+                                        const gchar *uri)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-image-set-color-profile-from-file",
+                                    &nreturn_vals,
+                                    GIMP_PDB_IMAGE, image_ID,
+                                    GIMP_PDB_STRING, uri,
+                                    GIMP_PDB_END);
+
+  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return success;
+}
+
+/**
  * _gimp_image_convert_color_profile:
  * @image_ID: The image.
  * @num_bytes: Number of bytes in the color_profile array.
diff --git a/libgimp/gimpimagecolorprofile_pdb.h b/libgimp/gimpimagecolorprofile_pdb.h
index 844fcc4..cc9831c 100644
--- a/libgimp/gimpimagecolorprofile_pdb.h
+++ b/libgimp/gimpimagecolorprofile_pdb.h
@@ -39,6 +39,8 @@ G_GNUC_INTERNAL guint8*  _gimp_image_get_effective_color_profile (gint32
 G_GNUC_INTERNAL gboolean _gimp_image_set_color_profile           (gint32                    image_ID,
                                                                   gint                      num_bytes,
                                                                   const guint8             *color_profile);
+gboolean                 gimp_image_set_color_profile_from_file  (gint32                    image_ID,
+                                                                  const gchar              *uri);
 G_GNUC_INTERNAL gboolean _gimp_image_convert_color_profile       (gint32                    image_ID,
                                                                   gint                      num_bytes,
                                                                   const guint8             *color_profile,
diff --git a/tools/pdbgen/pdb/image_color_profile.pdb b/tools/pdbgen/pdb/image_color_profile.pdb
index d5aae04..7089570 100644
--- a/tools/pdbgen/pdb/image_color_profile.pdb
+++ b/tools/pdbgen/pdb/image_color_profile.pdb
@@ -113,7 +113,7 @@ sub image_set_color_profile {
 
     $help = <<'HELP';
 This procedure sets the image's color profile, or unsets it if NULL is
-passed as 'color_profile'.
+passed as 'color_profile'. This procedure does no color conversion.
 HELP
 
     &mitch_pdb_misc('2015', '2.10');
@@ -155,6 +155,53 @@ CODE
     );
 }
 
+sub image_set_color_profile_from_file {
+    $blurb = "Sets the image's color profile from an ICC file";
+
+    $help = <<'HELP';
+This procedure sets the image's color profile from a file containing
+an ICC profile, or unsets it if NULL is passed as 'uri'. This
+procedure does no color conversion.
+HELP
+
+    &mitch_pdb_misc('2015', '2.10');
+
+    @inargs = (
+        { name => 'image', type => 'image',
+          desc => 'The image' },
+        { name => 'uri', type => 'string',
+          desc => 'The URI of the file containing the new color profile' }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  if (uri)
+    {
+      GFile            *file = g_file_new_for_uri (uri);
+      GimpColorProfile *profile;
+
+      profile = gimp_color_profile_new_from_file (file, error);
+
+      if (profile)
+        {
+          success = gimp_image_set_color_profile (image, profile, error);
+          g_object_unref (profile);
+        }
+      else
+        success = FALSE;
+
+      g_object_unref (file);
+    }
+  else
+    {
+      success = gimp_image_set_color_profile (image, NULL, error);
+    }
+}
+CODE
+    );
+}
+
 sub image_convert_color_profile {
     $blurb = "Convert the image's layers to a color profile";
 
@@ -215,6 +262,7 @@ CODE
 @procs = qw(image_get_color_profile
             image_get_effective_color_profile
             image_set_color_profile
+            image_set_color_profile_from_file
             image_convert_color_profile);
 
 %exports = (app => [ procs], lib => [ procs]);


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