[gimp/wip/Jehan/classy-GIMP: 28/64] plug-ins: ported a few plug-ins to new GimpImage/GimpDrawable classes.



commit 1cc65187497007631fda556ae86627e9e6f96bbe
Author: Jehan <jehan girinstud io>
Date:   Tue Aug 13 17:31:13 2019 +0200

    plug-ins: ported a few plug-ins to new GimpImage/GimpDrawable classes.

 plug-ins/common/Makefile.am        | 18 ----------
 plug-ins/common/blinds.c           | 53 ++++++++++++++-------------
 plug-ins/common/checkerboard.c     | 70 ++++++++++++++++++++----------------
 plug-ins/common/contrast-retinex.c | 49 ++++++++++++++-----------
 plug-ins/common/despeckle.c        | 46 +++++++++++++-----------
 plug-ins/common/destripe.c         | 51 ++++++++++++++------------
 plug-ins/common/grid.c             | 66 ++++++++++++++++++----------------
 plug-ins/common/jigsaw.c           | 48 +++++++++++++------------
 plug-ins/common/nl-filter.c        | 44 +++++++++++++----------
 plug-ins/common/plugin-defs.pl     | 18 +++++-----
 plug-ins/common/sparkle.c          | 73 +++++++++++++++++++++-----------------
 11 files changed, 288 insertions(+), 248 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index b638337bea..6e0ba7c55b 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -282,8 +282,6 @@ animation_play_LDADD = \
        $(INTLLIBS)             \
        $(animation_play_RC)
 
-blinds_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 blinds_SOURCES = \
        blinds.c
 
@@ -342,8 +340,6 @@ busy_dialog_LDADD = \
        $(INTLLIBS)             \
        $(busy_dialog_RC)
 
-checkerboard_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 checkerboard_SOURCES = \
        checkerboard.c
 
@@ -422,8 +418,6 @@ compose_LDADD = \
        $(INTLLIBS)             \
        $(compose_RC)
 
-contrast_retinex_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 contrast_retinex_SOURCES = \
        contrast-retinex.c
 
@@ -520,8 +514,6 @@ depth_merge_LDADD = \
        $(INTLLIBS)             \
        $(depth_merge_RC)
 
-despeckle_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 despeckle_SOURCES = \
        despeckle.c
 
@@ -540,8 +532,6 @@ despeckle_LDADD = \
        $(INTLLIBS)             \
        $(despeckle_RC)
 
-destripe_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 destripe_SOURCES = \
        destripe.c
 
@@ -1322,8 +1312,6 @@ gradient_map_LDADD = \
        $(INTLLIBS)             \
        $(gradient_map_RC)
 
-grid_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 grid_SOURCES = \
        grid.c
 
@@ -1379,8 +1367,6 @@ hot_LDADD = \
        $(INTLLIBS)             \
        $(hot_RC)
 
-jigsaw_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 jigsaw_SOURCES = \
        jigsaw.c
 
@@ -1418,8 +1404,6 @@ mail_LDADD = \
        $(INTLLIBS)             \
        $(mail_RC)
 
-nl_filter_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 nl_filter_SOURCES = \
        nl-filter.c
 
@@ -1536,8 +1520,6 @@ smooth_palette_LDADD = \
        $(INTLLIBS)             \
        $(smooth_palette_RC)
 
-sparkle_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 sparkle_SOURCES = \
        sparkle.c
 
diff --git a/plug-ins/common/blinds.c b/plug-ins/common/blinds.c
index df96ce378b..7ac7c41b75 100644
--- a/plug-ins/common/blinds.c
+++ b/plug-ins/common/blinds.c
@@ -65,11 +65,11 @@ static void      run    (const gchar      *name,
                          gint             *nreturn_vals,
                          GimpParam       **return_vals);
 
-static gboolean  blinds_dialog         (gint32         drawable_id);
+static gboolean  blinds_dialog         (GimpDrawable  *drawable);
 
-static void      dialog_update_preview (gpointer       drawable_id,
+static void      dialog_update_preview (GimpDrawable  *drawable,
                                         GimpPreview   *preview);
-static void      apply_blinds          (gint32         drawable_id);
+static void      apply_blinds          (GimpDrawable  *drawable);
 
 
 /* Array to hold each size of fans. And no there are not each the
@@ -134,6 +134,7 @@ run (const gchar      *name,
      GimpParam       **return_vals)
 {
   static GimpParam  values[1];
+  GimpDrawable     *drawable;
   gint32            drawable_id;
   GimpRunMode       run_mode;
   GimpPDBStatusType status = GIMP_PDB_SUCCESS;
@@ -149,13 +150,17 @@ run (const gchar      *name,
 
   run_mode    = param[0].data.d_int32;
   drawable_id = param[2].data.d_drawable;
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_id));
 
   switch (run_mode)
     {
     case GIMP_RUN_INTERACTIVE:
       gimp_get_data (PLUG_IN_PROC, &bvals);
-      if (! blinds_dialog (drawable_id))
-        return;
+      if (! blinds_dialog (drawable))
+        {
+          g_object_unref (drawable);
+          return;
+        }
       break;
 
     case GIMP_RUN_NONINTERACTIVE:
@@ -179,12 +184,12 @@ run (const gchar      *name,
       break;
     }
 
-  if (gimp_drawable_is_rgb  (drawable_id) ||
-      gimp_drawable_is_gray (drawable_id))
+  if (gimp_drawable_is_rgb  (drawable) ||
+      gimp_drawable_is_gray (drawable))
     {
       gimp_progress_init (_("Adding blinds"));
 
-      apply_blinds (drawable_id);
+      apply_blinds (drawable);
 
       if (run_mode != GIMP_RUN_NONINTERACTIVE)
         gimp_displays_flush ();
@@ -197,12 +202,13 @@ run (const gchar      *name,
       status = GIMP_PDB_EXECUTION_ERROR;
     }
 
+  g_object_unref (drawable);
   values[0].data.d_status = status;
 }
 
 
 static gboolean
-blinds_dialog (gint32 drawable_id)
+blinds_dialog (GimpDrawable *drawable)
 {
   GtkWidget     *dialog;
   GtkWidget     *main_vbox;
@@ -240,13 +246,13 @@ blinds_dialog (gint32 drawable_id)
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_aspect_preview_new_from_drawable_id (drawable_id);
+  preview = gimp_aspect_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
 
   g_signal_connect_swapped (preview, "invalidated",
                             G_CALLBACK (dialog_update_preview),
-                            GINT_TO_POINTER (drawable_id));
+                            drawable);
 
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
   gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
@@ -291,7 +297,7 @@ blinds_dialog (gint32 drawable_id)
 
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), bvals.bg_trans);
 
-  if (! gimp_drawable_has_alpha (drawable_id))
+  if (! gimp_drawable_has_alpha (drawable))
     {
       gtk_widget_set_sensitive (toggle, FALSE);
       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), FALSE);
@@ -442,10 +448,9 @@ blindsapply (guchar *srow,
 }
 
 static void
-dialog_update_preview (gpointer     drawable_ptr,
-                       GimpPreview *preview)
+dialog_update_preview (GimpDrawable *drawable,
+                       GimpPreview  *preview)
 {
-  gint32   drawable_id = GPOINTER_TO_INT (drawable_ptr);
   gint     y;
   guchar  *p, *buffer, *cache;
   GimpRGB  background;
@@ -453,7 +458,7 @@ dialog_update_preview (gpointer     drawable_ptr,
   gint     width, height, bpp;
 
   gimp_preview_get_size (preview, &width, &height);
-  cache = gimp_drawable_get_thumbnail_data (drawable_id,
+  cache = gimp_drawable_get_thumbnail_data (drawable,
                                             &width, &height, &bpp);
   p = cache;
 
@@ -462,7 +467,7 @@ dialog_update_preview (gpointer     drawable_ptr,
   if (bvals.bg_trans)
     gimp_rgb_set_alpha (&background, 0.0);
 
-  if (gimp_drawable_is_gray (drawable_id))
+  if (gimp_drawable_is_gray (drawable))
     {
       bg[0] = gimp_rgb_luminance_uchar (&background);
       gimp_rgba_get_uchar (&background, NULL, NULL, NULL, bg + 3);
@@ -557,7 +562,7 @@ dialog_update_preview (gpointer     drawable_ptr,
 #define STEP 40
 
 static void
-apply_blinds (gint32 drawable_id)
+apply_blinds (GimpDrawable *drawable)
 {
   GeglBuffer *src_buffer;
   GeglBuffer *dest_buffer;
@@ -577,20 +582,20 @@ apply_blinds (gint32 drawable_id)
 
   gimp_rgba_get_uchar (&background, bg, bg + 1, bg + 2, bg + 3);
 
-  if (! gimp_drawable_mask_intersect (drawable_id,
+  if (! gimp_drawable_mask_intersect (drawable,
                                       &sel_x1, &sel_y1,
                                       &sel_width, &sel_height))
     return;
 
-  if (gimp_drawable_has_alpha (drawable_id))
+  if (gimp_drawable_has_alpha (drawable))
     format = babl_format ("R'G'B'A u8");
   else
     format = babl_format ("R'G'B' u8");
 
   bytes = babl_format_get_bytes_per_pixel (format);
 
-  src_buffer  = gimp_drawable_get_buffer (drawable_id);
-  dest_buffer = gimp_drawable_get_shadow_buffer (drawable_id);
+  src_buffer  = gimp_drawable_get_buffer (drawable);
+  dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
 
   src_rows = g_new (guchar, MAX (sel_width, sel_height) * bytes * STEP);
   des_rows = g_new (guchar, MAX (sel_width, sel_height) * bytes * STEP);
@@ -724,7 +729,7 @@ apply_blinds (gint32 drawable_id)
 
   gimp_progress_update (1.0);
 
-  gimp_drawable_merge_shadow (drawable_id, TRUE);
-  gimp_drawable_update (drawable_id,
+  gimp_drawable_merge_shadow (drawable, TRUE);
+  gimp_drawable_update (drawable,
                         sel_x1, sel_y1, sel_width, sel_height);
 }
diff --git a/plug-ins/common/checkerboard.c b/plug-ins/common/checkerboard.c
index 986b255994..7797f5f40d 100644
--- a/plug-ins/common/checkerboard.c
+++ b/plug-ins/common/checkerboard.c
@@ -47,15 +47,15 @@ static void      run    (const gchar       *name,
                          gint              *nreturn_vals,
                          GimpParam        **return_vals);
 
-static void      do_checkerboard_pattern    (gint32        drawable_ID,
+static void      do_checkerboard_pattern    (GimpDrawable *drawable,
                                              GimpPreview  *preview);
-static void      do_checkerboard_preview    (gpointer      drawable_ID,
+static void      do_checkerboard_preview    (GimpDrawable *drawable,
                                              GimpPreview  *preview);
 static gint      inblock                    (gint          pos,
                                              gint          size);
 
-static gboolean  checkerboard_dialog        (gint32        image_ID,
-                                             gint32        drawable_ID);
+static gboolean  checkerboard_dialog        (GimpImage    *image,
+                                             GimpDrawable *drawable);
 static void      check_size_update_callback (GtkWidget    *widget);
 
 
@@ -111,6 +111,8 @@ run (const gchar      *name,
 {
   static GimpParam   values[1];
   GimpRunMode        run_mode;
+  GimpImage         *image;
+  GimpDrawable      *drawable;
   gint32             image_ID;
   gint32             drawable_ID;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
@@ -127,13 +129,19 @@ run (const gchar      *name,
   run_mode    = param[0].data.d_int32;
   image_ID    = param[1].data.d_int32;
   drawable_ID = param[2].data.d_drawable;
+  image       = gimp_image_new_by_id (image_ID);
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
   switch (run_mode)
     {
     case GIMP_RUN_INTERACTIVE:
       gimp_get_data (PLUG_IN_PROC, &cvals);
-      if (! checkerboard_dialog (image_ID, drawable_ID))
-        return;
+      if (! checkerboard_dialog (image, drawable))
+        {
+          g_object_unref (image);
+          g_object_unref (drawable);
+          return;
+        }
       break;
 
     case GIMP_RUN_NONINTERACTIVE:
@@ -154,10 +162,10 @@ run (const gchar      *name,
       break;
     }
 
-  if (gimp_drawable_is_rgb (drawable_ID) ||
-      gimp_drawable_is_gray (drawable_ID))
+  if (gimp_drawable_is_rgb (drawable) ||
+      gimp_drawable_is_gray (drawable))
     {
-      do_checkerboard_pattern (drawable_ID, NULL);
+      do_checkerboard_pattern (drawable, NULL);
 
       if (run_mode != GIMP_RUN_NONINTERACTIVE)
         gimp_displays_flush ();
@@ -170,6 +178,8 @@ run (const gchar      *name,
       status = GIMP_PDB_EXECUTION_ERROR;
     }
 
+  g_object_unref (drawable);
+  g_object_unref (image);
   values[0].data.d_status = status;
 }
 
@@ -214,8 +224,8 @@ checkerboard_func (gint      x,
 }
 
 static void
-do_checkerboard_pattern (gint32       drawable_ID,
-                         GimpPreview *preview)
+do_checkerboard_pattern (GimpDrawable *drawable,
+                         GimpPreview  *preview)
 {
   CheckerboardParam_t  param;
   GimpRGB              fg, bg;
@@ -225,7 +235,7 @@ do_checkerboard_pattern (gint32       drawable_ID,
   gimp_context_get_background (&bg);
   gimp_context_get_foreground (&fg);
 
-  if (gimp_drawable_is_gray (drawable_ID))
+  if (gimp_drawable_is_gray (drawable))
     {
       param.bg[0] = gimp_rgb_luminance_uchar (&bg);
       gimp_rgba_get_uchar (&bg, NULL, NULL, NULL, param.bg + 1);
@@ -233,7 +243,7 @@ do_checkerboard_pattern (gint32       drawable_ID,
       param.fg[0] = gimp_rgb_luminance_uchar (&fg);
       gimp_rgba_get_uchar (&fg, NULL, NULL, NULL, param.fg + 3);
 
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("R'G'B'A u8");
       else
         format = babl_format ("R'G'B' u8");
@@ -246,7 +256,7 @@ do_checkerboard_pattern (gint32       drawable_ID,
       gimp_rgba_get_uchar (&fg,
                            param.fg, param.fg + 1, param.fg + 2, param.fg + 3);
 
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("Y'A u8");
       else
         format = babl_format ("Y' u8");
@@ -269,7 +279,7 @@ do_checkerboard_pattern (gint32       drawable_ID,
 
       gimp_preview_get_position (preview, &x1, &y1);
       gimp_preview_get_size (preview, &width, &height);
-      bpp = gimp_drawable_bpp (drawable_ID);
+      bpp = gimp_drawable_bpp (drawable);
       buffer = g_new (guchar, width * height * bpp);
 
       for (i = 0; i < width * height; i++)
@@ -291,14 +301,14 @@ do_checkerboard_pattern (gint32       drawable_ID,
       gint                progress_total;
       gint                progress_done = 0;
 
-      if (! gimp_drawable_mask_intersect (drawable_ID, &x, &y, &w, &h))
+      if (! gimp_drawable_mask_intersect (drawable, &x, &y, &w, &h))
         return;
 
       progress_total = w * h;
 
       gimp_progress_init (_("Checkerboard"));
 
-      buffer = gimp_drawable_get_shadow_buffer (drawable_ID);
+      buffer = gimp_drawable_get_shadow_buffer (drawable);
 
       iter = gegl_buffer_iterator_new (buffer,
                                        GEGL_RECTANGLE (x, y, w, h), 0,
@@ -336,16 +346,16 @@ do_checkerboard_pattern (gint32       drawable_ID,
 
       gimp_progress_update (1.0);
 
-      gimp_drawable_merge_shadow (drawable_ID, TRUE);
-      gimp_drawable_update (drawable_ID, x, y, w, h);
+      gimp_drawable_merge_shadow (drawable, TRUE);
+      gimp_drawable_update (drawable, x, y, w, h);
     }
 }
 
 static void
-do_checkerboard_preview (gpointer     drawable_ID,
-                         GimpPreview *preview)
+do_checkerboard_preview (GimpDrawable *drawable,
+                         GimpPreview  *preview)
 {
-  do_checkerboard_pattern (GPOINTER_TO_INT (drawable_ID), preview);
+  do_checkerboard_pattern (drawable, preview);
 }
 
 static gint
@@ -404,8 +414,8 @@ inblock (gint pos,
 }
 
 static gboolean
-checkerboard_dialog (gint32 image_ID,
-                     gint32 drawable_ID)
+checkerboard_dialog (GimpImage    *image,
+                     GimpDrawable *drawable)
 {
   GtkWidget *dialog;
   GtkWidget *vbox;
@@ -443,23 +453,23 @@ checkerboard_dialog (gint32 image_ID,
                       vbox, TRUE, TRUE, 0);
   gtk_widget_show (vbox);
 
-  preview = gimp_drawable_preview_new_from_drawable_id (drawable_ID);
+  preview = gimp_drawable_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
   g_signal_connect_swapped (preview, "invalidated",
                             G_CALLBACK (do_checkerboard_preview),
-                            GINT_TO_POINTER (drawable_ID));
+                            drawable);
 
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
   gtk_widget_show (hbox);
 
   /*  Get the image resolution and unit  */
-  gimp_image_get_resolution (image_ID, &xres, &yres);
-  unit = gimp_image_get_unit (image_ID);
+  gimp_image_get_resolution (image, &xres, &yres);
+  unit = gimp_image_get_unit (image);
 
-  width  = gimp_drawable_width (drawable_ID);
-  height = gimp_drawable_height (drawable_ID);
+  width  = gimp_drawable_width (drawable);
+  height = gimp_drawable_height (drawable);
   size   = MIN (width, height);
 
   size_entry = gimp_size_entry_new (1, unit, "%a",
diff --git a/plug-ins/common/contrast-retinex.c b/plug-ins/common/contrast-retinex.c
index 72f9b48f07..57382eb9e4 100644
--- a/plug-ins/common/contrast-retinex.c
+++ b/plug-ins/common/contrast-retinex.c
@@ -81,10 +81,10 @@ static void     run                         (const gchar      *name,
                                              GimpParam       **return_vals);
 
 /* Gimp */
-static gboolean retinex_dialog              (gint32        drawable_ID);
-static void     retinex                     (gint32        drawable_ID,
+static gboolean retinex_dialog              (GimpDrawable *drawable);
+static void     retinex                     (GimpDrawable *drawable,
                                              GimpPreview  *preview);
-static void     retinex_preview             (gpointer      drawable_ID,
+static void     retinex_preview             (GimpDrawable *drawable,
                                              GimpPreview  *preview);
 
 static void     retinex_scales_distribution (gfloat       *scales,
@@ -183,6 +183,7 @@ run (const gchar      *name,
 {
   static GimpParam   values[1];
   GimpRunMode        run_mode;
+  GimpDrawable      *drawable;
   gint32             drawable_ID;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
   gint               x, y, width, height;
@@ -198,14 +199,16 @@ run (const gchar      *name,
 
   run_mode    = param[0].data.d_int32;
   drawable_ID = param[2].data.d_drawable;
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
-  if (! gimp_drawable_mask_intersect (drawable_ID,
+  if (! gimp_drawable_mask_intersect (drawable,
                                       &x, &y, &width, &height) ||
       width  < MIN_GAUSSIAN_SCALE ||
       height < MIN_GAUSSIAN_SCALE)
     {
       status = GIMP_PDB_EXECUTION_ERROR;
       values[0].data.d_status = status;
+      g_object_unref (drawable);
       return;
     }
 
@@ -216,8 +219,11 @@ run (const gchar      *name,
       gimp_get_data (PLUG_IN_PROC, &rvals);
 
       /*  First acquire information with a dialog  */
-      if (! retinex_dialog (drawable_ID))
-        return;
+      if (! retinex_dialog (drawable))
+        {
+          g_object_unref (drawable);
+          return;
+        }
       break;
 
     case GIMP_RUN_NONINTERACTIVE:
@@ -244,11 +250,11 @@ run (const gchar      *name,
     }
 
   if (status == GIMP_PDB_SUCCESS &&
-      (gimp_drawable_is_rgb (drawable_ID)))
+      (gimp_drawable_is_rgb (drawable)))
     {
       gimp_progress_init (_("Retinex"));
 
-      retinex (drawable_ID, NULL);
+      retinex (drawable, NULL);
 
       if (run_mode != GIMP_RUN_NONINTERACTIVE)
         gimp_displays_flush ();
@@ -262,12 +268,13 @@ run (const gchar      *name,
       status = GIMP_PDB_EXECUTION_ERROR;
     }
 
+  g_object_unref (drawable);
   values[0].data.d_status = status;
 }
 
 
 static gboolean
-retinex_dialog (gint32 drawable_ID)
+retinex_dialog (GimpDrawable *drawable)
 {
   GtkWidget     *dialog;
   GtkWidget     *main_vbox;
@@ -301,13 +308,13 @@ retinex_dialog (gint32 drawable_ID)
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_zoom_preview_new_from_drawable_id (drawable_ID);
+  preview = gimp_zoom_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
 
   g_signal_connect_swapped (preview, "invalidated",
                             G_CALLBACK (retinex_preview),
-                            GINT_TO_POINTER (drawable_ID));
+                            drawable);
 
   grid = gtk_grid_new ();
   gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
@@ -383,7 +390,7 @@ retinex_dialog (gint32 drawable_ID)
  * Applies the algorithm
  */
 static void
-retinex (gint32       drawable_ID,
+retinex (GimpDrawable *drawable,
          GimpPreview *preview)
 {
   GeglBuffer *src_buffer;
@@ -404,11 +411,11 @@ retinex (gint32       drawable_ID,
     }
   else
     {
-      if (! gimp_drawable_mask_intersect (drawable_ID,
+      if (! gimp_drawable_mask_intersect (drawable,
                                           &x, &y, &width, &height))
         return;
 
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("R'G'B'A u8");
       else
         format = babl_format ("R'G'B' u8");
@@ -428,7 +435,7 @@ retinex (gint32       drawable_ID,
       memset (src, 0, sizeof (guchar) * size);
 
       /* Fill allocated memory with pixel data */
-      src_buffer = gimp_drawable_get_buffer (drawable_ID);
+      src_buffer = gimp_drawable_get_buffer (drawable);
 
       gegl_buffer_get (src_buffer, GEGL_RECTANGLE (x, y, width, height), 1.0,
                        format, src,
@@ -447,7 +454,7 @@ retinex (gint32       drawable_ID,
     }
   else
     {
-      dest_buffer = gimp_drawable_get_shadow_buffer (drawable_ID);
+      dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
 
       gegl_buffer_set (dest_buffer, GEGL_RECTANGLE (x, y, width, height), 0,
                        format, psrc,
@@ -458,18 +465,18 @@ retinex (gint32       drawable_ID,
 
       gimp_progress_update (1.0);
 
-      gimp_drawable_merge_shadow (drawable_ID, TRUE);
-      gimp_drawable_update (drawable_ID, x, y, width, height);
+      gimp_drawable_merge_shadow (drawable, TRUE);
+      gimp_drawable_update (drawable, x, y, width, height);
     }
 
   g_free (src);
 }
 
 static void
-retinex_preview (gpointer     drawable_ID,
-                 GimpPreview *preview)
+retinex_preview (GimpDrawable *drawable,
+                 GimpPreview  *preview)
 {
-  retinex (GPOINTER_TO_INT (drawable_ID), preview);
+  retinex (drawable, preview);
 }
 
 /*
diff --git a/plug-ins/common/despeckle.c b/plug-ins/common/despeckle.c
index 310062bbef..48f4a7e441 100644
--- a/plug-ins/common/despeckle.c
+++ b/plug-ins/common/despeckle.c
@@ -119,8 +119,8 @@ const GimpPlugInInfo PLUG_IN_INFO =
   run    /* run   */
 };
 
-static GtkWidget *preview;          /* Preview widget   */
-static gint32     drawable_ID = -1; /* Current drawable */
+static GtkWidget    *preview;         /* Preview widget   */
+static GimpDrawable *drawable = NULL; /* Current drawable */
 
 
 static gint despeckle_vals[4] =
@@ -175,6 +175,7 @@ run (const gchar      *name,
   GimpRunMode        run_mode;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
   static GimpParam   values[1];
+  gint32             drawable_ID;
 
   INIT_I18N ();
   gegl_init (NULL, NULL);
@@ -187,17 +188,21 @@ run (const gchar      *name,
 
   run_mode    = param[0].data.d_int32;
   drawable_ID = param[2].data.d_drawable;
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
   switch (run_mode)
     {
     case GIMP_RUN_INTERACTIVE :
       gimp_get_data (PLUG_IN_PROC, &despeckle_radius);
 
-      if (gimp_drawable_is_rgb (drawable_ID) ||
-          gimp_drawable_is_gray (drawable_ID))
+      if (gimp_drawable_is_rgb (drawable) ||
+          gimp_drawable_is_gray (drawable))
        {
           if (! despeckle_dialog ())
-          return;
+            {
+              g_object_unref (drawable);
+              return;
+            }
        }
       break;
 
@@ -247,8 +252,8 @@ run (const gchar      *name,
 
   if (status == GIMP_PDB_SUCCESS)
     {
-      if (gimp_drawable_is_rgb (drawable_ID) ||
-          gimp_drawable_is_gray (drawable_ID))
+      if (gimp_drawable_is_rgb (drawable) ||
+          gimp_drawable_is_gray (drawable))
         {
           despeckle ();
 
@@ -265,6 +270,7 @@ run (const gchar      *name,
         }
     }
 
+  g_object_unref (drawable);
   values[0].data.d_status = status;
 }
 
@@ -329,20 +335,20 @@ despeckle (void)
   gint        x, y;
   gint        width, height;
 
-  if (! gimp_drawable_mask_intersect (drawable_ID,
+  if (! gimp_drawable_mask_intersect (drawable,
                                       &x, &y, &width, &height))
     return;
 
-  if (gimp_drawable_is_rgb (drawable_ID))
+  if (gimp_drawable_is_rgb (drawable))
     {
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("R'G'B'A u8");
       else
         format = babl_format ("R'G'B' u8");
     }
   else
     {
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("Y'A u8");
       else
         format = babl_format ("Y' u8");
@@ -350,8 +356,8 @@ despeckle (void)
 
   img_bpp = babl_format_get_bytes_per_pixel (format);
 
-  src_buffer  = gimp_drawable_get_buffer (drawable_ID);
-  dest_buffer = gimp_drawable_get_shadow_buffer (drawable_ID);
+  src_buffer  = gimp_drawable_get_buffer (drawable);
+  dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
 
   src = g_new (guchar, width * height * img_bpp);
   dst = g_new (guchar, width * height * img_bpp);
@@ -369,8 +375,8 @@ despeckle (void)
   g_object_unref (src_buffer);
   g_object_unref (dest_buffer);
 
-  gimp_drawable_merge_shadow (drawable_ID, TRUE);
-  gimp_drawable_update (drawable_ID, x, y, width, height);
+  gimp_drawable_merge_shadow (drawable, TRUE);
+  gimp_drawable_update (drawable, x, y, width, height);
 
   g_free (dst);
   g_free (src);
@@ -412,7 +418,7 @@ despeckle_dialog (void)
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_drawable_preview_new_from_drawable_id (drawable_ID);
+  preview = gimp_drawable_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
 
@@ -525,16 +531,16 @@ preview_update (GtkWidget *widget)
 
   preview = GIMP_PREVIEW (widget);
 
-  if (gimp_drawable_is_rgb (drawable_ID))
+  if (gimp_drawable_is_rgb (drawable))
     {
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("R'G'B'A u8");
       else
         format = babl_format ("R'G'B' u8");
     }
   else
     {
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("Y'A u8");
       else
         format = babl_format ("Y' u8");
@@ -545,7 +551,7 @@ preview_update (GtkWidget *widget)
   gimp_preview_get_size (preview, &width, &height);
   gimp_preview_get_position (preview, &x1, &y1);
 
-  src_buffer = gimp_drawable_get_buffer (drawable_ID);
+  src_buffer = gimp_drawable_get_buffer (drawable);
 
   dst = g_new (guchar, width * height * img_bpp);
   src = g_new (guchar, width * height * img_bpp);
diff --git a/plug-ins/common/destripe.c b/plug-ins/common/destripe.c
index 2b5c3548b8..11bf6de14f 100644
--- a/plug-ins/common/destripe.c
+++ b/plug-ins/common/destripe.c
@@ -54,12 +54,12 @@ static void      run   (const gchar      *name,
                         gint             *nreturn_vals,
                         GimpParam       **return_vals);
 
-static void      destripe         (gint32        drawable_ID,
+static void      destripe         (GimpDrawable *drawable,
                                    GimpPreview  *preview);
-static void      destripe_preview (gpointer      drawable_ID,
+static void      destripe_preview (GimpDrawable *drawable,
                                    GimpPreview  *preview);
 
-static gboolean  destripe_dialog  (gint32        drawable_ID);
+static gboolean  destripe_dialog  (GimpDrawable *drawable);
 
 /*
  * Globals...
@@ -127,6 +127,7 @@ run (const gchar      *name,
   static GimpParam   values[1];  /* Return values */
   GimpPDBStatusType  status;     /* Return status */
   GimpRunMode        run_mode;   /* Current run mode */
+  GimpDrawable      *drawable;
   gint32             drawable_ID;
 
   INIT_I18N ();
@@ -142,6 +143,7 @@ run (const gchar      *name,
 
   run_mode    = param[0].data.d_int32;
   drawable_ID = param[2].data.d_drawable;
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
   switch (run_mode)
     {
@@ -154,8 +156,11 @@ run (const gchar      *name,
       /*
        * Get information from the dialog...
        */
-      if (! destripe_dialog (drawable_ID))
-        return;
+      if (! destripe_dialog (drawable))
+        {
+          g_object_unref (drawable);
+          return;
+        }
       break;
 
     case GIMP_RUN_NONINTERACTIVE:
@@ -186,13 +191,13 @@ run (const gchar      *name,
 
   if (status == GIMP_PDB_SUCCESS)
     {
-      if ((gimp_drawable_is_rgb (drawable_ID) ||
-           gimp_drawable_is_gray (drawable_ID)))
+      if ((gimp_drawable_is_rgb (drawable) ||
+           gimp_drawable_is_gray (drawable)))
         {
           /*
            * Run!
            */
-          destripe (drawable_ID, NULL);
+          destripe (drawable, NULL);
 
           /*
            * If run mode is interactive, flush displays...
@@ -212,6 +217,8 @@ run (const gchar      *name,
         }
     };
 
+  g_object_unref (drawable);
+
   /*
    * Reset the current run status...
    */
@@ -219,7 +226,7 @@ run (const gchar      *name,
 }
 
 static void
-destripe (gint32       drawable_ID,
+destripe (GimpDrawable *drawable,
           GimpPreview *preview)
 {
   GeglBuffer *src_buffer;
@@ -246,7 +253,7 @@ destripe (gint32       drawable_ID,
     {
       gimp_progress_init (_("Destriping"));
 
-      if (! gimp_drawable_mask_intersect (drawable_ID,
+      if (! gimp_drawable_mask_intersect (drawable,
                                           &x1, &y1, &width, &height))
         {
           return;
@@ -258,16 +265,16 @@ destripe (gint32       drawable_ID,
 
   x2 = x1 + width;
 
-  if (gimp_drawable_is_rgb (drawable_ID))
+  if (gimp_drawable_is_rgb (drawable))
     {
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("R'G'B'A u8");
       else
         format = babl_format ("R'G'B' u8");
     }
   else
     {
-      if (gimp_drawable_has_alpha (drawable_ID))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("Y'A u8");
       else
         format = babl_format ("Y' u8");
@@ -279,8 +286,8 @@ destripe (gint32       drawable_ID,
    * Setup for filter...
    */
 
-  src_buffer  = gimp_drawable_get_buffer (drawable_ID);
-  dest_buffer = gimp_drawable_get_shadow_buffer (drawable_ID);
+  src_buffer  = gimp_drawable_get_buffer (drawable);
+  dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
 
   hist = g_new (long, width * bpp);
   corr = g_new (long, width * bpp);
@@ -431,8 +438,8 @@ destripe (gint32       drawable_ID,
 
       gimp_progress_update (1.0);
 
-      gimp_drawable_merge_shadow (drawable_ID, TRUE);
-      gimp_drawable_update (drawable_ID,
+      gimp_drawable_merge_shadow (drawable, TRUE);
+      gimp_drawable_update (drawable,
                             x1, y1, width, height);
     }
 
@@ -441,15 +448,15 @@ destripe (gint32       drawable_ID,
 }
 
 static void
-destripe_preview (gpointer     drawable_ID,
+destripe_preview (GimpDrawable *drawable,
                   GimpPreview *preview)
 {
-  destripe (GPOINTER_TO_INT (drawable_ID), preview);
+  destripe (drawable, preview);
 }
 
 
 static gboolean
-destripe_dialog (gint32 drawable_ID)
+destripe_dialog (GimpDrawable *drawable)
 {
   GtkWidget     *dialog;
   GtkWidget     *main_vbox;
@@ -483,13 +490,13 @@ destripe_dialog (gint32 drawable_ID)
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_drawable_preview_new_from_drawable_id (drawable_ID);
+  preview = gimp_drawable_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
 
   g_signal_connect_swapped (preview, "invalidated",
                             G_CALLBACK (destripe_preview),
-                            GINT_TO_POINTER (drawable_ID));
+                            drawable);
 
   grid = gtk_grid_new ();
   gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
diff --git a/plug-ins/common/grid.c b/plug-ins/common/grid.c
index 3c5fe452f9..66a0fde98e 100644
--- a/plug-ins/common/grid.c
+++ b/plug-ins/common/grid.c
@@ -64,11 +64,11 @@ static void   run    (const gchar      *name,
 static guchar      best_cmap_match (const guchar  *cmap,
                                     gint           ncolors,
                                     const GimpRGB *color);
-static void        grid            (gint32         image_ID,
-                                    gint32         drawable_ID,
+static void        grid            (GimpImage     *image,
+                                    GimpDrawable  *drawable,
                                     GimpPreview   *preview);
-static gint        dialog          (gint32         image_ID,
-                                    gint32         drawable_ID);
+static gint        dialog          (GimpImage     *image,
+                                    GimpDrawable  *drawable);
 
 const GimpPlugInInfo PLUG_IN_INFO =
 {
@@ -162,6 +162,8 @@ run (const gchar      *name,
      GimpParam       **return_vals)
 {
   static GimpParam   values[1];
+  GimpImage         *image;
+  GimpDrawable      *drawable;
   gint32             image_ID;
   gint32             drawable_ID;
   GimpRunMode        run_mode;
@@ -176,6 +178,8 @@ run (const gchar      *name,
   run_mode    = param[0].data.d_int32;
   image_ID    = param[1].data.d_int32;
   drawable_ID = param[2].data.d_drawable;
+  image       = gimp_image_new_by_id (image_ID);
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
   if (run_mode == GIMP_RUN_NONINTERACTIVE)
     {
@@ -225,7 +229,7 @@ run (const gchar      *name,
 
   if (run_mode == GIMP_RUN_INTERACTIVE)
     {
-      if (! dialog (image_ID, drawable_ID))
+      if (! dialog (image, drawable))
         {
           /* The dialog was closed, or something similarly evil happened. */
           status = GIMP_PDB_EXECUTION_ERROR;
@@ -241,7 +245,7 @@ run (const gchar      *name,
     {
       gimp_progress_init (_("Drawing grid"));
 
-      grid (image_ID, drawable_ID, NULL);
+      grid (image, drawable, NULL);
 
       if (run_mode != GIMP_RUN_NONINTERACTIVE)
         gimp_displays_flush ();
@@ -250,6 +254,9 @@ run (const gchar      *name,
         gimp_set_data (PLUG_IN_PROC, &grid_cfg, sizeof (grid_cfg));
     }
 
+  g_object_unref (image);
+  g_object_unref (drawable);
+
   values[0].type          = GIMP_PDB_STATUS;
   values[0].data.d_status = status;
 }
@@ -323,9 +330,9 @@ pix_composite (guchar   *p1,
 }
 
 static void
-grid (gint32       image_ID,
-      gint32       drawable_ID,
-      GimpPreview *preview)
+grid (GimpImage    *image,
+      GimpDrawable *drawable,
+      GimpPreview  *preview)
 {
   GeglBuffer *src_buffer;
   GeglBuffer *dest_buffer;
@@ -351,9 +358,9 @@ grid (gint32       image_ID,
   gimp_rgba_get_uchar (&grid_cfg.icolor,
                        icolor, icolor + 1, icolor + 2, icolor + 3);
 
-  alpha = gimp_drawable_has_alpha (drawable_ID);
+  alpha = gimp_drawable_has_alpha (drawable);
 
-  switch (gimp_image_base_type (image_ID))
+  switch (gimp_image_base_type (image))
     {
     case GIMP_RGB:
       blend = TRUE;
@@ -377,7 +384,7 @@ grid (gint32       image_ID,
       break;
 
     case GIMP_INDEXED:
-      cmap = gimp_image_get_colormap (image_ID, &ncolors);
+      cmap = gimp_image_get_colormap (image, &ncolors);
 
       hcolor[0] = best_cmap_match (cmap, ncolors, &grid_cfg.hcolor);
       vcolor[0] = best_cmap_match (cmap, ncolors, &grid_cfg.vcolor);
@@ -386,7 +393,7 @@ grid (gint32       image_ID,
       g_free (cmap);
       blend = FALSE;
 
-      format = gimp_drawable_get_format (drawable_ID);
+      format = gimp_drawable_get_format (drawable);
       break;
 
     default:
@@ -410,17 +417,17 @@ grid (gint32       image_ID,
     {
       gint w, h;
 
-      if (! gimp_drawable_mask_intersect (drawable_ID,
+      if (! gimp_drawable_mask_intersect (drawable,
                                           &sx1, &sy1, &w, &h))
         return;
 
       sx2 = sx1 + w;
       sy2 = sy1 + h;
 
-      dest_buffer = gimp_drawable_get_shadow_buffer (drawable_ID);
+      dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
     }
 
-  src_buffer = gimp_drawable_get_buffer (drawable_ID);
+  src_buffer = gimp_drawable_get_buffer (drawable);
 
   dest = g_new (guchar, (sx2 - sx1) * bytes);
 
@@ -533,8 +540,8 @@ grid (gint32       image_ID,
 
       g_object_unref (dest_buffer);
 
-      gimp_drawable_merge_shadow (drawable_ID, TRUE);
-      gimp_drawable_update (drawable_ID,
+      gimp_drawable_merge_shadow (drawable, TRUE);
+      gimp_drawable_update (drawable,
                             sx1, sy1, sx2 - sx1, sy2 - sy1);
     }
 }
@@ -580,13 +587,12 @@ update_values (void)
 
 static void
 update_preview (GimpPreview  *preview,
-                gpointer      drawable_ID)
+                GimpDrawable  *drawable)
 {
   update_values ();
 
-  grid (gimp_item_get_image (GPOINTER_TO_INT (drawable_ID)),
-        GPOINTER_TO_INT (drawable_ID),
-        preview);
+  grid (gimp_item_get_image (GIMP_ITEM (drawable)),
+        drawable, preview);
 }
 
 static void
@@ -640,8 +646,8 @@ color_callback (GtkWidget *widget,
 
 
 static gint
-dialog (gint32 image_ID,
-        gint32 drawable_ID)
+dialog (GimpImage    *image,
+        GimpDrawable *drawable)
 {
   GimpColorConfig *config;
   GtkWidget       *dlg;
@@ -666,8 +672,8 @@ dialog (gint32 image_ID,
 
   gimp_ui_init (PLUG_IN_BINARY, TRUE);
 
-  d_width  = gimp_drawable_width  (drawable_ID);
-  d_height = gimp_drawable_height (drawable_ID);
+  d_width  = gimp_drawable_width  (drawable);
+  d_height = gimp_drawable_height (drawable);
 
   main_dialog = dlg = gimp_dialog_new (_("Grid"), PLUG_IN_ROLE,
                                        NULL, 0,
@@ -686,8 +692,8 @@ dialog (gint32 image_ID,
   gimp_window_set_transient (GTK_WINDOW (dlg));
 
   /*  Get the image resolution and unit  */
-  gimp_image_get_resolution (image_ID, &xres, &yres);
-  unit = gimp_image_get_unit (image_ID);
+  gimp_image_get_resolution (image, &xres, &yres);
+  unit = gimp_image_get_unit (image);
 
   main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
@@ -695,13 +701,13 @@ dialog (gint32 image_ID,
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_drawable_preview_new_from_drawable_id (drawable_ID);
+  preview = gimp_drawable_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
 
   g_signal_connect (preview, "invalidated",
                     G_CALLBACK (update_preview),
-                    GINT_TO_POINTER (drawable_ID));
+                    drawable);
 
   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
   gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
diff --git a/plug-ins/common/jigsaw.c b/plug-ins/common/jigsaw.c
index b58d597bea..750458fcca 100644
--- a/plug-ins/common/jigsaw.c
+++ b/plug-ins/common/jigsaw.c
@@ -69,12 +69,12 @@ static void run   (const gchar      *name,
                    gint             *nreturn_vals,
                    GimpParam       **return_vals);
 
-static void     jigsaw             (guint32       drawable_id,
+static void     jigsaw             (GimpDrawable *drawable,
                                     GimpPreview  *preview);
-static void     jigsaw_preview     (gpointer      drawable_id,
+static void     jigsaw_preview     (GimpDrawable *drawable,
                                     GimpPreview  *preview);
 
-static gboolean jigsaw_dialog      (guint32       drawable_id);
+static gboolean jigsaw_dialog      (GimpDrawable *drawable);
 
 static void     draw_jigsaw        (guchar    *buffer,
                                     gint       bufsize,
@@ -378,6 +378,7 @@ run (const gchar      *name,
 {
   static GimpParam   values[1];
   GimpRunMode        run_mode;
+  GimpDrawable      *drawable;
   guint32            drawable_id;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
 
@@ -386,6 +387,7 @@ run (const gchar      *name,
 
   run_mode    = param[0].data.d_int32;
   drawable_id = param[2].data.d_drawable;
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_id));
 
   switch (run_mode)
     {
@@ -398,7 +400,7 @@ run (const gchar      *name,
           config.blend_lines = param[6].data.d_int32;
           config.blend_amount = param[7].data.d_float;
 
-          jigsaw (drawable_id, NULL);
+          jigsaw (drawable, NULL);
         }
       else
         {
@@ -408,24 +410,26 @@ run (const gchar      *name,
 
     case GIMP_RUN_INTERACTIVE:
       gimp_get_data (PLUG_IN_PROC, &config);
-      if (! jigsaw_dialog (drawable_id))
+      if (! jigsaw_dialog (drawable))
         {
           status = GIMP_PDB_CANCEL;
           break;
         }
       gimp_progress_init (_("Assembling jigsaw"));
 
-      jigsaw (drawable_id, NULL);
+      jigsaw (drawable, NULL);
       gimp_set_data (PLUG_IN_PROC, &config, sizeof(config_t));
       gimp_displays_flush ();
       break;
 
     case GIMP_RUN_WITH_LAST_VALS:
       gimp_get_data (PLUG_IN_PROC, &config);
-      jigsaw (drawable_id, NULL);
+      jigsaw (drawable, NULL);
       gimp_displays_flush ();
     }  /* switch */
 
+  g_object_unref (drawable);
+
   *nreturn_vals = 1;
   *return_vals = values;
   values[0].type = GIMP_PDB_STATUS;
@@ -433,7 +437,7 @@ run (const gchar      *name,
 }
 
 static void
-jigsaw (guint32       drawable_id,
+jigsaw (GimpDrawable *drawable,
         GimpPreview  *preview)
 {
   GeglBuffer *gegl_buffer = NULL;
@@ -447,18 +451,18 @@ jigsaw (guint32       drawable_id,
   if (preview)
     {
       gimp_preview_get_size (preview, &width, &height);
-      buffer = gimp_drawable_get_thumbnail_data (drawable_id,
+      buffer = gimp_drawable_get_thumbnail_data (drawable,
                                                  &width, &height, &bytes);
       buffer_size = bytes * width * height;
     }
   else
     {
-      gegl_buffer = gimp_drawable_get_buffer (drawable_id);
+      gegl_buffer = gimp_drawable_get_buffer (drawable);
 
-      width  = gimp_drawable_width  (drawable_id);
-      height = gimp_drawable_height (drawable_id);
+      width  = gimp_drawable_width  (drawable);
+      height = gimp_drawable_height (drawable);
 
-      if (gimp_drawable_has_alpha (drawable_id))
+      if (gimp_drawable_has_alpha (drawable))
         format = babl_format ("R'G'B'A u8");
       else
         format = babl_format ("R'G'B' u8");
@@ -491,25 +495,25 @@ jigsaw (guint32       drawable_id,
     }
   else
     {
-      gegl_buffer = gimp_drawable_get_shadow_buffer (drawable_id);
+      gegl_buffer = gimp_drawable_get_shadow_buffer (drawable);
 
       gegl_buffer_set (gegl_buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
                        format, buffer,
                        GEGL_AUTO_ROWSTRIDE);
       g_object_unref (gegl_buffer);
 
-      gimp_drawable_merge_shadow (drawable_id, TRUE);
-      gimp_drawable_update (drawable_id, 0, 0, width, height);
+      gimp_drawable_merge_shadow (drawable, TRUE);
+      gimp_drawable_update (drawable, 0, 0, width, height);
     }
 
   g_free (buffer);
 }
 
 static void
-jigsaw_preview (gpointer     drawable_id,
-                GimpPreview *preview)
+jigsaw_preview (GimpDrawable *drawable,
+                GimpPreview  *preview)
 {
-  jigsaw (GPOINTER_TO_INT (drawable_id), preview);
+  jigsaw (drawable, preview);
 }
 
 static void
@@ -2393,7 +2397,7 @@ check_config (gint width,
 ********************************************************/
 
 static gboolean
-jigsaw_dialog (guint32 drawable_id)
+jigsaw_dialog (GimpDrawable *drawable)
 {
   GtkWidget     *dialog;
   GtkWidget     *main_vbox;
@@ -2430,13 +2434,13 @@ jigsaw_dialog (guint32 drawable_id)
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_aspect_preview_new_from_drawable_id (drawable_id);
+  preview = gimp_aspect_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
 
   g_signal_connect_swapped (preview, "invalidated",
                             G_CALLBACK (jigsaw_preview),
-                            GINT_TO_POINTER (drawable_id));
+                            drawable);
 
   frame = gimp_frame_new (_("Number of Tiles"));
   gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
diff --git a/plug-ins/common/nl-filter.c b/plug-ins/common/nl-filter.c
index a05722e3e7..f9b3130f48 100644
--- a/plug-ins/common/nl-filter.c
+++ b/plug-ins/common/nl-filter.c
@@ -73,12 +73,12 @@ static void     run              (const gchar      *name,
                                   gint             *nretvals,
                                   GimpParam       **retvals);
 
-static void     nlfilter         (gint32            drawable_id,
+static void     nlfilter         (GimpDrawable     *drawable,
                                   GimpPreview      *preview);
-static void     nlfilter_preview (gpointer          drawable_id,
+static void     nlfilter_preview (GimpDrawable     *drawable,
                                   GimpPreview      *preview);
 
-static gboolean nlfilter_dialog  (gint32            drawable_id);
+static gboolean nlfilter_dialog  (GimpDrawable     *drawable);
 
 static gint     nlfiltInit       (gdouble           alpha,
                                   gdouble           radius,
@@ -144,6 +144,7 @@ run (const gchar      *name,
 {
   static GimpParam   values[1];
   GimpRunMode        run_mode;
+  GimpDrawable      *drawable;
   gint32             drawable_id;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
 
@@ -152,6 +153,7 @@ run (const gchar      *name,
 
   run_mode    = param[0].data.d_int32;
   drawable_id = param[2].data.d_drawable;
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_id));
 
   *nreturn_vals = 1;
   *return_vals  = values;
@@ -164,8 +166,11 @@ run (const gchar      *name,
     case GIMP_RUN_INTERACTIVE:
       gimp_get_data (PLUG_IN_PROC, &nlfvals);
 
-      if (! nlfilter_dialog (drawable_id))
-        return;
+      if (! nlfilter_dialog (drawable))
+        {
+          g_object_unref (drawable);
+          return;
+        }
       break;
 
     case GIMP_RUN_NONINTERACTIVE:
@@ -192,13 +197,14 @@ run (const gchar      *name,
 
   if (status == GIMP_PDB_SUCCESS)
     {
-      nlfilter (drawable_id, NULL);
+      nlfilter (drawable, NULL);
 
       /* Store data */
       if (run_mode == GIMP_RUN_INTERACTIVE)
         gimp_set_data (PLUG_IN_PROC, &nlfvals, sizeof (NLFilterValues));
     }
 
+  g_object_unref (drawable);
   values[0].data.d_status = status;
 }
 
@@ -901,7 +907,7 @@ rectang_area (gdouble rx0, gdouble ry0, gdouble rx1, gdouble ry1, gdouble tx0,
 }
 
 static void
-nlfilter (gint32        drawable_id,
+nlfilter (GimpDrawable *drawable,
           GimpPreview  *preview)
 {
   GeglBuffer *src_buffer;
@@ -921,24 +927,24 @@ nlfilter (gint32        drawable_id,
     }
   else
     {
-      if (! gimp_drawable_mask_intersect (drawable_id,
+      if (! gimp_drawable_mask_intersect (drawable,
                                           &x1, &y1, &width, &height))
         return;
 
       y2 = y1 + height;
     }
 
-  if (gimp_drawable_has_alpha (drawable_id))
+  if (gimp_drawable_has_alpha (drawable))
     format = babl_format ("R'G'B'A u8");
   else
     format = babl_format ("R'G'B' u8");
 
-  src_buffer = gimp_drawable_get_buffer (drawable_id);
+  src_buffer = gimp_drawable_get_buffer (drawable);
 
   if (preview)
     dest_buffer = gegl_buffer_new (gegl_buffer_get_extent (src_buffer), format);
   else
-    dest_buffer = gimp_drawable_get_shadow_buffer (drawable_id);
+    dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
 
   bpp = babl_format_get_bytes_per_pixel (format);
 
@@ -1024,21 +1030,21 @@ nlfilter (gint32        drawable_id,
     {
       gimp_progress_update (1.0);
 
-      gimp_drawable_merge_shadow (drawable_id, TRUE);
-      gimp_drawable_update (drawable_id, x1, y1, width, height);
+      gimp_drawable_merge_shadow (drawable, TRUE);
+      gimp_drawable_update (drawable, x1, y1, width, height);
       gimp_displays_flush ();
     }
 }
 
 static void
-nlfilter_preview (gpointer     drawable_id,
-                  GimpPreview *preview)
+nlfilter_preview (GimpDrawable *drawable,
+                  GimpPreview  *preview)
 {
-  nlfilter (GPOINTER_TO_INT (drawable_id), preview);
+  nlfilter (drawable, preview);
 }
 
 static gboolean
-nlfilter_dialog (gint32 drawable_id)
+nlfilter_dialog (GimpDrawable *drawable)
 {
   GtkWidget     *dialog;
   GtkWidget     *main_vbox;
@@ -1075,13 +1081,13 @@ nlfilter_dialog (gint32 drawable_id)
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_drawable_preview_new_from_drawable_id (drawable_id);
+  preview = gimp_drawable_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
 
   g_signal_connect_swapped (preview, "invalidated",
                             G_CALLBACK (nlfilter_preview),
-                            GINT_TO_POINTER (drawable_id));
+                            drawable);
 
   frame = gimp_int_radio_group_new (TRUE, _("Filter"),
                                     G_CALLBACK (gimp_radio_button_update),
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index c41f6783ff..3290012cf6 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -2,20 +2,20 @@
     'align-layers' => { ui => 1, old_api => 1 },
     'animation-optimize' => { gegl => 1, old_api => 1 },
     'animation-play' => { ui => 1, gegl => 1, old_api => 1 },
-    'blinds' => { ui => 1, gegl => 1, old_api => 1 },
+    'blinds' => { ui => 1, gegl => 1 },
     'border-average' => { ui => 1, gegl => 1, old_api => 1 },
     'busy-dialog' => { ui => 1, gegl => 1, old_api => 1 },
-    'checkerboard' => { ui => 1, gegl => 1, old_api => 1 },
+    'checkerboard' => { ui => 1, gegl => 1 },
     'cml-explorer' => { ui => 1, gegl => 1, old_api => 1 },
     'colormap-remap' => { ui => 1, gegl => 1, old_api => 1 },
     'compose' => { ui => 1, gegl => 1, old_api => 1 },
-    'contrast-retinex' => { ui => 1, gegl => 1, old_api => 1 },
+    'contrast-retinex' => { ui => 1, gegl => 1 },
     'crop-zealous' => { gegl => 1, old_api => 1 },
     'curve-bend' => { ui => 1, gegl => 1, old_api => 1 },
     'decompose' => { ui => 1, gegl => 1, old_api => 1 },
     'depth-merge' => { ui => 1, gegl => 1, old_api => 1 },
-    'despeckle' => { ui => 1, gegl => 1, old_api => 1 },
-    'destripe' => { ui => 1, gegl => 1, old_api => 1 },
+    'despeckle' => { ui => 1, gegl => 1 },
+    'destripe' => { ui => 1, gegl => 1 },
     'file-aa' => { ui => 1, gegl => 1, optional => 1, libs => 'AA_LIBS', old_api => 1 },
     'file-cel' => { ui => 1, gegl => 1, old_api => 1 },
     'file-csource' => { ui => 1, gegl => 1, old_api => 1 },
@@ -53,18 +53,18 @@
     'file-xwd' => {  ui => 1, gegl => 1, old_api => 1 },
     'film' => { ui => 1, gegl => 1, old_api => 1 },
     'gradient-map' => { gegl => 1, old_api => 1 },
-    'grid' => { ui => 1, gegl => 1, old_api => 1 },
+    'grid' => { ui => 1, gegl => 1 },
     'guillotine' => { old_api => 1 },
     'hot' => { ui => 1, gegl => 1, old_api => 1 },
-    'jigsaw' => { ui => 1, gegl => 1, old_api => 1 },
+    'jigsaw' => { ui => 1, gegl => 1 },
     'mail' => { ui => 1, optional => 1, old_api => 1 },
-    'nl-filter' => { ui => 1, gegl => 1, old_api => 1 },
+    'nl-filter' => { ui => 1, gegl => 1 },
     'plugin-browser' => { ui => 1, old_api => 1 },
     'procedure-browser' => { ui => 1, old_api => 1 },
     'qbist' => { ui => 1, gegl => 1, old_api => 1 },
     'sample-colorize' => { ui => 1, gegl => 1, old_api => 1 },
     'smooth-palette' => { ui => 1, gegl => 1, old_api => 1 },
-    'sparkle' => { ui => 1, gegl => 1, old_api => 1 },
+    'sparkle' => { ui => 1, gegl => 1 },
     'sphere-designer' => { ui => 1, gegl => 1, old_api => 1 },
     'tile' => { ui => 1, gegl => 1, old_api => 1 },
     'tile-small' => { ui => 1, gegl => 1, old_api => 1 },
diff --git a/plug-ins/common/sparkle.c b/plug-ins/common/sparkle.c
index 305f732328..6220a39d80 100644
--- a/plug-ins/common/sparkle.c
+++ b/plug-ins/common/sparkle.c
@@ -80,16 +80,16 @@ static void      run    (const gchar      *name,
                          gint             *nreturn_vals,
                          GimpParam       **return_vals);
 
-static gboolean  sparkle_dialog        (gint32        drawable_ID);
+static gboolean  sparkle_dialog        (GimpDrawable *drawable);
 
 static gint      compute_luminosity    (const guchar *pixel,
                                         gboolean      gray,
                                         gboolean      has_alpha);
-static gint      compute_lum_threshold (gint32        drawable_ID,
+static gint      compute_lum_threshold (GimpDrawable *drawable,
                                         gdouble       percentile);
-static void      sparkle               (gint32        drawable_ID,
+static void      sparkle               (GimpDrawable *drawable,
                                         GimpPreview  *preview);
-static void      sparkle_preview       (gpointer      drawable_ID,
+static void      sparkle_preview       (GimpDrawable *drawable,
                                         GimpPreview  *preview);
 static void      fspike                (GeglBuffer   *src_buffer,
                                         GeglBuffer   *dest_buffer,
@@ -200,6 +200,7 @@ run (const gchar      *name,
 {
   static GimpParam   values[1];
   GimpRunMode        run_mode;
+  GimpDrawable      *drawable;
   gint32             drawable_ID;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
   gint               x, y, w, h;
@@ -215,10 +216,12 @@ run (const gchar      *name,
 
   run_mode    = param[0].data.d_int32;
   drawable_ID = param[2].data.d_drawable;
+  drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
-  if (! gimp_drawable_mask_intersect (drawable_ID, &x, &y, &w, &h))
+  if (! gimp_drawable_mask_intersect (drawable, &x, &y, &w, &h))
     {
       g_message (_("Region selected for filter is empty"));
+      g_object_unref (drawable);
       return;
     }
 
@@ -229,8 +232,11 @@ run (const gchar      *name,
       gimp_get_data (PLUG_IN_PROC, &svals);
 
       /*  First acquire information with a dialog  */
-      if (! sparkle_dialog (drawable_ID))
-        return;
+      if (! sparkle_dialog (drawable))
+        {
+          g_object_unref (drawable);
+          return;
+        }
       break;
 
     case GIMP_RUN_NONINTERACTIVE:
@@ -289,12 +295,12 @@ run (const gchar      *name,
     }
 
   /*  Make sure that the drawable is gray or RGB color  */
-  if (gimp_drawable_is_rgb (drawable_ID) ||
-      gimp_drawable_is_gray (drawable_ID))
+  if (gimp_drawable_is_rgb (drawable) ||
+      gimp_drawable_is_gray (drawable))
     {
       gimp_progress_init (_("Sparkling"));
 
-      sparkle (drawable_ID, NULL);
+      sparkle (drawable, NULL);
 
       if (run_mode != GIMP_RUN_NONINTERACTIVE)
         gimp_displays_flush ();
@@ -309,11 +315,12 @@ run (const gchar      *name,
       status = GIMP_PDB_EXECUTION_ERROR;
     }
 
+  g_object_unref (drawable);
   values[0].data.d_status = status;
 }
 
 static gboolean
-sparkle_dialog (gint32 drawable_ID)
+sparkle_dialog (GimpDrawable *drawable)
 {
   GtkWidget     *dialog;
   GtkWidget     *main_vbox;
@@ -350,12 +357,12 @@ sparkle_dialog (gint32 drawable_ID)
                       main_vbox, TRUE, TRUE, 0);
   gtk_widget_show (main_vbox);
 
-  preview = gimp_drawable_preview_new_from_drawable_id (drawable_ID);
+  preview = gimp_drawable_preview_new_from_drawable (drawable);
   gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
   gtk_widget_show (preview);
   g_signal_connect_swapped (preview, "invalidated",
                             G_CALLBACK (sparkle_preview),
-                            GINT_TO_POINTER (drawable_ID));
+                            drawable);
 
   grid = gtk_grid_new ();
   gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
@@ -616,7 +623,7 @@ compute_luminosity (const guchar *pixel,
 }
 
 static gint
-compute_lum_threshold (gint32  drawable_ID,
+compute_lum_threshold (GimpDrawable *drawable,
                        gdouble percentile)
 {
   GeglBuffer         *src_buffer;
@@ -634,12 +641,12 @@ compute_lum_threshold (gint32  drawable_ID,
   /*  zero out the luminosity values array  */
   memset (values, 0, sizeof (gint) * 256);
 
-  if (! gimp_drawable_mask_intersect (drawable_ID,
+  if (! gimp_drawable_mask_intersect (drawable,
                                       &x1, &y1, &width, &height))
     return 0;
 
-  gray = gimp_drawable_is_gray (drawable_ID);
-  has_alpha = gimp_drawable_has_alpha (drawable_ID);
+  gray = gimp_drawable_is_gray (drawable);
+  has_alpha = gimp_drawable_has_alpha (drawable);
 
   if (gray)
     {
@@ -658,7 +665,7 @@ compute_lum_threshold (gint32  drawable_ID,
 
   bpp = babl_format_get_bytes_per_pixel (format);
 
-  src_buffer = gimp_drawable_get_buffer (drawable_ID);
+  src_buffer = gimp_drawable_get_buffer (drawable);
 
   iter = gegl_buffer_iterator_new (src_buffer,
                                    GEGL_RECTANGLE (x1, y1, width, height), 0,
@@ -696,8 +703,8 @@ compute_lum_threshold (gint32  drawable_ID,
 }
 
 static void
-sparkle (gint32       drawable_ID,
-         GimpPreview *preview)
+sparkle (GimpDrawable *drawable,
+         GimpPreview  *preview)
 {
   GeglBuffer         *src_buffer;
   GeglBuffer         *dest_buffer;
@@ -716,8 +723,8 @@ sparkle (gint32       drawable_ID,
   GRand              *gr;
   guchar             *dest_buf = NULL;
 
-  gray = gimp_drawable_is_gray (drawable_ID);
-  has_alpha = gimp_drawable_has_alpha (drawable_ID);
+  gray = gimp_drawable_is_gray (drawable);
+  has_alpha = gimp_drawable_has_alpha (drawable);
 
   if (gray)
     {
@@ -749,7 +756,7 @@ sparkle (gint32       drawable_ID,
     }
   else
     {
-      if (! gimp_drawable_mask_intersect (drawable_ID,
+      if (! gimp_drawable_mask_intersect (drawable,
                                           &x1, &y1, &width, &height))
         return;
 
@@ -760,8 +767,8 @@ sparkle (gint32       drawable_ID,
   if (width < 1 || height < 1)
     return;
 
-  d_width  = gimp_drawable_width  (drawable_ID);
-  d_height = gimp_drawable_height (drawable_ID);
+  d_width  = gimp_drawable_width  (drawable);
+  d_height = gimp_drawable_height (drawable);
 
   gr = g_rand_new ();
 
@@ -773,7 +780,7 @@ sparkle (gint32       drawable_ID,
   else
     {
       /*  compute the luminosity which exceeds the luminosity threshold  */
-      threshold = compute_lum_threshold (drawable_ID, svals.lum_threshold);
+      threshold = compute_lum_threshold (drawable, svals.lum_threshold);
     }
 
   /* initialize the progress dialog */
@@ -781,8 +788,8 @@ sparkle (gint32       drawable_ID,
   max_progress = num_sparkles;
 
   /* copy what is already there */
-  src_buffer  = gimp_drawable_get_buffer (drawable_ID);
-  dest_buffer = gimp_drawable_get_shadow_buffer (drawable_ID);
+  src_buffer  = gimp_drawable_get_buffer (drawable);
+  dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
 
   iter = gegl_buffer_iterator_new (src_buffer,
                                    GEGL_RECTANGLE (x1, y1, width, height), 0,
@@ -944,18 +951,18 @@ sparkle (gint32       drawable_ID,
     {
       gimp_progress_update (1.0);
 
-      gimp_drawable_merge_shadow (drawable_ID, TRUE);
-      gimp_drawable_update (drawable_ID, x1, y1, width, height);
+      gimp_drawable_merge_shadow (drawable, TRUE);
+      gimp_drawable_update (drawable, x1, y1, width, height);
     }
 
   g_rand_free (gr);
 }
 
 static void
-sparkle_preview (gpointer     drawable_ID,
-                 GimpPreview *preview)
+sparkle_preview (GimpDrawable *drawable,
+                 GimpPreview  *preview)
 {
-  sparkle (GPOINTER_TO_INT (drawable_ID), preview);
+  sparkle (drawable, preview);
 }
 
 static inline void


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