[gimp] libgimp, pdb: new functions gimp_image_policy_rotate() and…



commit 5a8d69629abaa0311e20977dbd3cb84db4f3f94b
Author: Jehan <jehan girinstud io>
Date:   Thu Sep 24 02:53:24 2020 +0200

    libgimp, pdb: new functions gimp_image_policy_rotate() and…
    
    … gimp_image_policy_color_profile().
    These functions allow a plug-in to explicitly execute the Rotation and
    Profile conversion policies on an image (which may be any of
    Rotating/Discarding/Ask or Converting/Keeping/Ask respectively). These
    policies are automatically executed when loading an image from GIMP
    interfaces, but they won't be when loading an image from the PDB. Then
    it is up to the calling code to decide what to do (which can be either
    some arbitrary code or following the user policy).

 app/pdb/image-cmds.c     | 112 +++++++++++++++++++++++++++++++++++++++++++++++
 app/pdb/internal-procs.c |   2 +-
 libgimp/gimpimage_pdb.c  | 101 ++++++++++++++++++++++++++++++++++++++++++
 libgimp/gimpimage_pdb.h  |   4 ++
 pdb/groups/image.pdb     |  81 +++++++++++++++++++++++++++++++++-
 5 files changed, 298 insertions(+), 2 deletions(-)
---
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 44fcf02093..80a08c5c54 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -38,12 +38,14 @@
 #include "core/gimpcontainer.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpgrouplayer.h"
+#include "core/gimpimage-color-profile.h"
 #include "core/gimpimage-colormap.h"
 #include "core/gimpimage-duplicate.h"
 #include "core/gimpimage-merge.h"
 #include "core/gimpimage-metadata.h"
 #include "core/gimpimage-pick-color.h"
 #include "core/gimpimage-pick-item.h"
+#include "core/gimpimage-rotate.h"
 #include "core/gimpimage.h"
 #include "core/gimpitem.h"
 #include "core/gimplayer.h"
@@ -2819,6 +2821,54 @@ image_get_parasite_list_invoker (GimpProcedure         *procedure,
   return return_vals;
 }
 
+static GimpValueArray *
+image_policy_rotate_invoker (GimpProcedure         *procedure,
+                             Gimp                  *gimp,
+                             GimpContext           *context,
+                             GimpProgress          *progress,
+                             const GimpValueArray  *args,
+                             GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  gboolean interactive;
+
+  image = g_value_get_object (gimp_value_array_index (args, 0));
+  interactive = g_value_get_boolean (gimp_value_array_index (args, 1));
+
+  if (success)
+    {
+      gimp_image_import_rotation_metadata (image, context, progress, interactive);
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
+image_policy_color_profile_invoker (GimpProcedure         *procedure,
+                                    Gimp                  *gimp,
+                                    GimpContext           *context,
+                                    GimpProgress          *progress,
+                                    const GimpValueArray  *args,
+                                    GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  gboolean interactive;
+
+  image = g_value_get_object (gimp_value_array_index (args, 0));
+  interactive = g_value_get_boolean (gimp_value_array_index (args, 1));
+
+  if (success)
+    {
+      gimp_image_import_color_profile (image, context, progress, interactive);
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 void
 register_image_procs (GimpPDB *pdb)
 {
@@ -5533,4 +5583,66 @@ register_image_procs (GimpPDB *pdb)
                                                                  GIMP_PARAM_READWRITE));
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
+
+  /*
+   * gimp-image-policy-rotate
+   */
+  procedure = gimp_procedure_new (image_policy_rotate_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-policy-rotate");
+  gimp_procedure_set_static_help (procedure,
+                                  "Execute the \"Orientation\" metadata policy.",
+                                  "Process the image according to the rotation policy as set in Preferences. 
If GIMP is running as a GUI and interactive is TRUE, a dialog may be presented to the user depending on the 
set policy. Otherwise, if the policy does not mandate the action to perform, the image will be rotated 
following the Orientation metadata.\n"
+                                     "If you wish absolutely to rotate a loaded image following the 
Orientation metadata, do not use this function and process the metadata yourself. Indeed even with 
`interactive` to FALSE, user settings may leave the image unrotated.\n"
+                                     "Finally it is unnecessary to call this function in a format load 
procedure because this is called automatically by the core code when loading any image. You should only call 
this function explicitly when loading an image through a PDB call.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Jehan",
+                                         "Jehan",
+                                         "2020");
+  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_boolean ("interactive",
+                                                     "interactive",
+                                                     "Querying the user through a dialog is a possibility",
+                                                     FALSE,
+                                                     GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-image-policy-color-profile
+   */
+  procedure = gimp_procedure_new (image_policy_color_profile_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-policy-color-profile");
+  gimp_procedure_set_static_help (procedure,
+                                  "Execute the color profile conversion policy.",
+                                  "Process the image according to the color profile policy as set in 
Preferences. If GIMP is running as a GUI and interactive is TRUE, a dialog may be presented to the user 
depending on the set policy. Otherwise, if the policy does not mandate the conversion to perform, the 
conversion to the builtin RGB or grayscale profile will happen.\n"
+                                     "This function should be used only if you want to follow user settings. 
If you wish to keep to convert to a specific profile, call preferrably 'gimp-image-convert-color-profile'. 
And if you wish to leave whatever profile an image has, do not call any of these functions.\n"
+                                     "Finally it is unnecessary to call this function in a format load 
procedure because this is called automatically by the core code when loading any image. You should only call 
this function explicitly when loading an image through a PDB call.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Jehan",
+                                         "Jehan",
+                                         "2020");
+  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_boolean ("interactive",
+                                                     "interactive",
+                                                     "Querying the user through a dialog is a possibility",
+                                                     FALSE,
+                                                     GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
 }
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 123a42eeae..e869958ce5 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 753 procedures registered total */
+/* 755 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index 6acd41cf97..1510b7e91c 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -3422,3 +3422,104 @@ gimp_image_get_parasite_list (GimpImage *image,
 
   return parasites;
 }
+
+/**
+ * gimp_image_policy_rotate:
+ * @image: The image.
+ * @interactive: Querying the user through a dialog is a possibility.
+ *
+ * Execute the \"Orientation\" metadata policy.
+ *
+ * Process the image according to the rotation policy as set in
+ * Preferences. If GIMP is running as a GUI and interactive is TRUE, a
+ * dialog may be presented to the user depending on the set policy.
+ * Otherwise, if the policy does not mandate the action to perform, the
+ * image will be rotated following the Orientation metadata.
+ * If you wish absolutely to rotate a loaded image following the
+ * Orientation metadata, do not use this function and process the
+ * metadata yourself. Indeed even with `interactive` to FALSE, user
+ * settings may leave the image unrotated.
+ * Finally it is unnecessary to call this function in a format load
+ * procedure because this is called automatically by the core code when
+ * loading any image. You should only call this function explicitly
+ * when loading an image through a PDB call.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_image_policy_rotate (GimpImage *image,
+                          gboolean   interactive)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean success = TRUE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          GIMP_TYPE_IMAGE, image,
+                                          G_TYPE_BOOLEAN, interactive,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-image-policy-rotate",
+                                              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_policy_color_profile:
+ * @image: The image.
+ * @interactive: Querying the user through a dialog is a possibility.
+ *
+ * Execute the color profile conversion policy.
+ *
+ * Process the image according to the color profile policy as set in
+ * Preferences. If GIMP is running as a GUI and interactive is TRUE, a
+ * dialog may be presented to the user depending on the set policy.
+ * Otherwise, if the policy does not mandate the conversion to perform,
+ * the conversion to the builtin RGB or grayscale profile will happen.
+ * This function should be used only if you want to follow user
+ * settings. If you wish to keep to convert to a specific profile, call
+ * preferrably gimp_image_convert_color_profile(). And if you wish to
+ * leave whatever profile an image has, do not call any of these
+ * functions.
+ * Finally it is unnecessary to call this function in a format load
+ * procedure because this is called automatically by the core code when
+ * loading any image. You should only call this function explicitly
+ * when loading an image through a PDB call.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_image_policy_color_profile (GimpImage *image,
+                                 gboolean   interactive)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean success = TRUE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          GIMP_TYPE_IMAGE, image,
+                                          G_TYPE_BOOLEAN, interactive,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-image-policy-color-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;
+}
diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h
index d20bdd7322..4fcf0aa40c 100644
--- a/libgimp/gimpimage_pdb.h
+++ b/libgimp/gimpimage_pdb.h
@@ -195,6 +195,10 @@ GimpParasite*            gimp_image_get_parasite               (GimpImage
                                                                 const gchar         *name);
 gchar**                  gimp_image_get_parasite_list          (GimpImage           *image,
                                                                 gint                *num_parasites);
+gboolean                 gimp_image_policy_rotate              (GimpImage           *image,
+                                                                gboolean             interactive);
+gboolean                 gimp_image_policy_color_profile       (GimpImage           *image,
+                                                                gboolean             interactive);
 
 
 G_END_DECLS
diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb
index 59d90b84ae..fcb5e6a270 100644
--- a/pdb/groups/image.pdb
+++ b/pdb/groups/image.pdb
@@ -2978,13 +2978,90 @@ CODE
     );
 }
 
+sub image_policy_rotate {
+    $blurb = 'Execute the "Orientation" metadata policy.';
+    $help = <<'HELP';
+Process the image according to the rotation policy as set in Preferences.
+If GIMP is running as a GUI and interactive is TRUE, a dialog may be
+presented to the user depending on the set policy. Otherwise, if the
+policy does not mandate the action to perform, the image will be rotated
+following the Orientation metadata.
+
+If you wish absolutely to rotate a loaded image following the
+Orientation metadata, do not use this function and process the metadata
+yourself. Indeed even with `interactive` to FALSE, user settings may
+leave the image unrotated.
+
+Finally it is unnecessary to call this function in a format load
+procedure because this is called automatically by the core code when
+loading any image. You should only call this function explicitly when
+loading an image through a PDB call.
+HELP
+
+    &jehan_pdb_misc('2020', '3.0');
+
+    @inargs = (
+        { name => 'image', type => 'image',
+          desc => 'The image' },
+        { name => 'interactive', type => 'boolean',
+          desc => 'Querying the user through a dialog is a possibility' }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  gimp_image_import_rotation_metadata (image, context, progress, interactive);
+}
+CODE
+    );
+}
+
+sub image_policy_color_profile {
+    $blurb = 'Execute the color profile conversion policy.';
+    $help = <<'HELP';
+Process the image according to the color profile policy as set in Preferences.
+If GIMP is running as a GUI and interactive is TRUE, a dialog may be
+presented to the user depending on the set policy. Otherwise, if the
+policy does not mandate the conversion to perform, the conversion to the
+builtin RGB or grayscale profile will happen.
+
+This function should be used only if you want to follow user settings.
+If you wish to keep to convert to a specific profile, call preferrably
+gimp_image_convert_color_profile(). And if you wish to leave whatever
+profile an image has, do not call any of these functions.
+
+Finally it is unnecessary to call this function in a format load
+procedure because this is called automatically by the core code when
+loading any image. You should only call this function explicitly when
+loading an image through a PDB call.
+HELP
+
+    &jehan_pdb_misc('2020', '3.0');
+
+    @inargs = (
+        { name => 'image', type => 'image',
+          desc => 'The image' },
+        { name => 'interactive', type => 'boolean',
+          desc => 'Querying the user through a dialog is a possibility' }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  gimp_image_import_color_profile (image, context, progress, interactive);
+}
+CODE
+    );
+}
 
 @headers = qw("libgimpmath/gimpmath.h"
               "libgimpbase/gimpbase.h"
               "gegl/gimp-babl.h"
               "core/gimp.h"
               "core/gimpcontainer.h"
+              "core/gimpimage-color-profile.h"
               "core/gimpimage-metadata.h"
+              "core/gimpimage-rotate.h"
               "core/gimpprogress.h"
               "core/gimptempbuf.h"
               "file/file-utils.h"
@@ -3053,7 +3130,9 @@ CODE
             image_get_vectors_by_name
             image_attach_parasite image_detach_parasite
             image_get_parasite
-            image_get_parasite_list);
+            image_get_parasite_list
+            image_policy_rotate
+            image_policy_color_profile);
 
 %exports = (app => [@procs], lib => [@procs]);
 


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