[gimp/wip/Jehan/classy-GIMP: 12/17] libgimp: s/gimp_image_new_by_id()/gimp_image_get_by_id()/



commit fe5225c82206c144db8e141f3ac448b9a5a97669
Author: Jehan <jehan girinstud io>
Date:   Thu Aug 15 10:01:08 2019 +0200

    libgimp: s/gimp_image_new_by_id()/gimp_image_get_by_id()/
    
    This means that images' ownership is not given to caller in particular.
    libgimp will now keep a reference of all GimpImage-s it creates and
    return this same reference if called again. It also means that you can
    now compare images by pointer comparison (as 2 GimpImage objects
    representing the same image ID will be equal).
    Obviously as a side effect, gimp_image_list() is changed to (transfer
    container) as you must only free the container now, not the elements.
    Also various other functions creating new images are now (transfer none)
    too.
    
    Long-time plug-ins will have to be taken in consideration in a further
    step (we currently never free GimpImage for destroyed images in
    particular).

 libgimp/gimpaspectpreview.c     |   1 -
 libgimp/gimpchannel.c           |   5 +-
 libgimp/gimpdrawable.c          |   1 -
 libgimp/gimpdrawablepreview.c   |   3 -
 libgimp/gimpedit_pdb.c          |   8 +--
 libgimp/gimpexport.c            |  14 ++--
 libgimp/gimpfileops_pdb.c       |   4 +-
 libgimp/gimpimage.c             | 147 +++++++++++++++-------------------------
 libgimp/gimpimage.h             |   2 +-
 libgimp/gimpimage_pdb.c         |  12 ++--
 libgimp/gimpimagecolorprofile.c |  38 ++---------
 libgimp/gimpimagecombobox.c     |   8 +--
 libgimp/gimpimagemetadata.c     |  38 +++--------
 libgimp/gimpitem_pdb.c          |   4 +-
 libgimp/gimpitemcombobox.c      |   2 +-
 libgimp/gimplayer.c             |  15 ++--
 libgimp/gimpparamspecs.c        |   6 +-
 libgimp/gimpprocedure.c         |   6 +-
 libgimp/gimpselection.c         |   6 +-
 libgimp/gimpzoompreview.c       |   2 -
 pdb/pdb.pl                      |   4 +-
 plug-ins/common/checkerboard.c  |   4 +-
 plug-ins/common/grid.c          |   3 +-
 23 files changed, 110 insertions(+), 223 deletions(-)
---
diff --git a/libgimp/gimpaspectpreview.c b/libgimp/gimpaspectpreview.c
index 273dd343c0..f334b7246d 100644
--- a/libgimp/gimpaspectpreview.c
+++ b/libgimp/gimpaspectpreview.c
@@ -339,7 +339,6 @@ gimp_aspect_preview_draw_buffer (GimpPreview  *preview,
       g_free (sel);
       g_free (src);
     }
-  g_object_unref (image);
 }
 
 static void
diff --git a/libgimp/gimpchannel.c b/libgimp/gimpchannel.c
index b379e3576d..f68a66bc3a 100644
--- a/libgimp/gimpchannel.c
+++ b/libgimp/gimpchannel.c
@@ -111,15 +111,14 @@ gimp_channel_new_deprecated (gint32         image_id,
                              gdouble        opacity,
                              const GimpRGB *color)
 {
-  GimpImage   *image = gimp_image_new_by_id (image_id);
   GimpChannel *channel;
   gint32       channel_id;
 
-  channel = gimp_channel_new (image, name, width, height,
+  channel = gimp_channel_new (gimp_image_get_by_id (image_id),
+                              name, width, height,
                               opacity, color);
   channel_id = gimp_item_get_id (GIMP_ITEM (channel));
 
-  g_object_unref (image);
   g_object_unref (channel);
 
   return channel_id;
diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c
index da86c2b9b0..bdf0c8c006 100644
--- a/libgimp/gimpdrawable.c
+++ b/libgimp/gimpdrawable.c
@@ -347,7 +347,6 @@ gimp_drawable_get_format (GimpDrawable *drawable)
           format = babl_format_with_space (format_str, space);
         }
 
-      g_object_unref (image);
       g_free (format_str);
     }
 
diff --git a/libgimp/gimpdrawablepreview.c b/libgimp/gimpdrawablepreview.c
index dde86cc3a7..efced0f072 100644
--- a/libgimp/gimpdrawablepreview.c
+++ b/libgimp/gimpdrawablepreview.c
@@ -485,7 +485,6 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
             default:
               g_free (sel);
               g_free (src);
-              g_object_unref (image);
               return;
             }
 
@@ -506,7 +505,6 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
           g_free (src);
         }
     }
-  g_object_unref (image);
 }
 
 static void
@@ -552,7 +550,6 @@ gimp_drawable_preview_set_drawable (GimpDrawablePreview *drawable_preview,
       cmap = gimp_image_get_colormap (image, &num_colors);
       gimp_preview_area_set_colormap (GIMP_PREVIEW_AREA (area),
                                       cmap, num_colors);
-      g_object_unref (image);
       g_free (cmap);
     }
 }
diff --git a/libgimp/gimpedit_pdb.c b/libgimp/gimpedit_pdb.c
index db17527177..61a280dd03 100644
--- a/libgimp/gimpedit_pdb.c
+++ b/libgimp/gimpedit_pdb.c
@@ -432,7 +432,7 @@ _gimp_edit_paste (gint32   drawable_ID,
  * previously made to either gimp_edit_cut() or gimp_edit_copy(). This
  * procedure returns the new image or -1 if the edit buffer was empty.
  *
- * Returns: (transfer full): The new image.
+ * Returns: (transfer none): The new image.
  *
  * Since: 2.10
  **/
@@ -457,7 +457,7 @@ gimp_edit_paste_as_new_image (void)
   gimp_value_array_unref (args);
 
   if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS)
-    image = gimp_image_new_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
+    image = gimp_image_get_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
 
   gimp_value_array_unref (return_vals);
 
@@ -902,7 +902,7 @@ _gimp_edit_named_paste (gint32       drawable_ID,
  * This procedure works like gimp_edit_paste_as_new_image() but pastes
  * a named buffer instead of the global buffer.
  *
- * Returns: (transfer full): The new image.
+ * Returns: (transfer none): The new image.
  *
  * Since: 2.10
  **/
@@ -928,7 +928,7 @@ gimp_edit_named_paste_as_new_image (const gchar *buffer_name)
   gimp_value_array_unref (args);
 
   if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS)
-    image = gimp_image_new_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
+    image = gimp_image_get_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
 
   gimp_value_array_unref (return_vals);
 
diff --git a/libgimp/gimpexport.c b/libgimp/gimpexport.c
index 02ae7b4483..82737a3e27 100644
--- a/libgimp/gimpexport.c
+++ b/libgimp/gimpexport.c
@@ -1147,28 +1147,22 @@ gimp_export_image_deprecated (gint32                 *image_ID,
                               GimpExportCapabilities  capabilities)
 {
   GimpImage        *image;
-  GimpImage        *new_image;
   GimpDrawable     *drawable;
   GimpDrawable     *new_drawable;
   GimpExportReturn  retval;
 
-  image        = gimp_image_new_by_id (*image_ID);
-  new_image    = image;
+  image        = gimp_image_get_by_id (*image_ID);
   drawable     = GIMP_DRAWABLE (gimp_item_new_by_id (*drawable_ID));
   new_drawable = drawable;
 
-  retval = gimp_export_image (&new_image, &new_drawable,
+  retval = gimp_export_image (&image, &new_drawable,
                               format_name, capabilities);
 
-  *image_ID    = gimp_image_get_id (new_image);
+  *image_ID    = gimp_image_get_id (image);
   *drawable_ID = gimp_item_get_id (GIMP_ITEM (new_drawable));
   if (retval == GIMP_EXPORT_EXPORT)
-    {
-      g_object_unref (new_image);
-      g_object_unref (new_drawable);
-    }
+    g_object_unref (new_drawable);
 
-  g_object_unref (image);
   g_object_unref (drawable);
 
   return retval;
diff --git a/libgimp/gimpfileops_pdb.c b/libgimp/gimpfileops_pdb.c
index 0d182a47e9..da53b161bf 100644
--- a/libgimp/gimpfileops_pdb.c
+++ b/libgimp/gimpfileops_pdb.c
@@ -50,7 +50,7 @@
  * https://www.gimp.org/foo.png he wants to fetch a URL, and the full
  * pathname will not look like a URL.
  *
- * Returns: (transfer full): The output image.
+ * Returns: (transfer none): The output image.
  **/
 GimpImage *
 gimp_file_load (GimpRunMode  run_mode,
@@ -78,7 +78,7 @@ gimp_file_load (GimpRunMode  run_mode,
   gimp_value_array_unref (args);
 
   if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS)
-    image = gimp_image_new_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
+    image = gimp_image_get_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
 
   gimp_value_array_unref (return_vals);
 
diff --git a/libgimp/gimpimage.c b/libgimp/gimpimage.c
index fc658a4d9f..52abdb858a 100644
--- a/libgimp/gimpimage.c
+++ b/libgimp/gimpimage.c
@@ -36,6 +36,9 @@ struct _GimpImagePrivate
   gint id;
 };
 
+static GHashTable *gimp_images = NULL;
+
+
 static void       gimp_image_set_property  (GObject      *object,
                                             guint         property_id,
                                             const GValue *value,
@@ -131,29 +134,49 @@ gimp_image_get_property (GObject    *object,
 gint32
 gimp_image_get_id (GimpImage *image)
 {
-  return image->priv->id;
+  return image ? image->priv->id : -1;
 }
 
 /**
- * gimp_image_new_by_id:
+ * gimp_image_get_by_id:
  * @image_id: The image id.
  *
- * Returns: (nullable) (transfer full): a #GimpImage for @image_id or
+ * Returns: (nullable) (transfer none): a #GimpImage for @image_id or
  *          %NULL if @image_id does not represent a valid image.
+ *          The object belongs to libgimp and you should not free it.
  *
  * Since: 3.0
  **/
 GimpImage *
-gimp_image_new_by_id (gint32 image_id)
+gimp_image_get_by_id (gint32 image_id)
 {
-  GimpImage *image;
+  GimpImage *image = NULL;
 
-  image = g_object_new (GIMP_TYPE_IMAGE,
-                        "id", image_id,
-                        NULL);
+  if (G_UNLIKELY (! gimp_images))
+    gimp_images = g_hash_table_new_full (g_direct_hash,
+                                         g_direct_equal,
+                                         NULL,
+                                         (GDestroyNotify) g_object_unref);
 
-  if (! gimp_image_is_valid (image))
-    g_clear_object (&image);
+  if (! _gimp_image_is_valid (image_id))
+    {
+      g_hash_table_remove (gimp_images, GINT_TO_POINTER (image_id));
+    }
+  else
+    {
+      image = g_hash_table_lookup (gimp_images,
+                                   GINT_TO_POINTER (image_id));
+
+      if (! image)
+        {
+          image = g_object_new (GIMP_TYPE_IMAGE,
+                                "id", image_id,
+                                NULL);
+          g_hash_table_insert (gimp_images,
+                               GINT_TO_POINTER (image_id),
+                               image);
+        }
+    }
 
   return image;
 }
@@ -165,10 +188,10 @@ gimp_image_new_by_id (gint32 image_id)
  *
  * This procedure returns the list of images currently open in GIMP.
  *
- * Returns: (element-type GimpImage) (transfer full):
+ * Returns: (element-type GimpImage) (transfer container):
  *          The list of images currently open.
- *          The returned value must be freed with:
- *          g_list_free_full(list, g_object_unref);
+ *          The returned value must be freed with g_list_free(). Image
+ *          elements belong to libgimp and must not be freed.
  **/
 GList *
 gimp_image_list (void)
@@ -180,13 +203,8 @@ gimp_image_list (void)
 
   ids = _gimp_image_list (&num_images);
   for (i = 0; i < num_images; i++)
-    {
-      GimpImage *image;
-
-      image = gimp_image_new_by_id (ids[i]);
-
-      images = g_list_prepend (images, image);
-    }
+    images = g_list_prepend (images,
+                             gimp_image_get_by_id (ids[i]));
   images = g_list_reverse (images);
   g_free (ids);
 
@@ -547,14 +565,8 @@ gint *
 gimp_image_get_layers_deprecated (gint32  image_id,
                                   gint   *num_layers)
 {
-  GimpImage *image;
-  gint      *layers;
-
-  image  = gimp_image_new_by_id (image_id);
-  layers = _gimp_image_get_layers (image, num_layers);
-  g_object_unref (image);
-
-  return layers;
+  return _gimp_image_get_layers (gimp_image_get_by_id (image_id),
+                                   num_layers);
 }
 
 /**
@@ -578,14 +590,8 @@ gint *
 gimp_image_get_channels_deprecated (gint32  image_id,
                                     gint   *num_channels)
 {
-  GimpImage *image;
-  gint      *channels;
-
-  image    = gimp_image_new_by_id (image_id);
-  channels = _gimp_image_get_layers (image, num_channels);
-  g_object_unref (image);
-
-  return channels;
+  return _gimp_image_get_layers (gimp_image_get_by_id (image_id),
+                                 num_channels);
 }
 
 /**
@@ -608,14 +614,8 @@ gint *
 gimp_image_get_vectors_deprecated (gint32  image_id,
                                    gint   *num_vectors)
 {
-  GimpImage *image;
-  gint      *vectors;
-
-  image   = gimp_image_new_by_id (image_id);
-  vectors = _gimp_image_get_vectors (image, num_vectors);
-  g_object_unref (image);
-
-  return vectors;
+  return _gimp_image_get_vectors (gimp_image_get_by_id (image_id),
+                                  num_vectors);
 }
 
 /**
@@ -635,14 +635,8 @@ guchar *
 gimp_image_get_colormap_deprecated (gint32  image_id,
                                     gint   *num_colors)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  guchar    *colormap;
-
-  colormap = gimp_image_get_colormap (image, num_colors);
-
-  g_object_unref (image);
-
-  return colormap;
+  return gimp_image_get_colormap (gimp_image_get_by_id (image_id),
+                                  num_colors);
 }
 
 /**
@@ -665,14 +659,8 @@ gimp_image_set_colormap_deprecated (gint32        image_id,
                                     const guchar *colormap,
                                     gint          num_colors)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  gboolean   success;
-
-  success = gimp_image_set_colormap (image, colormap, num_colors);
-
-  g_object_unref (image);
-
-  return success;
+  return gimp_image_set_colormap (gimp_image_get_by_id (image_id),
+                                  colormap, num_colors);
 }
 
 /**
@@ -697,14 +685,8 @@ gimp_image_get_thumbnail_data_deprecated (gint32  image_id,
                                           gint   *height,
                                           gint   *bpp)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  guchar    *thumbdata;
-
-  thumbdata = gimp_image_get_thumbnail_data (image, width, height, bpp);
-
-  g_object_unref (image);
-
-  return thumbdata;
+  return gimp_image_get_thumbnail_data (gimp_image_get_by_id (image_id),
+                                        width, height, bpp);
 }
 
 /**
@@ -727,14 +709,8 @@ gimp_image_get_thumbnail_deprecated (gint32                 image_id,
                                      gint                   height,
                                      GimpPixbufTransparency alpha)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  GdkPixbuf *thumbnail;
-
-  thumbnail = gimp_image_get_thumbnail (image, width, height, alpha);
-
-  g_object_unref (image);
-
-  return thumbnail;
+  return gimp_image_get_thumbnail (gimp_image_get_by_id (image_id),
+                                   width, height, alpha);
 }
 
 /**
@@ -753,14 +729,7 @@ gimp_image_get_thumbnail_deprecated (gint32                 image_id,
 GimpMetadata *
 gimp_image_get_metadata_deprecated (gint32 image_id)
 {
-  GimpImage    *image = gimp_image_new_by_id (image_id);
-  GimpMetadata *metadata;
-
-  metadata = gimp_image_get_metadata (image);
-
-  g_object_unref (image);
-
-  return metadata;
+  return gimp_image_get_metadata (gimp_image_get_by_id (image_id));
 }
 
 /**
@@ -781,12 +750,6 @@ gboolean
 gimp_image_set_metadata_deprecated (gint32        image_id,
                                     GimpMetadata *metadata)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  gboolean   success;
-
-  success = gimp_image_set_metadata (image, metadata);
-
-  g_object_unref (image);
-
-  return success;
+  return gimp_image_set_metadata (gimp_image_get_by_id (image_id),
+                                  metadata);
 }
diff --git a/libgimp/gimpimage.h b/libgimp/gimpimage.h
index beef38c043..d63c5a4f74 100644
--- a/libgimp/gimpimage.h
+++ b/libgimp/gimpimage.h
@@ -66,7 +66,7 @@ struct _GimpImageClass
 GType          gimp_image_get_type           (void) G_GNUC_CONST;
 
 gint32         gimp_image_get_id             (GimpImage    *image);
-GimpImage    * gimp_image_new_by_id          (gint32        image_id);
+GimpImage    * gimp_image_get_by_id          (gint32        image_id);
 
 GList        * gimp_image_list               (void);
 
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index 8f59ab463c..ed2091b8d0 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -183,7 +183,7 @@ _gimp_image_list (gint *num_images)
  * gimp_image_set_colormap(). An indexed image without a colormap will
  * output unexpected colors.
  *
- * Returns: (transfer full): The newly created image.
+ * Returns: (transfer none): The newly created image.
  **/
 GimpImage *
 gimp_image_new (gint              width,
@@ -211,7 +211,7 @@ gimp_image_new (gint              width,
   gimp_value_array_unref (args);
 
   if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS)
-    image = gimp_image_new_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
+    image = gimp_image_get_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
 
   gimp_value_array_unref (return_vals);
 
@@ -287,7 +287,7 @@ _gimp_image_new (gint              width,
  * GIMP_PRECISION_U8_NON_LINEAR precision. See gimp_image_new() for
  * further details.
  *
- * Returns: (transfer full): The newly created image.
+ * Returns: (transfer none): The newly created image.
  *
  * Since: 2.10
  **/
@@ -319,7 +319,7 @@ gimp_image_new_with_precision (gint              width,
   gimp_value_array_unref (args);
 
   if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS)
-    image = gimp_image_new_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
+    image = gimp_image_get_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
 
   gimp_value_array_unref (return_vals);
 
@@ -389,7 +389,7 @@ _gimp_image_new_with_precision (gint              width,
  * This procedure duplicates the specified image, copying all layers,
  * channels, and image information.
  *
- * Returns: (transfer full): The new, duplicated image.
+ * Returns: (transfer none): The new, duplicated image.
  **/
 GimpImage *
 gimp_image_duplicate (GimpImage *image)
@@ -413,7 +413,7 @@ gimp_image_duplicate (GimpImage *image)
   gimp_value_array_unref (args);
 
   if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS)
-    new_image = gimp_image_new_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
+    new_image = gimp_image_get_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
 
   gimp_value_array_unref (return_vals);
 
diff --git a/libgimp/gimpimagecolorprofile.c b/libgimp/gimpimagecolorprofile.c
index 68d9e44b42..5a54b46c34 100644
--- a/libgimp/gimpimagecolorprofile.c
+++ b/libgimp/gimpimagecolorprofile.c
@@ -191,14 +191,7 @@ gimp_image_convert_color_profile (GimpImage                 *image,
 GimpColorProfile *
 gimp_image_get_color_profile_deprecated (gint32 image_id)
 {
-  GimpImage        *image = gimp_image_new_by_id (image_id);
-  GimpColorProfile *profile;
-
-  profile = gimp_image_get_color_profile (image);
-
-  g_object_unref (image);
-
-  return profile;
+  return gimp_image_get_color_profile (gimp_image_get_by_id (image_id));
 }
 
 /**
@@ -216,14 +209,8 @@ gboolean
 gimp_image_set_color_profile_deprecated (gint32            image_id,
                                          GimpColorProfile *profile)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  gboolean   success;
-
-  success = gimp_image_set_color_profile (image, profile);
-
-  g_object_unref (image);
-
-  return success;
+  return gimp_image_set_color_profile (gimp_image_get_by_id (image_id),
+                                       profile);
 }
 
 /**
@@ -245,14 +232,7 @@ gimp_image_set_color_profile_deprecated (gint32            image_id,
 GimpColorProfile *
 gimp_image_get_effective_color_profile_deprecated (gint32 image_id)
 {
-  GimpImage        *image = gimp_image_new_by_id (image_id);
-  GimpColorProfile *profile;
-
-  profile = gimp_image_get_effective_color_profile (image);
-
-  g_object_unref (image);
-
-  return profile;
+  return gimp_image_get_effective_color_profile (gimp_image_get_by_id (image_id));
 }
 
 /**
@@ -276,12 +256,6 @@ gimp_image_convert_color_profile_deprecated (gint32                    image_id,
                                              GimpColorRenderingIntent  intent,
                                              gboolean                  bpc)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  gboolean   success;
-
-  success = gimp_image_convert_color_profile (image, profile, intent, bpc);
-
-  g_object_unref (image);
-
-  return success;
+  return gimp_image_convert_color_profile (gimp_image_get_by_id (image_id),
+                                           profile, intent, bpc);
 }
diff --git a/libgimp/gimpimagecombobox.c b/libgimp/gimpimagecombobox.c
index 5beefcc613..246d5b4915 100644
--- a/libgimp/gimpimagecombobox.c
+++ b/libgimp/gimpimagecombobox.c
@@ -191,7 +191,7 @@ gimp_image_combo_box_populate (GimpImageComboBox *combo_box)
                                   combo_box->constraint_d,
                                   combo_box->data);
 
-  g_list_free_full (images, g_object_unref);
+  g_list_free (images);
 
   if (gtk_tree_model_get_iter_first (model, &iter))
     gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
@@ -288,10 +288,7 @@ gimp_image_combo_box_changed (GimpImageComboBox *combo_box)
   if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo_box),
                                      &image_ID))
     {
-      GimpImage *image;
-
-      image = gimp_image_new_by_id (image_ID);
-      if (! gimp_image_is_valid (image))
+      if (! _gimp_image_is_valid (image_ID))
         {
           GtkTreeModel *model;
 
@@ -302,7 +299,6 @@ gimp_image_combo_box_changed (GimpImageComboBox *combo_box)
           gtk_list_store_clear (GTK_LIST_STORE (model));
           gimp_image_combo_box_populate (combo_box);
         }
-      g_object_unref (image);
     }
 }
 
diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c
index c4758f66d3..f6bfc9b11d 100644
--- a/libgimp/gimpimagemetadata.c
+++ b/libgimp/gimpimagemetadata.c
@@ -1059,14 +1059,8 @@ gimp_image_metadata_load_prepare_deprecated (gint32        image_id,
                                              GFile        *file,
                                              GError      **error)
 {
-  GimpImage    *image = gimp_image_new_by_id (image_id);
-  GimpMetadata *metadata;
-
-  metadata = gimp_image_metadata_load_prepare (image, mime_type, file, error);
-
-  g_object_unref (image);
-
-  return metadata;
+  return gimp_image_metadata_load_prepare (gimp_image_get_by_id (image_id),
+                                           mime_type, file, error);
 }
 
 /**
@@ -1090,10 +1084,8 @@ gimp_image_metadata_load_finish_deprecated (gint32                 image_id,
                                             GimpMetadataLoadFlags  flags,
                                             gboolean               interactive)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-
-  gimp_image_metadata_load_finish (image, mime_type, metadata, flags, interactive);
-  g_object_unref (image);
+  gimp_image_metadata_load_finish (gimp_image_get_by_id (image_id),
+                                   mime_type, metadata, flags, interactive);
 }
 
 /**
@@ -1127,14 +1119,8 @@ gimp_image_metadata_save_prepare_deprecated (gint32                 image_id,
                                              const gchar           *mime_type,
                                              GimpMetadataSaveFlags *suggested_flags)
 {
-  GimpImage    *image = gimp_image_new_by_id (image_id);
-  GimpMetadata *metadata;
-
-  metadata = gimp_image_metadata_save_prepare (image, mime_type, suggested_flags);
-
-  g_object_unref (image);
-
-  return metadata;
+  return gimp_image_metadata_save_prepare (gimp_image_get_by_id (image_id),
+                                           mime_type, suggested_flags);
 }
 
 /**
@@ -1162,15 +1148,9 @@ gimp_image_metadata_save_finish_deprecated (gint32                  image_id,
                                             GFile                  *file,
                                             GError                **error)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  gboolean   success;
-
-  success = gimp_image_metadata_save_finish (image, mime_type, metadata,
-                                             flags, file, error);
-
-  g_object_unref (image);
-
-  return success;
+  return gimp_image_metadata_save_finish (gimp_image_get_by_id (image_id),
+                                          mime_type, metadata,
+                                          flags, file, error);
 }
 
 /**
diff --git a/libgimp/gimpitem_pdb.c b/libgimp/gimpitem_pdb.c
index c9d698bca2..4cca121b79 100644
--- a/libgimp/gimpitem_pdb.c
+++ b/libgimp/gimpitem_pdb.c
@@ -126,7 +126,7 @@ _gimp_item_is_valid (gint32 item_ID)
  *
  * This procedure returns the item's image.
  *
- * Returns: (transfer full): The item's image.
+ * Returns: (transfer none): The item's image.
  *
  * Since: 2.8
  **/
@@ -152,7 +152,7 @@ gimp_item_get_image (GimpItem *item)
   gimp_value_array_unref (args);
 
   if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS)
-    image = gimp_image_new_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
+    image = gimp_image_get_by_id (gimp_value_get_image_id (gimp_value_array_index (return_vals, 1)));
 
   gimp_value_array_unref (return_vals);
 
diff --git a/libgimp/gimpitemcombobox.c b/libgimp/gimpitemcombobox.c
index 397a040d67..5ccaa80a0a 100644
--- a/libgimp/gimpitemcombobox.c
+++ b/libgimp/gimpitemcombobox.c
@@ -427,7 +427,7 @@ gimp_item_combo_box_populate (GimpIntComboBox *combo_box)
         }
     }
 
-  g_list_free_full (images, g_object_unref);
+  g_list_free (images);
 
   if (gtk_tree_model_get_iter_first (model, &iter))
     gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
diff --git a/libgimp/gimplayer.c b/libgimp/gimplayer.c
index f9f6a49dc4..7f31d111da 100644
--- a/libgimp/gimplayer.c
+++ b/libgimp/gimplayer.c
@@ -297,15 +297,14 @@ gimp_layer_new_deprecated (gint32         image_id,
                            gdouble        opacity,
                            GimpLayerMode  mode)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
   GimpLayer *layer;
   gint32     layer_id;
 
-  layer = gimp_layer_new (image, name, width, height,
+  layer = gimp_layer_new (gimp_image_get_by_id (image_id),
+                          name, width, height,
                           type, opacity, mode);
   layer_id = gimp_item_get_id (GIMP_ITEM (layer));
 
-  g_object_unref (image);
   g_object_unref (layer);
 
   return layer_id;
@@ -344,15 +343,14 @@ gimp_layer_new_from_pixbuf_deprecated (gint32         image_id,
                                        gdouble        progress_start,
                                        gdouble        progress_end)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
   GimpLayer *layer;
   gint32     layer_id;
 
-  layer = gimp_layer_new_from_pixbuf (image, name, pixbuf, opacity, mode,
+  layer = gimp_layer_new_from_pixbuf (gimp_image_get_by_id (image_id),
+                                      name, pixbuf, opacity, mode,
                                       progress_start, progress_end);
   layer_id = gimp_item_get_id (GIMP_ITEM (layer));
 
-  g_object_unref (image);
   g_object_unref (layer);
 
   return layer_id;
@@ -387,15 +385,14 @@ gimp_layer_new_from_surface_deprecated (gint32                image_id,
                                         gdouble               progress_start,
                                         gdouble               progress_end)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
   GimpLayer *layer;
   gint32     layer_id;
 
-  layer = gimp_layer_new_from_surface (image, name, surface,
+  layer = gimp_layer_new_from_surface (gimp_image_get_by_id (image_id),
+                                       name, surface,
                                        progress_start, progress_end);
   layer_id = gimp_item_get_id (GIMP_ITEM (layer));
 
-  g_object_unref (image);
   g_object_unref (layer);
 
   return layer_id;
diff --git a/libgimp/gimpparamspecs.c b/libgimp/gimpparamspecs.c
index 7252e11ea8..de792f0504 100644
--- a/libgimp/gimpparamspecs.c
+++ b/libgimp/gimpparamspecs.c
@@ -116,20 +116,16 @@ gimp_param_image_id_validate (GParamSpec *pspec,
                               GValue     *value)
 {
   GimpParamSpecImageID *ispec    = GIMP_PARAM_SPEC_IMAGE_ID (pspec);
-  GimpImage            *image;
   gint                  image_id = value->data[0].v_int;
 
   if (ispec->none_ok && (image_id == 0 || image_id == -1))
     return FALSE;
 
-  image = gimp_image_new_by_id (image_id);
-  if (! gimp_image_is_valid (image))
+  if (! _gimp_image_is_valid (image_id))
     {
       value->data[0].v_int = -1;
-      g_object_unref (image);
       return TRUE;
     }
-  g_object_unref (image);
 
   return FALSE;
 }
diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c
index 7591d0775a..4b91a4bcfb 100644
--- a/libgimp/gimpprocedure.c
+++ b/libgimp/gimpprocedure.c
@@ -1431,11 +1431,11 @@ gimp_procedure_validate_args (GimpProcedure   *procedure,
       if (arg_type == GIMP_TYPE_IMAGE_ID &&
           spec_type == GIMP_TYPE_IMAGE)
         {
-          GValue     value = G_VALUE_INIT;
-          GimpImage *image = gimp_image_new_by_id (g_value_get_int (arg));
+          GValue value = G_VALUE_INIT;
 
           g_value_init (&value, GIMP_TYPE_IMAGE);
-          g_value_take_object (&value, image);
+          g_value_set_object (&value,
+                              gimp_image_get_by_id (g_value_get_int (arg)));
           gimp_value_array_remove (args, i);
           gimp_value_array_insert (args, i, &value);
           g_value_unset (&value);
diff --git a/libgimp/gimpselection.c b/libgimp/gimpselection.c
index b5c0bb4c31..db5fa11993 100644
--- a/libgimp/gimpselection.c
+++ b/libgimp/gimpselection.c
@@ -93,21 +93,19 @@ gimp_selection_float_deprecated (gint32 image_ID,
                                  gint   offx,
                                  gint   offy)
 {
-  GimpImage    *image;
   GimpDrawable *drawable;
   GimpLayer    *selection;
   gint32        selection_id = -1;
 
-  image    = gimp_image_new_by_id (image_ID);
   drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
-  selection = gimp_selection_float (image, drawable,
+  selection = gimp_selection_float (gimp_image_get_by_id (image_ID),
+                                    drawable,
                                     offx,
                                     offy);
   if (selection)
     selection_id = gimp_item_get_id (GIMP_ITEM (selection));
 
-  g_object_unref (image);
   g_object_unref (drawable);
   g_object_unref (selection);
 
diff --git a/libgimp/gimpzoompreview.c b/libgimp/gimpzoompreview.c
index 038d502988..82f489b9f1 100644
--- a/libgimp/gimpzoompreview.c
+++ b/libgimp/gimpzoompreview.c
@@ -559,8 +559,6 @@ gimp_zoom_preview_draw_buffer (GimpPreview  *preview,
       g_free (sel);
       g_free (src);
     }
-
-  g_object_unref (image);
 }
 
 static void
diff --git a/pdb/pdb.pl b/pdb/pdb.pl
index 005b75dfcc..08af331f1c 100644
--- a/pdb/pdb.pl
+++ b/pdb/pdb.pl
@@ -170,9 +170,9 @@ package Gimp::CodeGen::pdb;
                     const_type      => 'GimpImage *',
                     id              => 1,
                     init_value      => 'NULL',
-                    out_annotate    => '(transfer full)',
+                    out_annotate    => '(transfer none)',
                     get_value_func  => '$var = gimp_value_get_image ($value, gimp)',
-                    dup_value_func  => '$var = gimp_image_new_by_id (gimp_value_get_image_id ($value))',
+                    dup_value_func  => '$var = gimp_image_get_by_id (gimp_value_get_image_id ($value))',
                     dup_value_func_d=> '$var = gimp_value_get_image_id ($value)',
                     set_value_func  => 'gimp_value_set_image_id ($value, gimp_image_get_id ($var))',
                     take_value_func => 'gimp_value_set_image ($value, $var)',
diff --git a/plug-ins/common/checkerboard.c b/plug-ins/common/checkerboard.c
index 7797f5f40d..15ad2f714e 100644
--- a/plug-ins/common/checkerboard.c
+++ b/plug-ins/common/checkerboard.c
@@ -129,7 +129,7 @@ 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);
+  image       = gimp_image_get_by_id (image_ID);
   drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
   switch (run_mode)
@@ -138,7 +138,6 @@ run (const gchar      *name,
       gimp_get_data (PLUG_IN_PROC, &cvals);
       if (! checkerboard_dialog (image, drawable))
         {
-          g_object_unref (image);
           g_object_unref (drawable);
           return;
         }
@@ -179,7 +178,6 @@ run (const gchar      *name,
     }
 
   g_object_unref (drawable);
-  g_object_unref (image);
   values[0].data.d_status = status;
 }
 
diff --git a/plug-ins/common/grid.c b/plug-ins/common/grid.c
index 66a0fde98e..875625a623 100644
--- a/plug-ins/common/grid.c
+++ b/plug-ins/common/grid.c
@@ -178,7 +178,7 @@ 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);
+  image       = gimp_image_get_by_id (image_ID);
   drawable    = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
 
   if (run_mode == GIMP_RUN_NONINTERACTIVE)
@@ -254,7 +254,6 @@ 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;


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