[gimp] plug-ins: port crop-zealous to GimpPlugIn



commit dcc89fb61118281b660b17f3c8a8bee5dfe1c1dd
Author: Michael Natterer <mitch gimp org>
Date:   Sat Aug 31 12:23:34 2019 +0200

    plug-ins: port crop-zealous to GimpPlugIn

 plug-ins/common/animation-play.c |   4 -
 plug-ins/common/crop-zealous.c   | 176 ++++++++++++++++++++-------------------
 2 files changed, 90 insertions(+), 90 deletions(-)
---
diff --git a/plug-ins/common/animation-play.c b/plug-ins/common/animation-play.c
index d217e9c7bf..48b83cee10 100644
--- a/plug-ins/common/animation-play.c
+++ b/plug-ins/common/animation-play.c
@@ -81,10 +81,6 @@ struct _PlayClass
   GimpPlugInClass parent_class;
 };
 
-
-/* Declare local functions.
- */
-
 #define PLAY_TYPE  (play_get_type ())
 #define PLAY (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLAY_TYPE, Play))
 
diff --git a/plug-ins/common/crop-zealous.c b/plug-ins/common/crop-zealous.c
index 6b8cbcb93c..e244d2c777 100644
--- a/plug-ins/common/crop-zealous.c
+++ b/plug-ins/common/crop-zealous.c
@@ -22,122 +22,126 @@
 
 #include "libgimp/stdplugins-intl.h"
 
+
 #define PLUG_IN_PROC "plug-in-zealouscrop"
 
 #define EPSILON (1e-5)
 #define FLOAT_IS_ZERO(value) (value > -EPSILON && value < EPSILON)
 #define FLOAT_EQUAL(v1, v2)  ((v1 - v2) > -EPSILON && (v1 - v2) < EPSILON)
 
-/* Declare local functions. */
-
-static void            query        (void);
-static void            run          (const gchar      *name,
-                                     gint              nparams,
-                                     const GimpParam  *param,
-                                     gint             *nreturn_vals,
-                                     GimpParam       **return_vals);
 
-static inline gboolean colors_equal (const gfloat     *col1,
-                                     const gfloat     *col2,
-                                     gint              components,
-                                     gboolean          has_alpha);
-static void            do_zcrop     (GimpDrawable     *drawable,
-                                     GimpImage        *image);
+typedef struct _Crop      Crop;
+typedef struct _CropClass CropClass;
 
+struct _Crop
+{
+  GimpPlugIn      parent_instance;
+};
 
-const GimpPlugInInfo PLUG_IN_INFO =
+struct _CropClass
 {
-  NULL,  /* init_proc  */
-  NULL,  /* quit_proc  */
-  query, /* query_proc */
-  run,   /* run_proc   */
+  GimpPlugInClass parent_class;
 };
 
+#define CROP_TYPE  (crop_get_type ())
+#define CROP (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CROP_TYPE, Crop))
+
+GType                   crop_get_type         (void) G_GNUC_CONST;
+
+static GList          * crop_query_procedures (GimpPlugIn           *plug_in);
+static GimpProcedure  * crop_create_procedure (GimpPlugIn           *plug_in,
+                                               const gchar          *name);
+
+static GimpValueArray * crop_run              (GimpProcedure        *procedure,
+                                               GimpRunMode           run_mode,
+                                               GimpImage            *image,
+                                               GimpDrawable         *drawable,
+                                               const GimpValueArray *args,
+                                               gpointer              run_data);
+
+static inline gboolean  colors_equal          (const gfloat         *col1,
+                                               const gfloat         *col2,
+                                               gint                  components,
+                                               gboolean              has_alpha);
+static void             do_zcrop              (GimpDrawable         *drawable,
+                                               GimpImage            *image);
+
+
+G_DEFINE_TYPE (Crop, crop, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (CROP_TYPE)
 
-MAIN ()
 
 static void
-query (void)
+crop_class_init (CropClass *klass)
 {
-  static const GimpParamDef args[] =
-  {
-    { GIMP_PDB_INT32,    "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
-    { GIMP_PDB_IMAGE,    "image",    "Input image"    },
-    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
-  };
-
-  gimp_install_procedure (PLUG_IN_PROC,
-                          N_("Autocrop unused space from edges and middle"),
-                          "",
-                          "Adam D. Moss",
-                          "Adam D. Moss",
-                          "1997",
-                          N_("_Zealous Crop"),
-                          "RGB*, GRAY*, INDEXED*",
-                          GIMP_PDB_PROC_TYPE_PLUGIN,
-                          G_N_ELEMENTS (args), 0,
-                          args, NULL);
-
-  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Image/Crop");
+  GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+
+  plug_in_class->query_procedures = crop_query_procedures;
+  plug_in_class->create_procedure = crop_create_procedure;
 }
 
 static void
-run (const gchar      *name,
-     gint              n_params,
-     const GimpParam  *param,
-     gint             *nreturn_vals,
-     GimpParam       **return_vals)
+crop_init (Crop *crop)
 {
-  static GimpParam   values[1];
-  GimpRunMode        run_mode;
-  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
-  GimpDrawable      *drawable;
-  GimpImage         *image;
-
-  INIT_I18N ();
-  gegl_init (NULL, NULL);
+}
 
-  *nreturn_vals = 1;
-  *return_vals  = values;
+static GList *
+crop_query_procedures (GimpPlugIn *plug_in)
+{
+  return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
+}
 
-  run_mode = param[0].data.d_int32;
+static GimpProcedure *
+crop_create_procedure (GimpPlugIn  *plug_in,
+                       const gchar *name)
+{
+  GimpProcedure *procedure = NULL;
 
-  if (run_mode == GIMP_RUN_NONINTERACTIVE)
+  if (! strcmp (name, PLUG_IN_PROC))
     {
-      if (n_params != 3)
-        {
-          status = GIMP_PDB_CALLING_ERROR;
-        }
+      procedure = gimp_image_procedure_new (plug_in, name,
+                                            GIMP_PDB_PROC_TYPE_PLUGIN,
+                                            crop_run, NULL, NULL);
+
+      gimp_procedure_set_image_types (procedure, "*");
+
+      gimp_procedure_set_menu_label (procedure, N_("_Zealous Crop"));
+      gimp_procedure_add_menu_path (procedure, "<Image>/Image/Crop");
+
+      gimp_procedure_set_documentation (procedure,
+                                        N_("Autocrop unused space from "
+                                           "edges and middle"),
+                                        NULL,
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "Adam D. Moss",
+                                      "Adam D. Moss",
+                                      "1997");
     }
 
-  if (status == GIMP_PDB_SUCCESS)
-    {
-      /*  Get the specified drawable  */
-      image    = gimp_image_get_by_id (param[1].data.d_int32);
-      drawable = GIMP_DRAWABLE (gimp_item_get_by_id (param[2].data.d_int32));
-
-      /*  Make sure that the drawable is gray or RGB or indexed  */
-      if (gimp_drawable_is_rgb (drawable) ||
-          gimp_drawable_is_gray (drawable) ||
-          gimp_drawable_is_indexed (drawable))
-        {
-          gimp_progress_init (_("Zealous cropping"));
+  return procedure;
+}
 
-          do_zcrop (drawable, image);
+static GimpValueArray *
+crop_run (GimpProcedure        *procedure,
+          GimpRunMode           run_mode,
+          GimpImage            *image,
+          GimpDrawable         *drawable,
+          const GimpValueArray *args,
+          gpointer              run_data)
+{
+  INIT_I18N ();
+  gegl_init (NULL, NULL);
 
-          if (run_mode != GIMP_RUN_NONINTERACTIVE)
-            gimp_displays_flush ();
-        }
-      else
-        {
-          status = GIMP_PDB_EXECUTION_ERROR;
-        }
-    }
+  gimp_progress_init (_("Zealous cropping"));
+
+  do_zcrop (drawable, image);
 
-  values[0].type          = GIMP_PDB_STATUS;
-  values[0].data.d_status = status;
+  if (run_mode != GIMP_RUN_NONINTERACTIVE)
+    gimp_displays_flush ();
 
-  gegl_exit ();
+  return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
 }
 
 static inline gboolean


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