[gegl/soc-2013-opecl-ops] Make gegl_buffer_get/set introspectable



commit ae5120b2f3fb68eb409e463d8b900045e1e722a8
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Tue Jun 11 07:31:47 2013 -0700

    Make gegl_buffer_get/set introspectable

 gegl/gegl-introspection-support.c |   56 +++++++++++++++++++++++++++++++++++++
 gegl/gegl-introspection-support.h |   44 +++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/gegl/gegl-introspection-support.c b/gegl/gegl-introspection-support.c
index 1a4c6a7..818e2f9 100644
--- a/gegl/gegl-introspection-support.c
+++ b/gegl/gegl-introspection-support.c
@@ -79,3 +79,59 @@ gegl_buffer_introspectable_new (const char *format_name,
                        "format", format,
                        NULL);
 }
+
+guchar *
+gegl_buffer_introspectable_get (GeglBuffer          *buffer,
+                                const GeglRectangle *rect,
+                                gdouble              scale,
+                                const gchar         *format_name,
+                                GeglAbyssPolicy      repeat_mode,
+                                guint               *data_length)
+{
+  const Babl *format;
+  guint bpp;
+  guchar *result;
+
+  *data_length = 0;
+
+  if (format_name)
+    format = babl_format (format_name);
+  else
+    format = gegl_buffer_get_format (buffer);
+
+  if (rect->width <= 0 || rect->height <= 0)
+    return NULL;
+  if (scale <= 0.0)
+    return NULL;
+
+  bpp = babl_format_get_bytes_per_pixel (format);
+  *data_length = bpp * rect->width * rect->height;
+
+  result = g_malloc (*data_length);
+
+  gegl_buffer_get (buffer, rect, scale, format, result, GEGL_AUTO_ROWSTRIDE, repeat_mode);
+
+  return result;
+}
+
+void
+gegl_buffer_introspectable_set (GeglBuffer          *buffer,
+                                const GeglRectangle *rect,
+                                const gchar         *format_name,
+                                const guchar        *src,
+                                gint                 src_length)
+{
+  const Babl *format;
+  guint bpp;
+
+  format = babl_format (format_name);
+
+  if (rect->width <= 0 || rect->height <= 0)
+    return;
+
+  bpp = babl_format_get_bytes_per_pixel (format);
+
+  g_return_if_fail (src_length == bpp * rect->width * rect->height);
+
+  gegl_buffer_set (buffer, rect, 0, format, src, 0);
+}
diff --git a/gegl/gegl-introspection-support.h b/gegl/gegl-introspection-support.h
index 9558a86..5303ce1 100644
--- a/gegl/gegl-introspection-support.h
+++ b/gegl/gegl-introspection-support.h
@@ -74,5 +74,49 @@ GeglBuffer *    gegl_buffer_introspectable_new (const char *format_name,
                                                 gint        width,
                                                 gint        height);
 
+/**
+ * gegl_buffer_introspectable_get:
+ * @buffer: the buffer to retrieve data from.
+ * @rect: the coordinates we want to retrieve data from.
+ * @scale: sampling scale, 1.0 = pixel for pixel 2.0 = magnify, 0.5 scale down.
+ * @format_name: (allow-none): the format to store data in, if NULL the format of the buffer is used.
+ * @repeat_mode: how requests outside the buffer extent are handled.
+ * Valid values: GEGL_ABYSS_NONE (abyss pixels are zeroed), GEGL_ABYSS_WHITE
+ * (abyss pixels are white), GEGL_ABYSS_BLACK (abyss pixels are black),
+ * GEGL_ABYSS_CLAMP (coordinates are clamped to the abyss rectangle),
+ * GEGL_ABYSS_LOOP (buffer contents are tiled if outside of the abyss rectangle).
+ * @data_length: (out): The length of the returned buffer
+ *
+ * Fetch a rectangular linear buffer of pixel data from the GeglBuffer.
+ *
+ * Rename to: gegl_buffer_get
+ *
+ * Return value: (transfer full) (array length=data_length): A copy of the requested data
+ */
+guchar *       gegl_buffer_introspectable_get (GeglBuffer          *buffer,
+                                               const GeglRectangle *rect,
+                                               gdouble              scale,
+                                               const gchar         *format_name,
+                                               GeglAbyssPolicy      repeat_mode,
+                                               guint               *data_length);
+
+
+/**
+ * gegl_buffer_introspectable_set:
+ * @buffer: the buffer to modify.
+ * @rect: the rectangle to write.
+ * @format_name: the format of the input data.
+ * @src: (transfer none) (array length=src_length): pixel data to write to @buffer.
+ * @src_length: the lenght of src in bytes
+ *
+ * Store a linear raster buffer into the GeglBuffer.
+ *
+ * Rename to: gegl_buffer_set
+ */
+void           gegl_buffer_introspectable_set (GeglBuffer          *buffer,
+                                               const GeglRectangle *rect,
+                                               const gchar         *format_name,
+                                               const guchar        *src,
+                                               gint                 src_length);
 #endif /* __GEGL_INTROSPECTION_SUPPORT_H__ */
 


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