[gimp] plug-ins, pdb: remove "set" and "set-rgb" from the lcms plug-in



commit fa5d28aad3c2d26f75d33b7725762dacf5be9f18
Author: Michael Natterer <mitch gimp org>
Date:   Wed Aug 5 01:03:33 2015 +0200

    plug-ins, pdb: remove "set" and "set-rgb" from the lcms plug-in
    
    and add PDB compat procedures.

 app/pdb/internal-procs.c            |    2 +-
 app/pdb/plug-in-compat-cmds.c       |  195 +++++++++++++++++++++++++++++++++++
 plug-ins/common/lcms.c              |  132 -----------------------
 tools/pdbgen/pdb/plug_in_compat.pdb |  143 +++++++++++++++++++++++++
 4 files changed, 339 insertions(+), 133 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 6f0b6e0..926cacb 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 768 procedures registered total */
+/* 770 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c
index c3cd7dd..67d2a3d 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -27,16 +27,20 @@
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpcolor/gimpcolor.h"
+#include "libgimpconfig/gimpconfig.h"
 #include "libgimpmath/gimpmath.h"
 
 #include "libgimpbase/gimpbase.h"
 
 #include "pdb-types.h"
 
+#include "config/gimpcoreconfig.h"
+#include "core/gimp.h"
 #include "core/gimpchannel.h"
 #include "core/gimpcontext.h"
 #include "core/gimpdrawable-operation.h"
 #include "core/gimpdrawable.h"
+#include "core/gimpimage-color-profile.h"
 #include "core/gimpimage-crop.h"
 #include "core/gimpimage-resize.h"
 #include "core/gimpimage-rotate.h"
@@ -1962,6 +1966,130 @@ plug_in_icc_profile_file_info_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
+plug_in_icc_profile_set_invoker (GimpProcedure         *procedure,
+                                 Gimp                  *gimp,
+                                 GimpContext           *context,
+                                 GimpProgress          *progress,
+                                 const GimpValueArray  *args,
+                                 GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  const gchar *profile;
+
+  image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp);
+  profile = g_value_get_string (gimp_value_array_index (args, 2));
+
+  if (success)
+    {
+      if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
+        {
+          GFile            *file = NULL;
+          GimpColorProfile *p    = NULL;
+
+          if (profile)
+            file = g_file_new_for_path (profile);
+          else if (image->gimp->config->color_management->rgb_profile)
+            file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
+
+          if (file)
+            {
+              p = gimp_color_profile_new_from_file (file, error);
+
+              if (! p)
+                success = FALSE;
+
+              g_object_unref (file);
+            }
+
+          if (success)
+            {
+              gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_MISC,
+                                           _("Set color profile"));
+
+              if (gimp_image_set_color_profile (image, p, error))
+                gimp_image_parasite_detach (image, "icc-profile-name");
+              else
+                success = FALSE;
+
+              gimp_image_undo_group_end (image);
+
+              if (! success)
+                gimp_image_undo (image);
+
+              if (p)
+                g_object_unref (p);
+            }
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
+plug_in_icc_profile_set_rgb_invoker (GimpProcedure         *procedure,
+                                     Gimp                  *gimp,
+                                     GimpContext           *context,
+                                     GimpProgress          *progress,
+                                     const GimpValueArray  *args,
+                                     GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+
+  image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp);
+
+  if (success)
+    {
+      if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
+        {
+          GFile            *file = NULL;
+          GimpColorProfile *p    = NULL;
+
+          if (image->gimp->config->color_management->rgb_profile)
+            file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
+
+          if (file)
+            {
+              p = gimp_color_profile_new_from_file (file, error);
+
+              if (! p)
+                success = FALSE;
+
+              g_object_unref (file);
+            }
+
+          if (success)
+            {
+              gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_MISC,
+                                           _("Set color profile"));
+
+              if (gimp_image_set_color_profile (image, p, error))
+                gimp_image_parasite_detach (image, "icc-profile-name");
+              else
+                success = FALSE;
+
+              gimp_image_undo_group_end (image);
+
+              if (! success)
+                gimp_image_undo (image);
+
+              if (p)
+                g_object_unref (p);
+            }
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 plug_in_illusion_invoker (GimpProcedure         *procedure,
                           Gimp                  *gimp,
                           GimpContext           *context,
@@ -5861,6 +5989,73 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-plug-in-icc-profile-set
+   */
+  procedure = gimp_procedure_new (plug_in_icc_profile_set_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-icc-profile-set");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-icc-profile-set",
+                                     "Set a color profile on the image",
+                                     "This procedure sets the user-configured RGB profile on an image using 
the 'icc-profile' parasite. This procedure does not do any color conversion.",
+                                     "Sven Neumann <sven gimp org>",
+                                     "Sven Neumann",
+                                     "2015",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("run-mode",
+                                                  "run mode",
+                                                  "The run mode",
+                                                  GIMP_TYPE_RUN_MODE,
+                                                  GIMP_RUN_INTERACTIVE,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image_id ("image",
+                                                         "image",
+                                                         "Input image",
+                                                         pdb->gimp, FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_string ("profile",
+                                                       "profile",
+                                                       "Filename of an ICC color profile",
+                                                       TRUE, FALSE, FALSE,
+                                                       NULL,
+                                                       GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-plug-in-icc-profile-set-rgb
+   */
+  procedure = gimp_procedure_new (plug_in_icc_profile_set_rgb_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-icc-profile-set-rgb");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-icc-profile-set-rgb",
+                                     "Set the default RGB color profile on the image",
+                                     "This procedure sets the user-configured RGB profile on an image using 
the 'icc-profile' parasite. If no RGB profile is configured, sRGB is assumed and the parasite is unset. This 
procedure does not do any color conversion.",
+                                     "Sven Neumann <sven gimp org>",
+                                     "Sven Neumann",
+                                     "2015",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("run-mode",
+                                                  "run mode",
+                                                  "The run mode",
+                                                  GIMP_TYPE_RUN_MODE,
+                                                  GIMP_RUN_INTERACTIVE,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image_id ("image",
+                                                         "image",
+                                                         "Input image",
+                                                         pdb->gimp, FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-plug-in-illusion
    */
   procedure = gimp_procedure_new (plug_in_illusion_invoker);
diff --git a/plug-ins/common/lcms.c b/plug-ins/common/lcms.c
index 8ece2bb..3767946 100644
--- a/plug-ins/common/lcms.c
+++ b/plug-ins/common/lcms.c
@@ -31,17 +31,12 @@
 #define PLUG_IN_BINARY          "lcms"
 #define PLUG_IN_ROLE            "gimp-lcms"
 
-#define PLUG_IN_PROC_SET        "plug-in-icc-profile-set"
-#define PLUG_IN_PROC_SET_RGB    "plug-in-icc-profile-set-rgb"
-
 #define PLUG_IN_PROC_APPLY      "plug-in-icc-profile-apply"
 #define PLUG_IN_PROC_APPLY_RGB  "plug-in-icc-profile-apply-rgb"
 
 
 enum
 {
-  PROC_SET,
-  PROC_SET_RGB,
   PROC_APPLY,
   PROC_APPLY_RGB,
   NONE
@@ -67,9 +62,6 @@ static void  run   (const gchar      *name,
                     gint             *nreturn_vals,
                     GimpParam       **return_vals);
 
-static GimpPDBStatusType  lcms_icc_set       (GimpColorConfig   *config,
-                                              gint32             image,
-                                              GFile             *file);
 static GimpPDBStatusType  lcms_icc_apply     (GimpColorConfig   *config,
                                               GimpRunMode        run_mode,
                                               gint32             image,
@@ -78,9 +70,6 @@ static GimpPDBStatusType  lcms_icc_apply     (GimpColorConfig   *config,
                                               gboolean           bpc,
                                               gboolean          *dont_ask);
 
-static gboolean     lcms_image_set_profile   (gint32            image,
-                                              GFile            *file);
-
 static gboolean     lcms_icc_apply_dialog    (gint32            image,
                                               GimpColorProfile *src_profile,
                                               GimpColorProfile *dest_profile,
@@ -116,8 +105,6 @@ static const GimpParamDef apply_rgb_args[] =
 
 static const Procedure procedures[] =
 {
-  { PLUG_IN_PROC_SET,       2 },
-  { PLUG_IN_PROC_SET_RGB,   2 },
   { PLUG_IN_PROC_APPLY,     2 },
   { PLUG_IN_PROC_APPLY_RGB, 2 }
 };
@@ -135,36 +122,6 @@ MAIN ()
 static void
 query (void)
 {
-  gimp_install_procedure (PLUG_IN_PROC_SET,
-                          N_("Set a color profile on the image"),
-                          "This procedure sets an ICC color profile on an "
-                          "image using the 'icc-profile' parasite. It does "
-                          "not do any color conversion.",
-                          "Sven Neumann",
-                          "Sven Neumann",
-                          "2006, 2007",
-                          N_("_Assign Color Profile..."),
-                          "RGB*, INDEXED*",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (set_args), 0,
-                          set_args, NULL);
-
-  gimp_install_procedure (PLUG_IN_PROC_SET_RGB,
-                          "Set the default RGB color profile on the image",
-                          "This procedure sets the user-configured RGB "
-                          "profile on an image using the 'icc-profile' "
-                          "parasite. If no RGB profile is configured, sRGB "
-                          "is assumed and the parasite is unset. This "
-                          "procedure does not do any color conversion.",
-                          "Sven Neumann",
-                          "Sven Neumann",
-                          "2006, 2007",
-                          N_("Assign default RGB Profile"),
-                          "RGB*, INDEXED*",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (set_rgb_args), 0,
-                          set_rgb_args, NULL);
-
   gimp_install_procedure (PLUG_IN_PROC_APPLY,
                           _("Apply a color profile on the image"),
                           "This procedure transform from the image's color "
@@ -247,13 +204,6 @@ run (const gchar      *name,
 
   switch (proc)
     {
-    case PROC_SET:
-      run_mode = param[0].data.d_int32;
-      image    = param[1].data.d_image;
-      if (nparams > 2)
-        file = g_file_new_for_path (param[2].data.d_string);
-      break;
-
     case PROC_APPLY:
       run_mode = param[0].data.d_int32;
       image    = param[1].data.d_image;
@@ -265,11 +215,6 @@ run (const gchar      *name,
         bpc    = param[4].data.d_int32 ? TRUE : FALSE;
       break;
 
-    case PROC_SET_RGB:
-      run_mode = param[0].data.d_int32;
-      image    = param[1].data.d_image;
-      break;
-
     case PROC_APPLY_RGB:
       run_mode = param[0].data.d_int32;
       image    = param[1].data.d_image;
@@ -280,26 +225,8 @@ run (const gchar      *name,
       break;
     }
 
-  if (run_mode != GIMP_RUN_NONINTERACTIVE)
-    {
-      switch (proc)
-        {
-        case PROC_SET:
-        case PROC_APPLY:
-          goto done;
-
-        default:
-          break;
-        }
-    }
-
   switch (proc)
     {
-    case PROC_SET:
-    case PROC_SET_RGB:
-      status = lcms_icc_set (config, image, file);
-      break;
-
     case PROC_APPLY:
     case PROC_APPLY_RGB:
       status = lcms_icc_apply (config, run_mode,
@@ -327,29 +254,6 @@ run (const gchar      *name,
 }
 
 static GimpPDBStatusType
-lcms_icc_set (GimpColorConfig *config,
-              gint32           image,
-              GFile           *file)
-{
-  gboolean success;
-
-  g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), GIMP_PDB_CALLING_ERROR);
-  g_return_val_if_fail (image != -1, GIMP_PDB_CALLING_ERROR);
-
-  if (file)
-    g_object_ref (file);
-  else if (config->rgb_profile)
-    file = g_file_new_for_path (config->rgb_profile);
-
-  success = lcms_image_set_profile (image, file);
-
-  if (file)
-    g_object_unref (file);
-
-  return success ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR;
-}
-
-static GimpPDBStatusType
 lcms_icc_apply (GimpColorConfig          *config,
                 GimpRunMode               run_mode,
                 gint32                    image,
@@ -438,42 +342,6 @@ lcms_icc_apply (GimpColorConfig          *config,
   return status;
 }
 
-static gboolean
-lcms_image_set_profile (gint32  image,
-                        GFile  *file)
-{
-  GimpColorProfile *profile = NULL;
-
-  g_return_val_if_fail (image != -1, FALSE);
-
-  if (file)
-    {
-      GError *error = NULL;
-
-      profile = gimp_color_profile_new_from_file (file, &error);
-
-      if (! profile)
-        {
-          g_message ("%s", error->message);
-          g_clear_error (&error);
-
-          return FALSE;
-        }
-    }
-
-  gimp_image_undo_group_start (image);
-
-  gimp_image_set_color_profile (image, profile);
-  gimp_image_detach_parasite (image, "icc-profile-name");
-
-  gimp_image_undo_group_end (image);
-
-  if (profile)
-    g_object_unref (profile);
-
-  return TRUE;
-}
-
 static GtkWidget *
 lcms_icc_profile_src_label_new (gint32            image,
                                 GimpColorProfile *profile)
diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb
index fb41bc4..e64c5d3 100644
--- a/tools/pdbgen/pdb/plug_in_compat.pdb
+++ b/tools/pdbgen/pdb/plug_in_compat.pdb
@@ -1849,6 +1849,143 @@ CODE
     );
 }
 
+sub plug_in_icc_profile_set {
+    $blurb = "Set a color profile on the image";
+
+    $help = <<'HELP';
+This procedure sets the user-configured RGB profile on an image using
+the 'icc-profile' parasite. This procedure does not do any color
+conversion.
+HELP
+
+    &neo_pdb_misc;
+    $date = '2015';
+
+    @inargs = (
+       { name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
+         desc => 'The run mode' },
+        { name => 'image', type => 'image',
+          desc => 'Input image' },
+        { name => 'profile', type => 'string',
+          desc => 'Filename of an ICC color profile', allow_non_utf8 => 1 }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
+    {
+      GFile            *file = NULL;
+      GimpColorProfile *p    = NULL;
+
+      if (profile)
+        file = g_file_new_for_path (profile);
+      else if (image->gimp->config->color_management->rgb_profile)
+        file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
+
+      if (file)
+        {
+          p = gimp_color_profile_new_from_file (file, error);
+
+          if (! p)
+           success = FALSE;
+
+          g_object_unref (file);
+       }
+
+      if (success)
+        {
+          gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_MISC,
+                                       _("Set color profile"));
+
+          if (gimp_image_set_color_profile (image, p, error))
+            gimp_image_parasite_detach (image, "icc-profile-name");
+          else
+            success = FALSE;
+
+          gimp_image_undo_group_end (image);
+
+          if (! success)
+           gimp_image_undo (image);
+
+          if (p)
+            g_object_unref (p);
+       }
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
+sub plug_in_icc_profile_set_rgb {
+    $blurb = "Set the default RGB color profile on the image";
+
+    $help = <<'HELP';
+This procedure sets the user-configured RGB profile on an image using
+the 'icc-profile' parasite. If no RGB profile is configured, sRGB is
+assumed and the parasite is unset. This procedure does not do any
+color conversion.
+HELP
+
+    &neo_pdb_misc;
+    $date = '2015';
+
+    @inargs = (
+       { name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
+         desc => 'The run mode' },
+        { name => 'image', type => 'image',
+          desc => 'Input image' }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
+    {
+      GFile            *file = NULL;
+      GimpColorProfile *p    = NULL;
+
+      if (image->gimp->config->color_management->rgb_profile)
+        file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
+
+      if (file)
+        {
+          p = gimp_color_profile_new_from_file (file, error);
+
+          if (! p)
+           success = FALSE;
+
+          g_object_unref (file);
+       }
+
+      if (success)
+        {
+          gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_MISC,
+                                       _("Set color profile"));
+
+          if (gimp_image_set_color_profile (image, p, error))
+            gimp_image_parasite_detach (image, "icc-profile-name");
+          else
+            success = FALSE;
+
+          gimp_image_undo_group_end (image);
+
+          if (! success)
+           gimp_image_undo (image);
+
+          if (p)
+            g_object_unref (p);
+       }
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub plug_in_illusion {
     $blurb = 'Superimpose many altered copies of the image';
 
@@ -4456,12 +4593,16 @@ gaussian_blur (GimpDrawable  *drawable,
 CODE
 
 @headers = qw("libgimpbase/gimpbase.h"
+              "libgimpconfig/gimpconfig.h"
               "libgimpmath/gimpmath.h"
               "gegl/gimp-babl.h"
               "gegl/gimp-gegl-utils.h"
+              "config/gimpcoreconfig.h"
+              "core/gimp.h"
               "core/gimpchannel.h"
               "core/gimpcontext.h"
               "core/gimpdrawable-operation.h"
+              "core/gimpimage-color-profile.h"
               "core/gimpimage-crop.h"
               "core/gimpimage-resize.h"
               "core/gimpimage-rotate.h"
@@ -4503,6 +4644,8 @@ CODE
             plug_in_hsv_noise
             plug_in_icc_profile_info
             plug_in_icc_profile_file_info
+            plug_in_icc_profile_set
+            plug_in_icc_profile_set_rgb
             plug_in_illusion
             plug_in_laplace
             plug_in_lens_distortion



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