[gimp] Remove plug-in crop-auto and add compat PDB wrappers to replace it



commit 6452a9512508c41df99201c5240080ab3d98b47a
Author: Michael Natterer <mitch gimp org>
Date:   Sat Sep 22 20:57:53 2012 +0200

    Remove plug-in crop-auto and add compat PDB wrappers to replace it

 app/pdb/internal-procs.c            |    2 +-
 app/pdb/plug-in-compat-cmds.c       |  174 ++++++++++++++
 plug-ins/common/.gitignore          |    2 -
 plug-ins/common/Makefile.am         |   16 --
 plug-ins/common/crop-auto.c         |  440 -----------------------------------
 plug-ins/common/gimprc.common       |    1 -
 plug-ins/common/plugin-defs.pl      |    1 -
 po-plug-ins/POTFILES.in             |    1 -
 tools/pdbgen/pdb/plug_in_compat.pdb |  113 +++++++++-
 9 files changed, 287 insertions(+), 463 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index af8522a..2d937eb 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 676 procedures registered total */
+/* 678 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 1388aea..a766a4f 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -35,7 +35,12 @@
 #include "core/gimpcontext.h"
 #include "core/gimpdrawable-operation.h"
 #include "core/gimpdrawable.h"
+#include "core/gimpimage-crop.h"
+#include "core/gimpimage-undo.h"
+#include "core/gimpimage.h"
 #include "core/gimpparamspecs.h"
+#include "core/gimppickable-auto-shrink.h"
+#include "core/gimppickable.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimppdb.h"
@@ -47,6 +52,103 @@
 
 
 static GimpValueArray *
+plug_in_autocrop_invoker (GimpProcedure         *procedure,
+                          Gimp                  *gimp,
+                          GimpContext           *context,
+                          GimpProgress          *progress,
+                          const GimpValueArray  *args,
+                          GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  GimpDrawable *drawable;
+
+  image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp);
+  drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
+
+  if (success)
+    {
+      if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error))
+        {
+          gint x1, y1, x2, y2;
+
+          if (gimp_pickable_auto_shrink (GIMP_PICKABLE (drawable),
+                                         0, 0,
+                                         gimp_item_get_width  (GIMP_ITEM (drawable)),
+                                         gimp_item_get_height (GIMP_ITEM (drawable)),
+                                         &x1, &y1, &x2, &y2))
+            {
+              gint off_x, off_y;
+
+              gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
+              x1 += off_x; x2 += off_x;
+              y1 += off_y; y2 += off_y;
+
+              gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE,
+                                           _("Autocrop image"));
+
+              gimp_image_crop (image, context,
+                               x2 - x1, y2 - y1, -x1, -y1, TRUE);
+
+              gimp_image_undo_group_end (image);
+            }
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
+plug_in_autocrop_layer_invoker (GimpProcedure         *procedure,
+                                Gimp                  *gimp,
+                                GimpContext           *context,
+                                GimpProgress          *progress,
+                                const GimpValueArray  *args,
+                                GError               **error)
+{
+  gboolean success = TRUE;
+  GimpImage *image;
+  GimpDrawable *drawable;
+
+  image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp);
+  drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
+
+  if (success)
+    {
+      if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error))
+        {
+          GimpLayer *layer = gimp_image_get_active_layer (image);
+          gint       x1, y1, x2, y2;
+
+          if (layer &&
+              gimp_pickable_auto_shrink (GIMP_PICKABLE (drawable),
+                                         0, 0,
+                                         gimp_item_get_width  (GIMP_ITEM (drawable)),
+                                         gimp_item_get_height (GIMP_ITEM (drawable)),
+                                         &x1, &y1, &x2, &y2))
+            {
+              gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE,
+                                           _("Autocrop layer"));
+
+              gimp_item_resize (GIMP_ITEM (layer), context,
+                                x2 - x1, y2 - y1, -x1, -y1);
+
+              gimp_image_undo_group_end (image);
+            }
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 plug_in_colortoalpha_invoker (GimpProcedure         *procedure,
                               Gimp                  *gimp,
                               GimpContext           *context,
@@ -354,6 +456,78 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   GimpProcedure *procedure;
 
   /*
+   * gimp-plug-in-autocrop
+   */
+  procedure = gimp_procedure_new (plug_in_autocrop_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-autocrop");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-autocrop",
+                                     "Remove empty borders from the image",
+                                     "Remove empty borders from the image.",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "1997",
+                                     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_drawable_id ("drawable",
+                                                            "drawable",
+                                                            "Input drawable",
+                                                            pdb->gimp, FALSE,
+                                                            GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-plug-in-autocrop-layer
+   */
+  procedure = gimp_procedure_new (plug_in_autocrop_layer_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-autocrop-layer");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-autocrop-layer",
+                                     "Remove empty borders from the layer",
+                                     "Remove empty borders from the layer.",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "1997",
+                                     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_drawable_id ("drawable",
+                                                            "drawable",
+                                                            "Input drawable",
+                                                            pdb->gimp, FALSE,
+                                                            GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-plug-in-colortoalpha
    */
   procedure = gimp_procedure_new (plug_in_colortoalpha_invoker);
diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore
index 04df9c1..899d516 100644
--- a/plug-ins/common/.gitignore
+++ b/plug-ins/common/.gitignore
@@ -58,8 +58,6 @@
 /contrast-stretch-hsv.exe
 /convolution-matrix
 /convolution-matrix.exe
-/crop-auto
-/crop-auto.exe
 /crop-zealous
 /crop-zealous.exe
 /cubism
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 4fed296..56dc3ec 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -72,7 +72,6 @@ libexec_PROGRAMS = \
 	contrast-stretch \
 	contrast-stretch-hsv \
 	convolution-matrix \
-	crop-auto \
 	crop-zealous \
 	cubism \
 	curve-bend \
@@ -685,21 +684,6 @@ convolution_matrix_LDADD = \
 	$(INTLLIBS)		\
 	$(convolution_matrix_RC)
 
-crop_auto_SOURCES = \
-	crop-auto.c
-
-crop_auto_LDADD = \
-	$(libgimp)		\
-	$(libgimpmath)		\
-	$(libgimpconfig)	\
-	$(libgimpcolor)		\
-	$(libgimpbase)		\
-	$(CAIRO_LIBS)		\
-	$(GDK_PIXBUF_LIBS)	\
-	$(RT_LIBS)		\
-	$(INTLLIBS)		\
-	$(crop_auto_RC)
-
 crop_zealous_SOURCES = \
 	crop-zealous.c
 
diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common
index edfc2c9..d837475 100644
--- a/plug-ins/common/gimprc.common
+++ b/plug-ins/common/gimprc.common
@@ -26,7 +26,6 @@ contrast_retinex_RC = contrast-retinex.rc.o
 contrast_stretch_RC = contrast-stretch.rc.o
 contrast_stretch_hsv_RC = contrast-stretch-hsv.rc.o
 convolution_matrix_RC = convolution-matrix.rc.o
-crop_auto_RC = crop-auto.rc.o
 crop_zealous_RC = crop-zealous.rc.o
 cubism_RC = cubism.rc.o
 curve_bend_RC = curve-bend.rc.o
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 7ef6f19..9dc4104 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -27,7 +27,6 @@
     'contrast-stretch' => {},
     'contrast-stretch-hsv' => {},
     'convolution-matrix' => { ui => 1 },
-    'crop-auto' => {},
     'crop-zealous' => {},
     'cubism' => { ui => 1 },
     'curve-bend' => { ui => 1 },
diff --git a/po-plug-ins/POTFILES.in b/po-plug-ins/POTFILES.in
index f9f1a07..90f72c0 100644
--- a/po-plug-ins/POTFILES.in
+++ b/po-plug-ins/POTFILES.in
@@ -34,7 +34,6 @@ plug-ins/common/contrast-retinex.c
 plug-ins/common/contrast-stretch.c
 plug-ins/common/contrast-stretch-hsv.c
 plug-ins/common/convolution-matrix.c
-plug-ins/common/crop-auto.c
 plug-ins/common/crop-zealous.c
 plug-ins/common/cubism.c
 plug-ins/common/curve-bend.c
diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb
index 7a119bf..e3e23ed 100644
--- a/tools/pdbgen/pdb/plug_in_compat.pdb
+++ b/tools/pdbgen/pdb/plug_in_compat.pdb
@@ -16,6 +16,111 @@
 
 # "Perlized" from C source by Manish Singh <yosh gimp org>
 
+sub plug_in_autocrop {
+    $blurb = 'Remove empty borders from the image';
+
+    $help = <<'HELP';
+Remove empty borders from the image.
+HELP
+
+    &std_pdb_misc;
+    $date = '1997';
+
+    @inargs = (
+	{ name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
+	  desc => 'The run mode' },
+	{ name => 'image', type => 'image',
+	  desc => 'Input image)' },
+	{ name => 'drawable', type => 'drawable',
+	  desc => 'Input drawable' }
+    );
+
+    %invoke = (
+	code => <<'CODE'
+{
+  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error))
+    {
+      gint x1, y1, x2, y2;
+
+      if (gimp_pickable_auto_shrink (GIMP_PICKABLE (drawable),
+                                     0, 0,
+                                     gimp_item_get_width  (GIMP_ITEM (drawable)),
+                                     gimp_item_get_height (GIMP_ITEM (drawable)),
+                                     &x1, &y1, &x2, &y2))
+        {
+          gint off_x, off_y;
+
+          gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
+          x1 += off_x; x2 += off_x;
+          y1 += off_y; y2 += off_y;
+
+          gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE,
+                                       _("Autocrop image"));
+
+          gimp_image_crop (image, context,
+                           x2 - x1, y2 - y1, -x1, -y1, TRUE);
+
+          gimp_image_undo_group_end (image);
+        }
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
+sub plug_in_autocrop_layer {
+    $blurb = 'Remove empty borders from the layer';
+
+    $help = <<'HELP';
+Remove empty borders from the layer.
+HELP
+
+    &std_pdb_misc;
+    $date = '1997';
+
+    @inargs = (
+	{ name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
+	  desc => 'The run mode' },
+	{ name => 'image', type => 'image',
+	  desc => 'Input image)' },
+	{ name => 'drawable', type => 'drawable',
+	  desc => 'Input drawable' }
+    );
+
+    %invoke = (
+	code => <<'CODE'
+{
+  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error))
+    {
+      GimpLayer *layer = gimp_image_get_active_layer (image);
+      gint       x1, y1, x2, y2;
+
+      if (layer &&
+          gimp_pickable_auto_shrink (GIMP_PICKABLE (drawable),
+                                     0, 0,
+                                     gimp_item_get_width  (GIMP_ITEM (drawable)),
+                                     gimp_item_get_height (GIMP_ITEM (drawable)),
+                                     &x1, &y1, &x2, &y2))
+        {
+          gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE,
+                                       _("Autocrop layer"));
+
+          gimp_item_resize (GIMP_ITEM (layer), context,
+                            x2 - x1, y2 - y1, -x1, -y1);
+
+          gimp_image_undo_group_end (image);
+        }
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub plug_in_colortoalpha {
     $blurb = 'Convert a specified color to transparency';
 
@@ -375,10 +480,16 @@ CODE
               "core/gimpcontext.h"
               "core/gimpdrawable.h"
               "core/gimpdrawable-operation.h"
+              "core/gimpimage-crop.h"
+              "core/gimpimage-undo.h"
+              "core/gimppickable.h"
+              "core/gimppickable-auto-shrink.h"
               "gimppdb-utils.h"
               "gimp-intl.h");
 
- procs = qw(plug_in_colortoalpha
+ procs = qw(plug_in_autocrop
+            plug_in_autocrop_layer
+            plug_in_colortoalpha
             plug_in_pixelize
             plug_in_pixelize2
             plug_in_polar_coords



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