gegl r2479 - in trunk: . gegl/buffer tests/buffer
- From: ok svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2479 - in trunk: . gegl/buffer tests/buffer
- Date: Mon, 16 Jun 2008 20:46:22 +0000 (UTC)
Author: ok
Date: Mon Jun 16 20:46:22 2008
New Revision: 2479
URL: http://svn.gnome.org/viewvc/gegl?rev=2479&view=rev
Log:
* gegl/buffer/gegl-buffer-linear.c: (gegl_buffer_linear_open): added
format parameter, which might be NULL to use the buffers format and
made it fake a buffer if dimensions are not right or format does not
match.
(gegl_buffer_linear_close): free the linear proxy buffer.
* gegl/buffer/gegl-buffer-private.h:
* tests/buffer/buffer-test.c: (linear_modify),
(linear_from_data_rows), (linear_proxy_modify): added new test and
slightly clarified others.
Modified:
trunk/ChangeLog
trunk/gegl/buffer/gegl-buffer-linear.c
trunk/gegl/buffer/gegl-buffer-private.h
trunk/tests/buffer/buffer-test.c
Modified: trunk/gegl/buffer/gegl-buffer-linear.c
==============================================================================
--- trunk/gegl/buffer/gegl-buffer-linear.c (original)
+++ trunk/gegl/buffer/gegl-buffer-linear.c Mon Jun 16 20:46:22 2008
@@ -98,15 +98,25 @@
return buffer;
}
-
-
-gpointer *gegl_buffer_linear_open (GeglBuffer *buffer,
- gint *width,
- gint *height,
- gint *rowstride)
+typedef struct {
+ gpointer buf;
+ GeglRectangle extent;
+ const Babl *format;
+} BufferInfo;
+
+gpointer *
+gegl_buffer_linear_open (GeglBuffer *buffer,
+ gint *width,
+ gint *height,
+ gint *rowstride,
+ const Babl *format)
{
+ if (!format)
+ format = buffer->format;
+
if (buffer->extent.width == buffer->tile_width &&
- buffer->extent.height == buffer->tile_height)
+ buffer->extent.height == buffer->tile_height &&
+ buffer->format == format)
{
GeglTile *tile;
@@ -123,13 +133,34 @@
g_object_set_data (G_OBJECT (buffer), "linear-tile", tile);
- *width = buffer->extent.width;
- *height = buffer->extent.height;
- *rowstride = buffer->tile_storage->tile_width * buffer->format->format.bytes_per_pixel;
+ if(width)*width = buffer->extent.width;
+ if(height)*height = buffer->extent.height;
+ if(rowstride)*rowstride = buffer->tile_storage->tile_width * format->format.bytes_per_pixel;
return (gpointer)gegl_tile_get_data (tile);
}
-
- g_warning ("doesn't seem to be a linear buffer");
+ /* FIXME: first check if there is a linear buffer, we should share that one to
+ * avoid conflicts.
+ */
+ {
+ BufferInfo *info = g_new0 (BufferInfo, 1);
+ GList *linear_buffers;
+ gint rs;
+ linear_buffers = g_object_get_data (G_OBJECT (buffer), "linear-buffers");
+ linear_buffers = g_list_append (linear_buffers, info);
+ g_object_set_data (G_OBJECT (buffer), "linear-buffers", linear_buffers);
+
+ info->extent = buffer->extent;
+ info->format = format;
+
+ rs = info->extent.width * format->format.bytes_per_pixel;
+ if(width)*width = info->extent.width;
+ if(height)*height = info->extent.height;
+ if(rowstride)*rowstride = rs;
+
+ info->buf = gegl_malloc (rs * info->extent.height);
+ gegl_buffer_get (buffer, 1.0, &info->extent, format, info->buf, rs);
+ return info->buf;
+ }
return NULL;
}
@@ -139,10 +170,42 @@
{
GeglTile *tile;
tile = g_object_get_data (G_OBJECT (buffer), "linear-tile");
- if (!tile)
- return;
- gegl_tile_unlock (tile);
- gegl_buffer_unlock (buffer);
- g_object_set_data (G_OBJECT (buffer), "linear-tile", NULL);
+ if (tile)
+ {
+ gegl_tile_unlock (tile);
+ gegl_buffer_unlock (buffer);
+ g_object_set_data (G_OBJECT (buffer), "linear-tile", NULL);
+ tile = NULL;
+ }
+ else
+ {
+ GList *linear_buffers;
+ GList *iter;
+ BufferInfo *info = NULL;
+ linear_buffers = g_object_get_data (G_OBJECT (buffer), "linear-buffers");
+
+ for (iter = linear_buffers; iter; iter=iter->next)
+ {
+ info = iter->data;
+ if (info->buf == linear)
+ {
+ gegl_buffer_set (buffer, &info->extent, info->format, info->buf, 0);
+ break;
+ }
+ else
+ {
+ info = NULL;
+ }
+ }
+
+ if (info)
+ {
+ linear_buffers = g_list_remove (linear_buffers, linear);
+ gegl_free (info->buf);
+ g_free (info);
+ }
+
+ g_object_set_data (G_OBJECT (buffer), "linear-buffers", linear_buffers);
+ }
return;
}
Modified: trunk/gegl/buffer/gegl-buffer-private.h
==============================================================================
--- trunk/gegl/buffer/gegl-buffer-private.h (original)
+++ trunk/gegl/buffer/gegl-buffer-private.h Mon Jun 16 20:46:22 2008
@@ -115,10 +115,10 @@
gpointer *gegl_buffer_linear_open (GeglBuffer *buffer,
gint *width,
gint *height,
- gint *rowstride);
-/* needed if the linear buffer is faked */
-void gegl_buffer_linear_close (GeglBuffer *buffer,
- gpointer linear);
+ gint *rowstride,
+ const Babl *format);
+void gegl_buffer_linear_close (GeglBuffer *buffer,
+ gpointer linear);
GType gegl_sampler_type_from_interpolation (GeglInterpolation interpolation);
Modified: trunk/tests/buffer/buffer-test.c
==============================================================================
--- trunk/tests/buffer/buffer-test.c (original)
+++ trunk/tests/buffer/buffer-test.c Mon Jun 16 20:46:22 2008
@@ -790,7 +790,7 @@
gfloat *buf;
gint x, y, i;
- buf = (gpointer)gegl_buffer_linear_open (buffer, &width, &height, &rowstride);
+ buf = (gpointer)gegl_buffer_linear_open (buffer, &width, &height, &rowstride, NULL);
g_assert (buf);
i=0;
@@ -830,6 +830,65 @@
gegl_buffer_destroy (buffer);
}
+static gchar * linear_from_data_rows ()
+{
+ GeglBuffer *buffer;
+ gfloat *buf;
+ test_start();
+
+ buf = g_malloc (sizeof (float) * 12 * 10);
+ gint i;
+ for (i=0;i<120;i++)
+ buf[i]=i%12==5?0.5:0.0;
+
+ buffer = gegl_buffer_linear_new_from_data (buf, babl_format ("Y float"),
+ 10, /* width */
+ 10, /* height */
+ 12 * 4,
+ G_CALLBACK(g_free), /* destroy_notify */
+ NULL /* destroy_notify_data */);
+ print_buffer (buffer);
+ test_end ();
+ gegl_buffer_destroy (buffer);
+}
+
+
+static gchar * linear_proxy_modify ()
+{
+ GeglBuffer *buffer;
+ GeglRectangle extent = {0,0,40,20};
+ GeglRectangle roi = {1,1,30,10};
+ test_start();
+ buffer = gegl_buffer_new (&extent, babl_format ("Y float"));
+ fill_rect (buffer, &roi, 0.5);
+ roi.y+=3;
+ roi.x+=20;
+
+ {
+ gint width;
+ gint height;
+ gint rowstride;
+ gfloat *buf;
+ gint x, y, i;
+
+ buf = (gpointer)gegl_buffer_linear_open (buffer, &width, &height, &rowstride, NULL);
+ g_assert (buf);
+
+ i=0;
+ for (y=0;y<height;y++)
+ for (x=0;x<width;x++)
+ {
+ buf[i++]= ((x+y)*1.0) / width;
+ }
+ gegl_buffer_linear_close (buffer, buf);
+ }
+ fill_rect (buffer, &roi, 0.2);
+
+ print_buffer (buffer);
+ test_end ();
+ gegl_buffer_destroy (buffer);
+}
+
/**************************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]