[gimp/goat-invasion: 110/325] app: add gimp_pixbuf_create_buffer() and use it in GimpBuffer



commit 01ea7c3521e008fffec4d9c0ffd6d586a897c03c
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 17 23:14:14 2012 +0100

    app: add gimp_pixbuf_create_buffer() and use it in GimpBuffer

 app/core/gimpbuffer.c      |   24 +++++-------------------
 app/gegl/gimp-gegl-utils.c |   27 +++++++++++++++++++++++++++
 app/gegl/gimp-gegl-utils.h |    6 +++++-
 3 files changed, 37 insertions(+), 20 deletions(-)
---
diff --git a/app/core/gimpbuffer.c b/app/core/gimpbuffer.c
index 4672114..e3be72d 100644
--- a/app/core/gimpbuffer.c
+++ b/app/core/gimpbuffer.c
@@ -259,30 +259,16 @@ gimp_buffer_new_from_pixbuf (GdkPixbuf   *pixbuf,
                              gint         offset_x,
                              gint         offset_y)
 {
-  GimpBuffer   *gimp_buffer;
-  GeglBuffer   *buffer;
-  gint          width;
-  gint          height;
-  gint          rowstride;
-  gint          channels;
-  GeglRectangle rect = { 0, };
+  GimpBuffer *gimp_buffer;
+  GeglBuffer *buffer;
+  gint        channels;
 
   g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
   g_return_val_if_fail (name != NULL, NULL);
 
-  width     = gdk_pixbuf_get_width (pixbuf);
-  height    = gdk_pixbuf_get_height (pixbuf);
-  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-  channels  = gdk_pixbuf_get_n_channels (pixbuf);
-
-  rect.width = width;
-  rect.height = height;
+  channels = gdk_pixbuf_get_n_channels (pixbuf);
 
-  buffer = gegl_buffer_linear_new_from_data (gdk_pixbuf_get_pixels (pixbuf),
-                                             gimp_bpp_to_babl_format (channels,
-                                                                      TRUE),
-                                             &rect, rowstride,
-                                             NULL, NULL);
+  buffer = gimp_pixbuf_create_buffer (pixbuf);
 
   gimp_buffer = gimp_buffer_new (buffer, name,
                                  GIMP_IMAGE_TYPE_FROM_BYTES (channels),
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index 02f667d..92b33d0 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -133,6 +133,33 @@ gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation)
 }
 
 GeglBuffer *
+gimp_pixbuf_create_buffer (GdkPixbuf *pixbuf)
+{
+  gint          width;
+  gint          height;
+  gint          rowstride;
+  gint          channels;
+  GeglRectangle rect = { 0, };
+
+  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
+
+  width     = gdk_pixbuf_get_width (pixbuf);
+  height    = gdk_pixbuf_get_height (pixbuf);
+  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+  channels  = gdk_pixbuf_get_n_channels (pixbuf);
+
+  rect.width = width;
+  rect.height = height;
+
+  return gegl_buffer_linear_new_from_data (gdk_pixbuf_get_pixels (pixbuf),
+                                           gimp_bpp_to_babl_format (channels,
+                                                                    TRUE),
+                                           &rect, rowstride,
+                                           (GDestroyNotify) g_object_unref,
+                                           pixbuf);
+}
+
+GeglBuffer *
 gimp_tile_manager_create_buffer (TileManager *tm,
                                  const Babl  *format,
                                  gboolean     write)
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index 95be309..ba69f65 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -22,15 +22,19 @@
 #define __GIMP_GEGL_UTILS_H__
 
 
+#include <gdk-pixbuf/gdk-pixbuf.h> /* temp hack */
+
+
 const Babl  * gimp_bpp_to_babl_format           (guint                  bpp,
                                                  gboolean               linear) G_GNUC_CONST;
 
 const gchar * gimp_layer_mode_to_gegl_operation (GimpLayerModeEffects   mode) G_GNUC_CONST;
 const gchar * gimp_interpolation_to_gegl_filter (GimpInterpolationType  interpolation) G_GNUC_CONST;
 
-GeglBuffer *  gimp_tile_manager_create_buffer   (TileManager           *tm,
+GeglBuffer  * gimp_tile_manager_create_buffer   (TileManager           *tm,
                                                  const Babl            *format,
                                                  gboolean               write);
+GeglBuffer  * gimp_pixbuf_create_buffer         (GdkPixbuf             *pixbuf);
 
 void          gimp_gegl_buffer_refetch_tiles    (GeglBuffer            *buffer);
 



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