[gimp] plug-ins: port guillotine.



commit 2524e9685ebbcf204589e6ae0990680f2f5160d8
Author: Jehan <jehan girinstud io>
Date:   Fri Aug 30 00:41:34 2019 +0200

    plug-ins: port guillotine.
    
    Maybe should we have IMAGE_ARRAY types as we still have to pass image
    IDs when we pass more than one image between core and plug-in. And even
    maybe have alternate LIST types to ARRAY ones, so that we can pass GList
    through rather than one array parameter + one length parameter.
    
    Anyway this port still return just old style array of image IDs + array
    length as int32.

 plug-ins/common/Makefile.am    |   2 -
 plug-ins/common/guillotine.c   | 207 ++++++++++++++++++++++++-----------------
 plug-ins/common/plugin-defs.pl |   2 +-
 3 files changed, 122 insertions(+), 89 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 42a86ec66c..845d2bcf3d 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -1247,8 +1247,6 @@ grid_LDADD = \
        $(INTLLIBS)             \
        $(grid_RC)
 
-guillotine_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 guillotine_SOURCES = \
        guillotine.c
 
diff --git a/plug-ins/common/guillotine.c b/plug-ins/common/guillotine.c
index fd12599fdb..c3505d4cd7 100644
--- a/plug-ins/common/guillotine.c
+++ b/plug-ins/common/guillotine.c
@@ -31,111 +31,146 @@
 #define PLUG_IN_PROC "plug-in-guillotine"
 
 
-/* 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 GList * guillotine (gint32            image_ID,
-                           gboolean          interactive);
+typedef struct _Guillotine      Guillotine;
+typedef struct _GuillotineClass GuillotineClass;
 
+struct _Guillotine
+{
+  GimpPlugIn      parent_instance;
+};
 
-const GimpPlugInInfo PLUG_IN_INFO =
+struct _GuillotineClass
 {
-  NULL,  /* init_proc  */
-  NULL,  /* quit_proc  */
-  query, /* query_proc */
-  run,   /* run_proc   */
+  GimpPlugInClass parent_class;
 };
 
 
-MAIN ()
+#define GUILLOTINE_TYPE  (guillotine_get_type ())
+#define GUILLOTINE (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GUILLOTINE_TYPE, Guillotine))
+
+GType                   guillotine_get_type         (void) G_GNUC_CONST;
+
+static GList          * guillotine_query_procedures (GimpPlugIn           *plug_in);
+static GimpProcedure  * guillotine_create_procedure (GimpPlugIn           *plug_in,
+                                                     const gchar          *name);
+
+static GimpValueArray * guillotine_run              (GimpProcedure        *procedure,
+                                                     GimpRunMode           run_mode,
+                                                     GimpImage            *image,
+                                                     GimpDrawable         *drawable,
+                                                     const GimpValueArray *args,
+                                                     gpointer              run_data);
+static GList          * guillotine                  (GimpImage            *image,
+                                                     gboolean              interactive);
+
+
+G_DEFINE_TYPE (Guillotine, guillotine, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (GUILLOTINE_TYPE)
 
 static void
-query (void)
+guillotine_class_init (GuillotineClass *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 (unused)" }
-  };
-  static const GimpParamDef return_vals[] =
-  {
-    { GIMP_PDB_INT32,      "image-count", "Number of images created" },
-    { GIMP_PDB_INT32ARRAY, "image-ids",   "Output images"            }
-  };
-
-  gimp_install_procedure (PLUG_IN_PROC,
-                          N_("Slice the image into subimages using guides"),
-                          "This function takes an image and slices it along "
-                          "its guides, creating new images. The original "
-                          "image is not modified.",
-                          "Adam D. Moss (adam foxbox org)",
-                          "Adam D. Moss (adam foxbox org)",
-                          "1998",
-                          N_("Slice Using G_uides"),
-                          "RGB*, INDEXED*, GRAY*",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (args), G_N_ELEMENTS (return_vals),
-                          args, return_vals);
-
-  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Image/Crop");
+  GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+
+  plug_in_class->query_procedures = guillotine_query_procedures;
+  plug_in_class->create_procedure = guillotine_create_procedure;
 }
 
 static void
-run (const gchar      *name,
-     gint              nparams,
-     const GimpParam  *param,
-     gint             *nreturn_vals,
-     GimpParam       **return_vals)
+guillotine_init (Guillotine *film)
+{
+}
+
+static GList *
+guillotine_query_procedures (GimpPlugIn *plug_in)
 {
-  static GimpParam  values[3];
-  GimpRunMode       run_mode = param[0].data.d_int32;
-  GimpPDBStatusType status   = GIMP_PDB_SUCCESS;
+  return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
+}
 
-  *nreturn_vals = 3;
-  *return_vals  = values;
+static GimpProcedure *
+guillotine_create_procedure (GimpPlugIn  *plug_in,
+                             const gchar *name)
+{
+  GimpProcedure *procedure = NULL;
 
-  values[0].type              = GIMP_PDB_STATUS;
-  values[0].data.d_status     = status;
-  values[1].type              = GIMP_PDB_INT32;
-  values[1].data.d_int32      = 0;
-  values[2].type              = GIMP_PDB_INT32ARRAY;
-  values[2].data.d_int32array = NULL;
+  if (! strcmp (name, PLUG_IN_PROC))
+    {
+      procedure = gimp_image_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                            guillotine_run, NULL, NULL);
+
+      gimp_procedure_set_image_types (procedure, "*");
+
+      gimp_procedure_set_menu_label (procedure, N_("Slice Using G_uides"));
+      gimp_procedure_add_menu_path (procedure, "<Image>/Image/Crop");
+
+      gimp_procedure_set_documentation (procedure,
+                                        N_("Slice the image into subimages using guides"),
+                                        "This function takes an image and slices it along "
+                                        "its guides, creating new images. The original "
+                                        "image is not modified.",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "Adam D. Moss (adam foxbox org)",
+                                      "Adam D. Moss (adam foxbox org)",
+                                      "1998");
+
+      GIMP_PROC_VAL_INT (procedure, "image-count",
+                         "Number of images created",
+                         "Number of images created",
+                         0, G_MAXINT, 0,
+                         G_PARAM_READWRITE);
+
+      GIMP_PROC_VAL_INT32_ARRAY (procedure, "image-ids",
+                                 "Output images IDs",
+                                 "Output images IDs",
+                                 G_PARAM_READWRITE);
+    }
+
+  return procedure;
+}
+
+static GimpValueArray *
+guillotine_run (GimpProcedure        *procedure,
+                GimpRunMode           run_mode,
+                GimpImage            *image,
+                GimpDrawable         *drawable,
+                const GimpValueArray *args,
+                gpointer              run_data)
+{
+  GimpValueArray    *return_vals = NULL;
+  GimpPDBStatusType  status      = GIMP_PDB_SUCCESS;
 
   INIT_I18N();
 
+  return_vals = gimp_procedure_new_return_values (procedure, status,
+                                                  NULL);
   if (status == GIMP_PDB_SUCCESS)
     {
-      GList *images;
-      GList *list;
+      GList  *images;
+      GList  *list;
+      gint32 *ids;
       gint   i;
 
       gimp_progress_init (_("Guillotine"));
 
-      images = guillotine (param[1].data.d_image,
-                           run_mode == GIMP_RUN_INTERACTIVE);
-
-      values[1].data.d_int32      = g_list_length (images);
-      values[2].data.d_int32array = g_new (gint32, values[1].data.d_int32);
+      images = guillotine (image, run_mode == GIMP_RUN_INTERACTIVE);
+      ids = g_new (gint32, g_list_length (images));
 
       for (list = images, i = 0; list; list = g_list_next (list), i++)
         {
-          values[2].data.d_int32array[i] = GPOINTER_TO_INT (list->data);
+          ids[i] = gimp_image_get_id (list->data);
         }
-
       g_list_free (images);
 
+      GIMP_VALUES_SET_INT (return_vals, 1, g_list_length (images));
+      GIMP_VALUES_TAKE_INT32_ARRAY (return_vals, 2, ids, g_list_length (images));
+
       if (run_mode == GIMP_RUN_INTERACTIVE)
         gimp_displays_flush ();
     }
 
-  values[0].data.d_status = status;
+  return return_vals;
 }
 
 
@@ -147,8 +182,8 @@ guide_sort_func (gconstpointer a,
 }
 
 static GList *
-guillotine (gint32   image_ID,
-            gboolean interactive)
+guillotine (GimpImage *image,
+            gboolean   interactive)
 {
   GList    *images = NULL;
   gint      guide;
@@ -158,8 +193,8 @@ guillotine (gint32   image_ID,
   GList    *hguides, *hg;
   GList    *vguides, *vg;
 
-  image_width  = gimp_image_width (image_ID);
-  image_height = gimp_image_height (image_ID);
+  image_width  = gimp_image_width (image);
+  image_height = gimp_image_height (image);
 
   hguides = g_list_append (NULL,    GINT_TO_POINTER (0));
   hguides = g_list_append (hguides, GINT_TO_POINTER (image_height));
@@ -167,13 +202,13 @@ guillotine (gint32   image_ID,
   vguides = g_list_append (NULL,    GINT_TO_POINTER (0));
   vguides = g_list_append (vguides, GINT_TO_POINTER (image_width));
 
-  for (guide = gimp_image_find_next_guide (image_ID, 0);
+  for (guide = gimp_image_find_next_guide (image, 0);
        guide > 0;
-       guide = gimp_image_find_next_guide (image_ID, guide))
+       guide = gimp_image_find_next_guide (image, guide))
     {
-      gint position = gimp_image_get_guide_position (image_ID, guide);
+      gint position = gimp_image_get_guide_position (image, guide);
 
-      switch (gimp_image_get_guide_orientation (image_ID, guide))
+      switch (gimp_image_get_guide_orientation (image, guide))
         {
         case GIMP_ORIENTATION_HORIZONTAL:
           if (! g_list_find (hguides, GINT_TO_POINTER (position)))
@@ -209,7 +244,7 @@ guillotine (gint32   image_ID,
       gchar *hformat;
       gchar *format;
 
-      filename = gimp_image_get_filename (image_ID);
+      filename = gimp_image_get_filename (image);
 
       if (! filename)
         filename = g_strdup (_("Untitled"));
@@ -233,13 +268,13 @@ guillotine (gint32   image_ID,
         {
           for (x = 0, vg = vguides; vg && vg->next; x++, vg = vg->next)
             {
-              gint32   new_image = gimp_image_duplicate (image_ID);
-              GString *new_filename;
-              gchar   *fileextension;
-              gchar   *fileindex;
-              gint     pos;
+              GimpImage *new_image = gimp_image_duplicate (image);
+              GString   *new_filename;
+              gchar     *fileextension;
+              gchar     *fileindex;
+              gint       pos;
 
-              if (new_image == -1)
+              if (! new_image)
                 {
                   g_warning ("Couldn't create new image.");
                   g_free (hformat);
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index be31ddaf2f..51487ae5ed 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -54,7 +54,7 @@
     'film' => { ui => 1, gegl => 1 },
     'gradient-map' => { gegl => 1, old_api => 1 },
     'grid' => { ui => 1, gegl => 1 },
-    'guillotine' => { old_api => 1 },
+    'guillotine' => { },
     'hot' => { ui => 1, gegl => 1, old_api => 1 },
     'jigsaw' => { ui => 1, gegl => 1 },
     'mail' => { ui => 1, optional => 1 },


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