[gimp/wip/Jehan/classy-GIMP: 38/50] plug-ins: port screenshot to GimpImage/GimpDrawable.



commit 9f0dbb57598e84bb2d56461774655a8ec0aead95
Author: Jehan <jehan girinstud io>
Date:   Fri Aug 16 11:54:50 2019 +0200

    plug-ins: port screenshot to GimpImage/GimpDrawable.

 plug-ins/screenshot/Makefile.am              |  1 -
 plug-ins/screenshot/screenshot-freedesktop.c | 26 ++++++++--------
 plug-ins/screenshot/screenshot-freedesktop.h |  2 +-
 plug-ins/screenshot/screenshot-gnome-shell.c |  8 ++---
 plug-ins/screenshot/screenshot-gnome-shell.h |  2 +-
 plug-ins/screenshot/screenshot-kwin.c        |  8 ++---
 plug-ins/screenshot/screenshot-kwin.h        |  2 +-
 plug-ins/screenshot/screenshot-osx.c         |  8 ++---
 plug-ins/screenshot/screenshot-osx.h         |  2 +-
 plug-ins/screenshot/screenshot-win32.h       |  2 +-
 plug-ins/screenshot/screenshot-x11.c         | 44 ++++++++++++++--------------
 plug-ins/screenshot/screenshot-x11.h         |  2 +-
 plug-ins/screenshot/screenshot.c             | 36 +++++++++++------------
 13 files changed, 71 insertions(+), 72 deletions(-)
---
diff --git a/plug-ins/screenshot/Makefile.am b/plug-ins/screenshot/Makefile.am
index 9ca66e391c..0d8d829f21 100644
--- a/plug-ins/screenshot/Makefile.am
+++ b/plug-ins/screenshot/Makefile.am
@@ -16,7 +16,6 @@ endif
 AM_LDFLAGS = $(mwindows)
 
 AM_CPPFLAGS = \
-       -DGIMP_DEPRECATED_REPLACE_NEW_API \
        -I$(top_srcdir)         \
        $(GTK_CFLAGS)           \
        $(GEGL_CFLAGS)          \
diff --git a/plug-ins/screenshot/screenshot-freedesktop.c b/plug-ins/screenshot/screenshot-freedesktop.c
index 38906acc1c..35aa27d256 100644
--- a/plug-ins/screenshot/screenshot-freedesktop.c
+++ b/plug-ins/screenshot/screenshot-freedesktop.c
@@ -73,11 +73,11 @@ screenshot_freedesktop_get_capabilities (void)
 }
 
 static void
-screenshot_freedesktop_dbus_signal (GDBusProxy *proxy,
-                                    gchar      *sender_name,
-                                    gchar      *signal_name,
-                                    GVariant   *parameters,
-                                    gint32     *image_ID)
+screenshot_freedesktop_dbus_signal (GDBusProxy  *proxy,
+                                    gchar       *sender_name,
+                                    gchar       *signal_name,
+                                    GVariant    *parameters,
+                                    GimpImage  **image)
 {
   if (g_strcmp0 (signal_name, "Response") == 0)
     {
@@ -103,9 +103,9 @@ screenshot_freedesktop_dbus_signal (GDBusProxy *proxy,
               GFile *file = g_file_new_for_uri (uri);
               gchar *path = g_file_get_path (file);
 
-              *image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
-                                          path, path);
-              gimp_image_set_filename (*image_ID, "screenshot.png");
+              *image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
+                                       path, path);
+              gimp_image_set_filename (*image, "screenshot.png");
 
               /* Delete the actual file. */
               g_file_delete (file, NULL, NULL);
@@ -125,7 +125,7 @@ screenshot_freedesktop_dbus_signal (GDBusProxy *proxy,
 GimpPDBStatusType
 screenshot_freedesktop_shoot (ScreenshotValues  *shootvals,
                               GdkMonitor        *monitor,
-                              gint32            *image_ID,
+                              GimpImage        **image,
                               GError           **error)
 {
   GVariant *retval;
@@ -163,17 +163,17 @@ screenshot_freedesktop_shoot (ScreenshotValues  *shootvals,
                                               opath,
                                               "org.freedesktop.portal.Request",
                                               NULL, NULL);
-      *image_ID = 0;
+      *image = NULL;
       g_signal_connect (proxy2, "g-signal",
                         G_CALLBACK (screenshot_freedesktop_dbus_signal),
-                        image_ID);
+                        image);
 
       gtk_main ();
       g_object_unref (proxy2);
       g_free (opath);
 
       /* Signal got a response. */
-      if (*image_ID)
+      if (*image)
         {
           GimpColorProfile *profile;
 
@@ -186,7 +186,7 @@ screenshot_freedesktop_shoot (ScreenshotValues  *shootvals,
           profile = gimp_monitor_get_color_profile (monitor);
           if (profile)
             {
-              gimp_image_set_color_profile (*image_ID, profile);
+              gimp_image_set_color_profile (*image, profile);
               g_object_unref (profile);
             }
 
diff --git a/plug-ins/screenshot/screenshot-freedesktop.h b/plug-ins/screenshot/screenshot-freedesktop.h
index d4f9a0874b..30a4161c0f 100644
--- a/plug-ins/screenshot/screenshot-freedesktop.h
+++ b/plug-ins/screenshot/screenshot-freedesktop.h
@@ -25,7 +25,7 @@ ScreenshotCapabilities screenshot_freedesktop_get_capabilities (void);
 
 GimpPDBStatusType      screenshot_freedesktop_shoot            (ScreenshotValues  *shootvals,
                                                                 GdkMonitor        *monitor,
-                                                                gint32            *image_ID,
+                                                                GimpImage        **image,
                                                                 GError           **error);
 
 
diff --git a/plug-ins/screenshot/screenshot-gnome-shell.c b/plug-ins/screenshot/screenshot-gnome-shell.c
index 5a350f5fab..e189e81e8e 100644
--- a/plug-ins/screenshot/screenshot-gnome-shell.c
+++ b/plug-ins/screenshot/screenshot-gnome-shell.c
@@ -78,7 +78,7 @@ screenshot_gnome_shell_get_capabilities (void)
 GimpPDBStatusType
 screenshot_gnome_shell_shoot (ScreenshotValues  *shootvals,
                               GdkMonitor        *monitor,
-                              gint32            *image_ID,
+                              GimpImage        **image,
                               GError           **error)
 {
   gchar       *filename;
@@ -176,15 +176,15 @@ screenshot_gnome_shell_shoot (ScreenshotValues  *shootvals,
     {
       GimpColorProfile *profile;
 
-      *image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
+      *image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
                                   filename, filename);
-      gimp_image_set_filename (*image_ID, "screenshot.png");
+      gimp_image_set_filename (*image, "screenshot.png");
 
       profile = gimp_monitor_get_color_profile (monitor);
 
       if (profile)
         {
-          gimp_image_set_color_profile (*image_ID, profile);
+          gimp_image_set_color_profile (*image, profile);
           g_object_unref (profile);
         }
 
diff --git a/plug-ins/screenshot/screenshot-gnome-shell.h b/plug-ins/screenshot/screenshot-gnome-shell.h
index bdc6c2082c..2d4e42634b 100644
--- a/plug-ins/screenshot/screenshot-gnome-shell.h
+++ b/plug-ins/screenshot/screenshot-gnome-shell.h
@@ -25,7 +25,7 @@ ScreenshotCapabilities screenshot_gnome_shell_get_capabilities (void);
 
 GimpPDBStatusType      screenshot_gnome_shell_shoot            (ScreenshotValues  *shootvals,
                                                                 GdkMonitor        *monitor,
-                                                                gint32            *image_ID,
+                                                                GimpImage        **image,
                                                                 GError           **error);
 
 
diff --git a/plug-ins/screenshot/screenshot-kwin.c b/plug-ins/screenshot/screenshot-kwin.c
index 2509729337..0a53bce50f 100644
--- a/plug-ins/screenshot/screenshot-kwin.c
+++ b/plug-ins/screenshot/screenshot-kwin.c
@@ -83,7 +83,7 @@ screenshot_kwin_get_capabilities (void)
 GimpPDBStatusType
 screenshot_kwin_shoot (ScreenshotValues  *shootvals,
                        GdkMonitor        *monitor,
-                       gint32            *image_ID,
+                       GimpImage        **image,
                        GError           **error)
 {
   gchar       *filename = NULL;
@@ -168,9 +168,9 @@ screenshot_kwin_shoot (ScreenshotValues  *shootvals,
     {
       GimpColorProfile *profile;
 
-      *image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
+      *image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
                                   filename, filename);
-      gimp_image_set_filename (*image_ID, "screenshot.png");
+      gimp_image_set_filename (*image, "screenshot.png");
 
       /* This is very wrong in multi-display setups since we have no
        * idea which profile is to be used. Let's keep it anyway and
@@ -181,7 +181,7 @@ screenshot_kwin_shoot (ScreenshotValues  *shootvals,
 
       if (profile)
         {
-          gimp_image_set_color_profile (*image_ID, profile);
+          gimp_image_set_color_profile (*image, profile);
           g_object_unref (profile);
         }
 
diff --git a/plug-ins/screenshot/screenshot-kwin.h b/plug-ins/screenshot/screenshot-kwin.h
index 361b29ad22..b978ea6a5a 100644
--- a/plug-ins/screenshot/screenshot-kwin.h
+++ b/plug-ins/screenshot/screenshot-kwin.h
@@ -25,7 +25,7 @@ ScreenshotCapabilities screenshot_kwin_get_capabilities (void);
 
 GimpPDBStatusType      screenshot_kwin_shoot            (ScreenshotValues  *shootvals,
                                                          GdkMonitor        *monitor,
-                                                         gint32            *image_ID,
+                                                         GimpImage        **image,
                                                          GError           **error);
 
 
diff --git a/plug-ins/screenshot/screenshot-osx.c b/plug-ins/screenshot/screenshot-osx.c
index dcd93728ac..1a2dd0d288 100644
--- a/plug-ins/screenshot/screenshot-osx.c
+++ b/plug-ins/screenshot/screenshot-osx.c
@@ -76,7 +76,7 @@ screenshot_osx_get_capabilities (void)
 GimpPDBStatusType
 screenshot_osx_shoot (ScreenshotValues  *shootvals,
                       GdkScreen         *screen,
-                      gint32            *image_ID,
+                      GimpImage        **image,
                       GError           **error)
 {
   const gchar *mode    = " ";
@@ -139,9 +139,9 @@ screenshot_osx_shoot (ScreenshotValues  *shootvals,
       /* don't attach a profile, screencapture attached one
        */
 
-      *image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
-                                  filename, filename);
-      gimp_image_set_filename (*image_ID, "screenshot.png");
+      *image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
+                               filename, filename);
+      gimp_image_set_filename (*image, "screenshot.png");
 
       g_unlink (filename);
       g_free (filename);
diff --git a/plug-ins/screenshot/screenshot-osx.h b/plug-ins/screenshot/screenshot-osx.h
index 40a987505c..16636d17bf 100644
--- a/plug-ins/screenshot/screenshot-osx.h
+++ b/plug-ins/screenshot/screenshot-osx.h
@@ -27,7 +27,7 @@ ScreenshotCapabilities screenshot_osx_get_capabilities (void);
 
 GimpPDBStatusType      screenshot_osx_shoot            (ScreenshotValues  *shootvals,
                                                         GdkScreen         *screen,
-                                                        gint32            *image_ID,
+                                                        GimpImage        **image,
                                                         GError           **error);
 
 #endif /* PLATFORM_OSX */
diff --git a/plug-ins/screenshot/screenshot-win32.h b/plug-ins/screenshot/screenshot-win32.h
index 548393ac50..a30eb69b7c 100644
--- a/plug-ins/screenshot/screenshot-win32.h
+++ b/plug-ins/screenshot/screenshot-win32.h
@@ -35,7 +35,7 @@ ScreenshotCapabilities screenshot_win32_get_capabilities (void);
 
 GimpPDBStatusType      screenshot_win32_shoot            (ScreenshotValues  *shootvals,
                                                           GdkMonitor        *monitor,
-                                                          gint32            *image_ID,
+                                                          GimpImage        **image,
                                                           GError           **error);
 
 #endif /* G_OS_WIN32 */
diff --git a/plug-ins/screenshot/screenshot-x11.c b/plug-ins/screenshot/screenshot-x11.c
index 2f316d5037..b9495e2b8d 100644
--- a/plug-ins/screenshot/screenshot-x11.c
+++ b/plug-ins/screenshot/screenshot-x11.c
@@ -48,11 +48,11 @@
 #include "libgimp/stdplugins-intl.h"
 
 
-static guint32    select_window        (ScreenshotValues *shootvals,
-                                        GdkMonitor       *monitor);
-static gint32     create_image         (cairo_surface_t  *surface,
-                                        cairo_region_t   *shape,
-                                        const gchar      *name);
+static guint32     select_window        (ScreenshotValues *shootvals,
+                                         GdkMonitor       *monitor);
+static GimpImage * create_image         (cairo_surface_t  *surface,
+                                         cairo_region_t   *shape,
+                                         const gchar      *name);
 
 
 /* Allow the user to select a window or a region with the mouse */
@@ -375,7 +375,7 @@ window_get_shape (GdkMonitor *monitor,
 }
 
 static void
-image_select_shape (gint32          image,
+image_select_shape (GimpImage      *image,
                     cairo_region_t *shape)
 {
   gint num_rects;
@@ -402,13 +402,13 @@ image_select_shape (gint32          image,
 
 /* Create a GimpImage from a GdkPixbuf */
 
-static gint32
+static GimpImage *
 create_image (cairo_surface_t *surface,
               cairo_region_t  *shape,
               const gchar     *name)
 {
-  gint32     image;
-  gint32     layer;
+  GimpImage *image;
+  GimpLayer *layer;
   gdouble    xres, yres;
   gint       width, height;
 
@@ -427,7 +427,7 @@ create_image (cairo_surface_t *surface,
                                        name ? name : _("Screenshot"),
                                        surface,
                                        0.0, 1.0);
-  gimp_image_insert_layer (image, layer, -1, 0);
+  gimp_image_insert_layer (image, layer, NULL, 0);
 
   if (shape && ! cairo_region_is_empty (shape))
     {
@@ -436,7 +436,7 @@ create_image (cairo_surface_t *surface,
       if (! gimp_selection_is_empty (image))
         {
           gimp_layer_add_alpha (layer);
-          gimp_drawable_edit_clear (layer);
+          gimp_drawable_edit_clear (GIMP_DRAWABLE (layer));
           gimp_selection_none (image);
         }
     }
@@ -447,7 +447,7 @@ create_image (cairo_surface_t *surface,
 }
 
 static void
-add_cursor_image (gint32      image,
+add_cursor_image (GimpImage  *image,
                   GdkDisplay *display)
 {
 #ifdef HAVE_XFIXES
@@ -455,8 +455,8 @@ add_cursor_image (gint32      image,
   GeglBuffer         *buffer;
   GeglBufferIterator *iter;
   GeglRectangle      *roi;
-  gint32              layer;
-  gint32              active;
+  GimpLayer          *layer;
+  GimpLayer          *active;
 
   cursor = XFixesGetCursorImage (GDK_DISPLAY_XDISPLAY (display));
 
@@ -471,12 +471,12 @@ add_cursor_image (gint32      image,
                           100.0,
                           gimp_image_get_default_new_layer_mode (image));
 
-  buffer = gimp_drawable_get_buffer (layer);
+  buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
 
   iter = gegl_buffer_iterator_new (buffer,
                                    GEGL_RECTANGLE (0, 0,
-                                                   gimp_drawable_width  (layer),
-                                                   gimp_drawable_height (layer)),
+                                                   gimp_drawable_width  (GIMP_DRAWABLE (layer)),
+                                                   gimp_drawable_height (GIMP_DRAWABLE (layer))),
                                    0, babl_format ("R'G'B'A u8"),
                                    GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE, 1);
   roi = &iter->items[0].roi;
@@ -516,7 +516,7 @@ add_cursor_image (gint32      image,
 
   g_object_unref (buffer);
 
-  gimp_image_insert_layer (image, layer, -1, -1);
+  gimp_image_insert_layer (image, layer, NULL, -1);
   gimp_layer_set_offsets (layer,
                           cursor->x - cursor->xhot, cursor->y - cursor->yhot);
 
@@ -557,7 +557,7 @@ screenshot_x11_get_capabilities (void)
 GimpPDBStatusType
 screenshot_x11_shoot (ScreenshotValues  *shootvals,
                       GdkMonitor        *monitor,
-                      gint32            *image_ID,
+                      GimpImage        **image,
                       GError           **error)
 {
   GdkDisplay       *display;
@@ -667,7 +667,7 @@ screenshot_x11_shoot (ScreenshotValues  *shootvals,
         cairo_region_translate (shape, x - rect.x, y - rect.y);
     }
 
-  *image_ID = create_image (screenshot, shape, name);
+  *image = create_image (screenshot, shape, name);
 
   cairo_surface_destroy (screenshot);
 
@@ -681,13 +681,13 @@ screenshot_x11_shoot (ScreenshotValues  *shootvals,
    */
   if ((shootvals->shoot_type == SHOOT_ROOT ||
        shootvals->shoot_type == SHOOT_WINDOW) && shootvals->show_cursor)
-    add_cursor_image (*image_ID, display);
+    add_cursor_image (*image, display);
 
   profile = gimp_monitor_get_color_profile (monitor);
 
   if (profile)
     {
-      gimp_image_set_color_profile (*image_ID, profile);
+      gimp_image_set_color_profile (*image, profile);
       g_object_unref (profile);
     }
 
diff --git a/plug-ins/screenshot/screenshot-x11.h b/plug-ins/screenshot/screenshot-x11.h
index 94ad693e51..e8471cf5ab 100644
--- a/plug-ins/screenshot/screenshot-x11.h
+++ b/plug-ins/screenshot/screenshot-x11.h
@@ -27,7 +27,7 @@ ScreenshotCapabilities screenshot_x11_get_capabilities (void);
 
 GimpPDBStatusType      screenshot_x11_shoot            (ScreenshotValues  *shootvals,
                                                         GdkMonitor        *monitor,
-                                                        gint32            *image_ID,
+                                                        GimpImage        **image,
                                                         GError           **error);
 
 #endif /* GDK_WINDOWING_X11 */
diff --git a/plug-ins/screenshot/screenshot.c b/plug-ins/screenshot/screenshot.c
index 24c03b3228..f8516d62a2 100644
--- a/plug-ins/screenshot/screenshot.c
+++ b/plug-ins/screenshot/screenshot.c
@@ -80,7 +80,7 @@ static GimpValueArray * screenshot_run              (GimpProcedure        *proce
                                                      gpointer              run_data);
 
 static GimpPDBStatusType   shoot               (GdkMonitor       *monitor,
-                                                gint32           *image_ID,
+                                                GimpImage       **image,
                                                 GError          **error);
 
 static gboolean            shoot_dialog        (GdkMonitor      **monitor);
@@ -235,8 +235,8 @@ screenshot_run (GimpProcedure        *procedure,
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
   GimpRunMode        run_mode;
   GdkMonitor        *monitor = NULL;
-  gint32             image_ID;
-  GError            *error  = NULL;
+  GimpImage         *image   = NULL;
+  GError            *error   = NULL;
 
   INIT_I18N ();
   gegl_init (NULL, NULL);
@@ -344,7 +344,7 @@ screenshot_run (GimpProcedure        *procedure,
 
   if (status == GIMP_PDB_SUCCESS)
     {
-      status = shoot (monitor, &image_ID, &error);
+      status = shoot (monitor, &image, &error);
     }
 
   if (status == GIMP_PDB_SUCCESS)
@@ -355,7 +355,7 @@ screenshot_run (GimpProcedure        *procedure,
         {
           GimpColorProfile *srgb_profile = gimp_color_profile_new_rgb_srgb ();
 
-          gimp_image_convert_color_profile (image_ID,
+          gimp_image_convert_color_profile (image,
                                             srgb_profile,
                                             GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
                                             TRUE);
@@ -370,20 +370,20 @@ screenshot_run (GimpProcedure        *procedure,
                                         GIMP_PARASITE_PERSISTENT,
                                         strlen (comment) + 1, comment);
 
-          gimp_image_attach_parasite (image_ID, parasite);
+          gimp_image_attach_parasite (image, parasite);
           gimp_parasite_free (parasite);
 
           g_free (comment);
         }
 
-      gimp_image_clean_all (image_ID);
+      gimp_image_clean_all (image);
 
       if (run_mode == GIMP_RUN_INTERACTIVE)
         {
           /* Store variable states for next run */
           gimp_set_data (PLUG_IN_PROC, &shootvals, sizeof (ScreenshotValues));
 
-          gimp_display_new (image_ID);
+          gimp_display_new (image);
 
           /* Give some sort of feedback that the shot is done */
           if (shootvals.select_delay > 0)
@@ -398,7 +398,7 @@ screenshot_run (GimpProcedure        *procedure,
   return_vals = gimp_procedure_new_return_values (procedure, status, error);
 
   if (status == GIMP_PDB_SUCCESS)
-    GIMP_VALUES_SET_IMAGE (return_vals, 1, image_ID);
+    GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
 
   return return_vals;
 }
@@ -407,30 +407,30 @@ screenshot_run (GimpProcedure        *procedure,
 /* The main Screenshot function */
 
 static GimpPDBStatusType
-shoot (GdkMonitor *monitor,
-       gint32     *image_ID,
-       GError    **error)
+shoot (GdkMonitor  *monitor,
+       GimpImage  **image,
+       GError     **error)
 {
 #ifdef PLATFORM_OSX
   if (backend == SCREENSHOT_BACKEND_OSX)
-    return screenshot_osx_shoot (&shootvals, monitor, image_ID, error);
+    return screenshot_osx_shoot (&shootvals, monitor, image, error);
 #endif
 
 #ifdef G_OS_WIN32
   if (backend == SCREENSHOT_BACKEND_WIN32)
-    return screenshot_win32_shoot (&shootvals, monitor, image_ID, error);
+    return screenshot_win32_shoot (&shootvals, monitor, image, error);
 #endif
 
   if (backend == SCREENSHOT_BACKEND_FREEDESKTOP)
-    return screenshot_freedesktop_shoot (&shootvals, monitor, image_ID, error);
+    return screenshot_freedesktop_shoot (&shootvals, monitor, image, error);
   else if (backend == SCREENSHOT_BACKEND_GNOME_SHELL)
-    return screenshot_gnome_shell_shoot (&shootvals, monitor, image_ID, error);
+    return screenshot_gnome_shell_shoot (&shootvals, monitor, image, error);
   else if (backend == SCREENSHOT_BACKEND_KWIN)
-    return screenshot_kwin_shoot (&shootvals, monitor, image_ID, error);
+    return screenshot_kwin_shoot (&shootvals, monitor, image, error);
 
 #ifdef GDK_WINDOWING_X11
   if (backend == SCREENSHOT_BACKEND_X11)
-    return screenshot_x11_shoot (&shootvals, monitor, image_ID, error);
+    return screenshot_x11_shoot (&shootvals, monitor, image, error);
 #endif
 
   return GIMP_PDB_CALLING_ERROR; /* silence compiler */


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