gegl r2414 - in trunk: . gegl/buffer
- From: ok svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2414 - in trunk: . gegl/buffer
- Date: Wed, 11 Jun 2008 21:25:53 +0000 (UTC)
Author: ok
Date: Wed Jun 11 21:25:53 2008
New Revision: 2414
URL: http://svn.gnome.org/viewvc/gegl?rev=2414&view=rev
Log:
* gegl/buffer/Makefile.am: added gegl-buffer-linear.c
* gegl/buffer/gegl-buffer-private.h: new functions for dealing with
linear buffers (internal only for now).
* gegl/buffer/gegl-buffer-linear.c: new file with the main logic to
use GeglBuffer with linear buffers as backing store.
* gegl/buffer/gegl-buffer.c: (set_property): width and height were
swapped.
(gegl_buffer_constructor): pass tile_width and height to tile_storage,
(gegl_buffer_new_from_format): added tile_width and tile_height
arguments.
* gegl/buffer/gegl-tile-storage.c: (gegl_tile_storage_constructor):
set the "cache" data on the tile-storage itself as well.
* gegl/buffer/gegl-tile.[ch]: (default_free), (dispose),
(gegl_tile_init), (gegl_tile_new): added a destroy callback for the
tile data in a tile.
Added:
trunk/gegl/buffer/gegl-buffer-linear.c
Modified:
trunk/ChangeLog
trunk/gegl/buffer/Makefile.am
trunk/gegl/buffer/gegl-buffer-private.h
trunk/gegl/buffer/gegl-buffer.c
trunk/gegl/buffer/gegl-tile-storage.c
trunk/gegl/buffer/gegl-tile.c
trunk/gegl/buffer/gegl-tile.h
Modified: trunk/gegl/buffer/Makefile.am
==============================================================================
--- trunk/gegl/buffer/Makefile.am (original)
+++ trunk/gegl/buffer/Makefile.am Wed Jun 11 21:25:53 2008
@@ -13,6 +13,7 @@
gegl-buffer-share.c \
gegl-buffer-index.h \
gegl-buffer-iterator.c \
+ gegl-buffer-linear.c \
gegl-buffer-save.c \
gegl-buffer-load.c \
gegl-cache.c \
Added: trunk/gegl/buffer/gegl-buffer-linear.c
==============================================================================
--- (empty file)
+++ trunk/gegl/buffer/gegl-buffer-linear.c Wed Jun 11 21:25:53 2008
@@ -0,0 +1,128 @@
+#include "config.h"
+#include <string.h>
+#include <math.h>
+
+#include <glib-object.h>
+#include <glib/gprintf.h>
+
+#include "gegl-types.h"
+#include "gegl-buffer-types.h"
+#include "gegl-buffer-private.h"
+#include "gegl-tile-storage.h"
+#include "gegl-tile-handler-cache.h"
+#include "gegl-utils.h"
+
+GeglBuffer *
+gegl_buffer_linear_new (const GeglRectangle *extent,
+ const Babl *format)
+{
+ GeglRectangle empty={0,0,0,0};
+
+ if (extent==NULL)
+ extent = ∅
+
+ if (format==NULL)
+ format = babl_format ("RGBA float");
+
+ return g_object_new (GEGL_TYPE_BUFFER,
+ "x", extent->x,
+ "y", extent->y,
+ "width", extent->width,
+ "height", extent->height,
+ "tile-width", extent->width,
+ "tile-height", extent->height,
+ "format", format,
+ NULL);
+}
+
+
+void gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
+ GeglTile *tile,
+ gint x,
+ gint y,
+ gint z);
+
+GeglBuffer *
+gegl_buffer_linear_new_from_data (const gpointer data,
+ const Babl *format,
+ gint width,
+ gint height,
+ GCallback destroy_fn,
+ gpointer destroy_fn_data)
+{
+ GeglBuffer *buffer;
+ GeglRectangle extent={0,0,width, height};
+
+ buffer = gegl_buffer_linear_new (&extent, format);
+
+ {
+ GeglTile *tile = g_object_new (GEGL_TYPE_TILE, NULL);
+
+ tile->rev = 1;
+ tile->stored_rev = 1;
+ tile->tile_storage = buffer->tile_storage;
+ tile->x = 0;
+ tile->y = 0;
+ tile->z = 0;
+ tile->data = (gpointer)data;
+ tile->size = format->format.bytes_per_pixel * width * height;
+ tile->next_shared = tile;
+ tile->prev_shared = tile;
+
+ {
+ GeglTileHandlerCache *cache = g_object_get_data (G_OBJECT (buffer->tile_storage), "cache");
+ if (cache)
+ gegl_tile_handler_cache_insert (cache, tile, 0, 0, 0);
+ }
+ g_object_unref (tile);
+ }
+
+ return buffer;
+}
+
+
+
+gpointer *gegl_buffer_linear_open (GeglBuffer *buffer,
+ gint *width,
+ gint *height,
+ gint *rowstride)
+{
+ if (buffer->extent.width == buffer->tile_width &&
+ buffer->extent.height == buffer->tile_height)
+ {
+ GeglTile *tile;
+
+ g_assert (buffer->tile_width == buffer->tile_storage->tile_width);
+ g_assert (buffer->tile_height == buffer->tile_storage->tile_height);
+
+ tile = g_object_get_data (G_OBJECT (buffer), "linear-tile");
+ g_assert (tile == NULL);
+ tile = gegl_tile_source_get_tile ((GeglTileSource*) (buffer),
+ 0,0,0);
+ g_assert (tile);
+ gegl_buffer_lock (buffer);
+ gegl_tile_lock (tile);
+
+ g_object_set_data (G_OBJECT (buffer), "linear-tile", tile);
+
+ *width = buffer->extent.width;
+ *height = buffer->extent.height;
+ *rowstride = buffer->extent.width * buffer->format->format.bytes_per_pixel;
+ return (gpointer)gegl_tile_get_data (tile);
+ }
+
+ g_warning ("doesn't seem to be a linear buffer");
+ return NULL;
+}
+
+void gegl_buffer_linear_close (GeglBuffer *buffer)
+{
+ 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);
+ return;
+}
Modified: trunk/gegl/buffer/gegl-buffer-private.h
==============================================================================
--- trunk/gegl/buffer/gegl-buffer-private.h (original)
+++ trunk/gegl/buffer/gegl-buffer-private.h Wed Jun 11 21:25:53 2008
@@ -99,6 +99,24 @@
gboolean gegl_buffer_lock (GeglBuffer *buffer);
gboolean gegl_buffer_unlock (GeglBuffer *buffer);
+GeglBuffer* gegl_buffer_linear_new (const GeglRectangle *extent,
+ const Babl *format);
+
+GeglBuffer * gegl_buffer_linear_new_from_data (const gpointer data,
+ const Babl *format,
+ gint width,
+ gint height,
+ /* gint rowstride, FIXME: this should be supported */
+ GCallback destroy_fn,
+ gpointer destroy_fn_data);
+
+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);
+
#include "gegl-buffer-iterator.h"
#endif
Modified: trunk/gegl/buffer/gegl-buffer.c
==============================================================================
--- trunk/gegl/buffer/gegl-buffer.c (original)
+++ trunk/gegl/buffer/gegl-buffer.c Wed Jun 11 21:25:53 2008
@@ -104,7 +104,9 @@
gint x,
gint y,
gint width,
- gint height);
+ gint height,
+ gint tile_width,
+ gint tile_height);
static inline gint needed_tiles (gint w,
gint stride)
@@ -225,11 +227,11 @@
buffer->extent.height = g_value_get_int (value);
break;
- case PROP_TILE_WIDTH:
+ case PROP_TILE_HEIGHT:
buffer->tile_height = g_value_get_int (value);
break;
- case PROP_TILE_HEIGHT:
+ case PROP_TILE_WIDTH:
buffer->tile_width = g_value_get_int (value);
break;
@@ -491,7 +493,9 @@
buffer->extent.x,
buffer->extent.y,
buffer->extent.width,
- buffer->extent.height));
+ buffer->extent.height,
+ buffer->tile_width,
+ buffer->tile_height));
/* after construction,. x and y should be set to reflect
* the top level behavior exhibited by this buffer object.
*/
@@ -909,7 +913,9 @@
gint x,
gint y,
gint width,
- gint height)
+ gint height,
+ gint tile_width,
+ gint tile_height)
{
GeglTileStorage *tile_storage;
GeglBuffer *buffer;
@@ -934,23 +940,29 @@
{
tile_storage = g_object_new (GEGL_TYPE_TILE_STORAGE,
"format", babl_format,
+ "tile-width", tile_width,
+ "tile-height", tile_height,
NULL);
}
else
{
tile_storage = g_object_new (GEGL_TYPE_TILE_STORAGE,
"format", babl_format,
+ "tile-width", tile_width,
+ "tile-height", tile_height,
"path", path,
NULL);
}
buffer = g_object_new (GEGL_TYPE_BUFFER,
- "source", tile_storage,
- "x", x,
- "y", y,
- "width", width,
- "height", height,
- NULL);
+ "source", tile_storage,
+ "x", x,
+ "y", y,
+ "width", width,
+ "height", height,
+ "tile-width", tile_width,
+ "tile-height", tile_height,
+ NULL);
g_object_unref (tile_storage);
return buffer;
Modified: trunk/gegl/buffer/gegl-tile-storage.c
==============================================================================
--- trunk/gegl/buffer/gegl-tile-storage.c (original)
+++ trunk/gegl/buffer/gegl-tile-storage.c Wed Jun 11 21:25:53 2008
@@ -194,6 +194,7 @@
tile_handler_chain = GEGL_TILE_HANDLER_CHAIN (tile_storage);
handler = GEGL_HANDLER (tile_storage);
+
if (tile_storage->path != NULL)
{
#if 1
@@ -258,6 +259,7 @@
if (g_getenv("GEGL_LOG_TILE_CACHE"))
gegl_tile_handler_chain_add (tile_handler_chain,
g_object_new (GEGL_TYPE_TILE_HANDLER_LOG, NULL));
+ g_object_set_data (G_OBJECT (tile_storage), "cache", cache);
g_object_set_data (G_OBJECT (empty), "cache", cache);
g_object_set_data (G_OBJECT (zoom), "cache", cache);
Modified: trunk/gegl/buffer/gegl-tile.c
==============================================================================
--- trunk/gegl/buffer/gegl-tile.c (original)
+++ trunk/gegl/buffer/gegl-tile.c Wed Jun 11 21:25:53 2008
@@ -108,6 +108,12 @@
#include "gegl-utils.h"
+static void default_free (gpointer data,
+ gpointer userdata)
+{
+ gegl_free (data);
+}
+
static void
dispose (GObject *object)
{
@@ -120,7 +126,8 @@
{
if (tile->next_shared == tile)
{ /* no clones */
- gegl_free (tile->data);
+ if (tile->destroy_notify)
+ tile->destroy_notify (tile->data, tile->destroy_notify_data);
tile->data = NULL;
}
else
@@ -187,6 +194,7 @@
#if ENABLE_MP
tile->mutex = g_mutex_new ();
#endif
+ tile->destroy_notify = default_free;
}
GeglTile *
@@ -217,7 +225,6 @@
tile->size = size;
tile->stored_rev = 1;
-
return tile;
}
Modified: trunk/gegl/buffer/gegl-tile.h
==============================================================================
--- trunk/gegl/buffer/gegl-tile.h (original)
+++ trunk/gegl/buffer/gegl-tile.h Wed Jun 11 21:25:53 2008
@@ -30,6 +30,7 @@
#define GEGL_IS_TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEGL_TYPE_TILE))
#define GEGL_TILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEGL_TYPE_TILE, GeglTileClass))
+
/* the instance size of a GeglTile is a bit large, and should if possible be
* trimmed down
*/
@@ -62,11 +63,15 @@
/* the shared list is a doubly linked circular list */
GeglTile *next_shared;
GeglTile *prev_shared;
+
+ void (*destroy_notify) (gpointer pixels,
+ gpointer data);
+ gpointer destroy_notify_data;
};
struct _GeglTileClass
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
GType gegl_tile_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]