[gimp/goat-invasion] libgimp: make GimpTileBackendPlugin properly private, and some cleanup



commit 5bf8d19baa96ca82add828dd2602ca64ed0ea084
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 22 11:24:03 2012 +0100

    libgimp: make GimpTileBackendPlugin properly private, and some cleanup

 libgimp/gimp.def                |    2 +
 libgimp/gimpdrawable.c          |   79 +++++++++++++++++++++++++++++++--------
 libgimp/gimpdrawable.h          |    1 -
 libgimp/gimptilebackendplugin.c |   44 +++++++++++----------
 libgimp/gimptilebackendplugin.h |    9 ++--
 libgimp/gimptypes.h             |   17 ++++----
 6 files changed, 101 insertions(+), 51 deletions(-)
---
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 1902cfb..6cc2416 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -176,6 +176,8 @@ EXPORTS
 	gimp_drawable_foreground_extract
 	gimp_drawable_free_shadow
 	gimp_drawable_get
+	gimp_drawable_get_buffer
+	gimp_drawable_get_shadow_buffer
 	gimp_drawable_get_color_uchar
 	gimp_drawable_get_image
 	gimp_drawable_get_linked
diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c
index df3162e..bddfd0c 100644
--- a/libgimp/gimpdrawable.c
+++ b/libgimp/gimpdrawable.c
@@ -25,6 +25,7 @@
 
 #include "gimptilebackendplugin.h"
 
+
 #define TILE_WIDTH  gimp_tile_width()
 #define TILE_HEIGHT gimp_tile_height()
 
@@ -647,30 +648,76 @@ gimp_drawable_attach_new_parasite (gint32          drawable_ID,
   return success;
 }
 
-
+/**
+ * gimp_drawable_get_buffer:
+ * @drawable_ID: the ID of the #GimpDrawableto  get the buffer for.
+ *
+ * Returns a #GeglBuffer of a specified drawable. The buffer can be used
+ * like any other GEGL buffer. Its data will we synced back with the core
+ * drawable when the buffer gets destroyed, or when gegl_buffer_flush()
+ * is called.
+ *
+ * Return value: The #GeglBuffer.
+ *
+ * See Also: gimp_drawable_get_shadow_buffer()
+ *
+ * Since: GIMP 2.10
+ */
 GeglBuffer *
 gimp_drawable_get_buffer (gint32 drawable_ID)
 {
-  GeglBuffer      *buffer;
-  GimpDrawable    *drawable;
-  GeglTileBackend *backend;
+  GimpDrawable *drawable;
+
   drawable = gimp_drawable_get (drawable_ID);
-  backend = gimp_tile_backend_plugin_new (drawable, FALSE);
-  buffer = gegl_buffer_new_for_backend (NULL, backend);
-  g_object_unref (backend);
-  return buffer;
-}
 
+  if (drawable)
+    {
+      GeglTileBackend *backend;
+      GeglBuffer      *buffer;
+
+      backend = _gimp_tile_backend_plugin_new (drawable, FALSE);
+      buffer = gegl_buffer_new_for_backend (NULL, backend);
+      g_object_unref (backend);
+
+      return buffer;
+    }
 
+  return NULL;
+}
+
+/**
+ * gimp_drawable_get_shadow_buffer:
+ * @drawable_ID: the ID of the #GimpDrawableto get the buffer for.
+ *
+ * Returns a #GeglBuffer of a specified drawable's shadow tiles. The
+ * buffer can be used like any other GEGL buffer. Its data will we
+ * synced back with the core drawable's shadow tiles when the buffer
+ * gets destroyed, or when gegl_buffer_flush() is called.
+ *
+ * Return value: The #GeglBuffer.
+ *
+ * See Also: gimp_drawable_get_shadow_buffer()
+ *
+ * Since: GIMP 2.10
+ */
 GeglBuffer *
 gimp_drawable_get_shadow_buffer (gint32 drawable_ID)
 {
-  GeglBuffer      *buffer;
-  GimpDrawable    *drawable;
-  GeglTileBackend *backend;
+  GimpDrawable *drawable;
+
   drawable = gimp_drawable_get (drawable_ID);
-  backend = gimp_tile_backend_plugin_new (drawable, TRUE);
-  buffer = gegl_buffer_new_for_backend (NULL, backend);
-  g_object_unref (backend);
-  return buffer;
+
+  if (drawable)
+    {
+      GeglTileBackend *backend;
+      GeglBuffer      *buffer;
+
+      backend = _gimp_tile_backend_plugin_new (drawable, TRUE);
+      buffer = gegl_buffer_new_for_backend (NULL, backend);
+      g_object_unref (backend);
+
+      return buffer;
+    }
+
+  return NULL;
 }
diff --git a/libgimp/gimpdrawable.h b/libgimp/gimpdrawable.h
index c2fb6ef..3df1fc2 100644
--- a/libgimp/gimpdrawable.h
+++ b/libgimp/gimpdrawable.h
@@ -45,7 +45,6 @@ struct _GimpDrawable
 GeglBuffer   * gimp_drawable_get_buffer             (gint32         drawable_ID);
 GeglBuffer   * gimp_drawable_get_shadow_buffer      (gint32         drawable_ID);
 
-
 GimpDrawable * gimp_drawable_get                    (gint32         drawable_ID);
 void           gimp_drawable_detach                 (GimpDrawable  *drawable);
 void           gimp_drawable_flush                  (GimpDrawable  *drawable);
diff --git a/libgimp/gimptilebackendplugin.c b/libgimp/gimptilebackendplugin.c
index 8528eec..6aa65d9 100644
--- a/libgimp/gimptilebackendplugin.c
+++ b/libgimp/gimptilebackendplugin.c
@@ -48,7 +48,6 @@ static int gimp_gegl_tile_mul (void)
 static const Babl *get_format (gint32 drawable_ID);
 static const Babl *get_format (gint32 drawable_ID)
 {
-  gint32 image_ID = gimp_item_get_image (drawable_ID);
   switch (gimp_drawable_type (drawable_ID))
     {
       case GIMP_RGB_IMAGE:  return babl_format ("RGB u8");
@@ -58,6 +57,7 @@ static const Babl *get_format (gint32 drawable_ID)
       case GIMP_INDEXED_IMAGE:
       case GIMP_INDEXEDA_IMAGE:
         {
+          gint32 image_ID = gimp_item_get_image (drawable_ID);
           const Babl *pala, *pal;
           gint    ncols;
           guchar *cmap = gimp_image_get_colormap (image_ID, &ncols);
@@ -82,22 +82,23 @@ static gpointer gimp_tile_backend_plugin_command  (GeglTileSource  *tile_store,
                                                    gpointer         data);
 
 static void       gimp_tile_write_mul (GimpTileBackendPlugin *backend_plugin,
-                                       gint                        x,
-                                       gint                        y,
-                                       guchar                     *source);
+                                       gint                   x,
+                                       gint                   y,
+                                       guchar                *source);
 
 static GeglTile * gimp_tile_read_mul (GimpTileBackendPlugin *backend_plugin,
-                                      gint                        x,
-                                      gint                        y);
+                                      gint                   x,
+                                      gint                   y);
 
-G_DEFINE_TYPE (GimpTileBackendPlugin, gimp_tile_backend_plugin,
+
+G_DEFINE_TYPE (GimpTileBackendPlugin, _gimp_tile_backend_plugin,
                GEGL_TYPE_TILE_BACKEND)
 
-#define parent_class gimp_tile_backend_plugin_parent_class
+#define parent_class _gimp_tile_backend_plugin_parent_class
 
 
 static void
-gimp_tile_backend_plugin_class_init (GimpTileBackendPluginClass *klass)
+_gimp_tile_backend_plugin_class_init (GimpTileBackendPluginClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
@@ -108,7 +109,7 @@ gimp_tile_backend_plugin_class_init (GimpTileBackendPluginClass *klass)
 }
 
 static void
-gimp_tile_backend_plugin_init (GimpTileBackendPlugin *backend)
+_gimp_tile_backend_plugin_init (GimpTileBackendPlugin *backend)
 {
   GeglTileSource *source = GEGL_TILE_SOURCE (backend);
 
@@ -125,18 +126,18 @@ gimp_tile_backend_plugin_finalize (GObject *object)
   GimpTileBackendPlugin *backend = GIMP_TILE_BACKEND_PLUGIN (object);
 
   if (backend->priv->drawable) /* This also causes a flush */
-     gimp_drawable_detach (backend->priv->drawable);
+    gimp_drawable_detach (backend->priv->drawable);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gpointer
 gimp_tile_backend_plugin_command (GeglTileSource  *tile_store,
-                                        GeglTileCommand  command,
-                                        gint             x,
-                                        gint             y,
-                                        gint             z,
-                                        gpointer         data)
+                                  GeglTileCommand  command,
+                                  gint             x,
+                                  gint             y,
+                                  gint             z,
+                                  gpointer         data)
 {
   GimpTileBackendPlugin *backend_plugin;
 
@@ -159,8 +160,8 @@ gimp_tile_backend_plugin_command (GeglTileSource  *tile_store,
 
 static GeglTile *
 gimp_tile_read_mul (GimpTileBackendPlugin *backend_plugin,
-                    gint                        x,
-                    gint                        y)
+                    gint                   x,
+                    gint                   y)
 {
   GimpTileBackendPluginPrivate *priv = backend_plugin->priv;
   GeglTileBackend            *backend;
@@ -186,7 +187,7 @@ gimp_tile_read_mul (GimpTileBackendPlugin *backend_plugin,
         if (x + u >= priv->drawable->ntile_cols ||
             y + v >= priv->drawable->ntile_rows)
           continue;
-        
+
         gimp_tile = gimp_drawable_get_tile (priv->drawable,
                                             priv->shadow,
                                             y+v, x+u);
@@ -261,8 +262,8 @@ gimp_tile_write_mul (GimpTileBackendPlugin *backend_plugin,
 }
 
 GeglTileBackend *
-gimp_tile_backend_plugin_new (GimpDrawable *drawable,
-                              gint          shadow)
+_gimp_tile_backend_plugin_new (GimpDrawable *drawable,
+                               gint          shadow)
 {
   const Babl                   *format;
   GeglTileBackend              *ret;
@@ -289,5 +290,6 @@ gimp_tile_backend_plugin_new (GimpDrawable *drawable,
   priv->shadow = shadow;
 
   gegl_tile_backend_set_extent (ret, &rect);
+
   return ret;
 }
diff --git a/libgimp/gimptilebackendplugin.h b/libgimp/gimptilebackendplugin.h
index a887b31..98f1f27 100644
--- a/libgimp/gimptilebackendplugin.h
+++ b/libgimp/gimptilebackendplugin.h
@@ -25,7 +25,7 @@
 
 G_BEGIN_DECLS
 
-#define GIMP_TYPE_TILE_BACKEND_PLUGIN            (gimp_tile_backend_plugin_get_type ())
+#define GIMP_TYPE_TILE_BACKEND_PLUGIN            (_gimp_tile_backend_plugin_get_type ())
 #define GIMP_TILE_BACKEND_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TILE_BACKEND_PLUGIN, GimpTileBackendPlugin))
 #define GIMP_TILE_BACKEND_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GIMP_TYPE_TILE_BACKEND_PLUGIN, GimpTileBackendPluginClass))
 #define GIMP_IS_TILE_BACKEND_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TILE_BACKEND_PLUGIN))
@@ -33,6 +33,7 @@ G_BEGIN_DECLS
 #define GIMP_TILE_BACKEND_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIMP_TYPE_TILE_BACKEND_PLUGIN, GimpTileBackendPluginClass))
 
 
+typedef struct _GimpTileBackendPlugin        GimpTileBackendPlugin;
 typedef struct _GimpTileBackendPluginClass   GimpTileBackendPluginClass;
 typedef struct _GimpTileBackendPluginPrivate GimpTileBackendPluginPrivate;
 
@@ -48,10 +49,10 @@ struct _GimpTileBackendPluginClass
   GeglTileBackendClass parent_class;
 };
 
-GType             gimp_tile_backend_plugin_get_type (void) G_GNUC_CONST;
+GType             _gimp_tile_backend_plugin_get_type (void) G_GNUC_CONST;
 
-GeglTileBackend * gimp_tile_backend_plugin_new      (GimpDrawable *drawable,
-                                                     gint          shadow);
+GeglTileBackend * _gimp_tile_backend_plugin_new      (GimpDrawable *drawable,
+                                                      gint          shadow);
 
 G_END_DECLS
 
diff --git a/libgimp/gimptypes.h b/libgimp/gimptypes.h
index b371146..48e7025 100644
--- a/libgimp/gimptypes.h
+++ b/libgimp/gimptypes.h
@@ -28,15 +28,14 @@ G_BEGIN_DECLS
 /* For information look into the html documentation */
 
 
-typedef struct _GimpPlugInInfo        GimpPlugInInfo;
-typedef struct _GimpTile              GimpTile;
-typedef struct _GimpDrawable          GimpDrawable;
-typedef struct _GimpPixelRgn          GimpPixelRgn;
-typedef struct _GimpParamDef          GimpParamDef;
-typedef struct _GimpParamRegion       GimpParamRegion;
-typedef union  _GimpParamData         GimpParamData;
-typedef struct _GimpParam             GimpParam;
-typedef struct _GimpTileBackendPlugin GimpTileBackendPlugin;
+typedef struct _GimpPlugInInfo  GimpPlugInInfo;
+typedef struct _GimpTile        GimpTile;
+typedef struct _GimpDrawable    GimpDrawable;
+typedef struct _GimpPixelRgn    GimpPixelRgn;
+typedef struct _GimpParamDef    GimpParamDef;
+typedef struct _GimpParamRegion GimpParamRegion;
+typedef union  _GimpParamData   GimpParamData;
+typedef struct _GimpParam       GimpParam;
 
 G_END_DECLS
 



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