[gimp/goat-invasion: 223/325] app: use utility functions to create a GeglBuffer from a TempBuf



commit 6700eb3be5d4f8b23e5814446512792883ada51f
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 22 22:09:52 2012 +0100

    app: use utility functions to create a GeglBuffer from a TempBuf
    
    and to get it back from the buffer.

 app/gegl/gimp-gegl-utils.c |   38 ++++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-utils.h |    5 +++++
 2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index 9889524..008bb86 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -24,6 +24,7 @@
 
 #include "gimp-gegl-types.h"
 
+#include "base/temp-buf.h"
 #include "base/tile-manager.h"
 
 #include "gimp-gegl-utils.h"
@@ -270,6 +271,43 @@ gimp_gegl_buffer_get_tiles (GeglBuffer *buffer)
   return gimp_tile_backend_tile_manager_get_tiles (backend);
 }
 
+GeglBuffer  *
+gimp_temp_buf_create_buffer (TempBuf    *temp_buf,
+                             const Babl *format)
+{
+  TempBuf    *new;
+  GeglBuffer *buffer;
+  gint        width, height;
+
+  g_return_val_if_fail (temp_buf != NULL, NULL);
+  g_return_val_if_fail (format != NULL, NULL);
+  g_return_val_if_fail (babl_format_get_bytes_per_pixel (format) ==
+                        temp_buf->bytes, NULL);
+
+  width  = temp_buf->width;
+  height = temp_buf->height;
+
+  new = temp_buf_copy (temp_buf, NULL);
+
+  buffer = gegl_buffer_linear_new_from_data (temp_buf_get_data (new),
+                                             format,
+                                             GIMP_GEGL_RECT (0, 0, width, height),
+                                             width * new->bytes,
+                                             (GDestroyNotify) temp_buf_free, new);
+
+  g_object_set_data (G_OBJECT (buffer), "gimp-temp-buf", new);
+
+  return buffer;
+}
+
+TempBuf *
+gimp_gegl_buffer_get_temp_buf (GeglBuffer *buffer)
+{
+  g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
+
+  return g_object_get_data (G_OBJECT (buffer), "gimp-temp-buf");
+}
+
 void
 gimp_gegl_buffer_refetch_tiles (GeglBuffer *buffer)
 {
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index a61235c..7a4dfed 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -40,6 +40,11 @@ GeglBuffer  * gimp_gegl_buffer_dup               (GeglBuffer            *buffer)
 GeglBuffer  * gimp_tile_manager_create_buffer    (TileManager           *tm,
                                                   const Babl            *format);
 TileManager * gimp_gegl_buffer_get_tiles         (GeglBuffer            *buffer);
+
+GeglBuffer  * gimp_temp_buf_create_buffer        (TempBuf               *temp_buf,
+                                                  const Babl            *format);
+TempBuf     * gimp_gegl_buffer_get_temp_buf      (GeglBuffer            *buffer);
+
 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]