[gegl] buffer: add gegl_buffer_iterator_stop
- From: Ãyvind KolÃs <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: add gegl_buffer_iterator_stop
- Date: Fri, 16 Mar 2012 22:41:42 +0000 (UTC)
commit 39a5fa34fed9d48ccf6a7080df671bcad6c9c0bb
Author: Ãyvind KolÃs <pippin gimp org>
Date: Fri Mar 16 22:41:11 2012 +0000
buffer: add gegl_buffer_iterator_stop
A function to be used when bailing out early from iterating over a region on a
buffer.
gegl/buffer/gegl-buffer-iterator.c | 71 ++++++++++++++++++++----------------
gegl/buffer/gegl-buffer-iterator.h | 9 +++++
2 files changed, 49 insertions(+), 31 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index 5ef5565..fc67bdf 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -241,6 +241,8 @@ static glong in_direct_read = 0;
static glong in_direct_write = 0;
#endif
+
+
gint
gegl_buffer_iterator_add (GeglBufferIterator *iterator,
GeglBuffer *buffer,
@@ -370,7 +372,42 @@ static void ensure_buf (GeglBufferIterators *i, gint no)
i->i[0].max_size);
}
-gboolean gegl_buffer_iterator_next (GeglBufferIterator *iterator)
+void
+gegl_buffer_iterator_stop (GeglBufferIterator *iterator)
+{
+ GeglBufferIterators *i = (gpointer)iterator;
+ gint no;
+ for (no=0; no<i->iterators;no++)
+ {
+ gint j;
+ gboolean found = FALSE;
+ for (j=0; j<no; j++)
+ if (i->buffer[no]==i->buffer[j])
+ {
+ found = TRUE;
+ break;
+ }
+ if (!found)
+ gegl_buffer_unlock (i->buffer[no]);
+ }
+
+ for (no=0; no<i->iterators; no++)
+ {
+ if (i->buf[no])
+ iterator_buf_pool_release (i->buf[no]);
+ i->buf[no]=NULL;
+ g_object_unref (i->buffer[no]);
+ }
+#if DEBUG_DIRECT
+ g_print ("%f %f\n", (100.0*direct_read/(in_direct_read+direct_read)),
+ 100.0*direct_write/(in_direct_write+direct_write));
+#endif
+ i->is_finished = TRUE;
+ g_slice_free (GeglBufferIterators, i);
+}
+
+gboolean
+gegl_buffer_iterator_next (GeglBufferIterator *iterator)
{
GeglBufferIterators *i = (gpointer)iterator;
gboolean result = FALSE;
@@ -500,36 +537,7 @@ gboolean gegl_buffer_iterator_next (GeglBufferIterator *iterator)
i->iteration_no++;
if (result == FALSE)
- {
- for (no=0; no<i->iterators;no++)
- {
- gint j;
- gboolean found = FALSE;
- for (j=0; j<no; j++)
- if (i->buffer[no]==i->buffer[j])
- {
- found = TRUE;
- break;
- }
- if (!found)
- gegl_buffer_unlock (i->buffer[no]);
- }
-
- for (no=0; no<i->iterators;no++)
- {
- if (i->buf[no])
- iterator_buf_pool_release (i->buf[no]);
- i->buf[no]=NULL;
- g_object_unref (i->buffer[no]);
- }
-#if DEBUG_DIRECT
- g_print ("%f %f\n", (100.0*direct_read/(in_direct_read+direct_read)),
- 100.0*direct_write/(in_direct_write+direct_write));
-#endif
- i->is_finished = TRUE;
- g_slice_free (GeglBufferIterators, i);
- }
-
+ gegl_buffer_iterator_stop (iterator);
return result;
}
@@ -545,3 +553,4 @@ GeglBufferIterator *gegl_buffer_iterator_new (GeglBuffer *buffer,
gegl_buffer_iterator_add (i, buffer, roi, format, flags);
return i;
}
+
diff --git a/gegl/buffer/gegl-buffer-iterator.h b/gegl/buffer/gegl-buffer-iterator.h
index 1e4ea14..6d2b321 100644
--- a/gegl/buffer/gegl-buffer-iterator.h
+++ b/gegl/buffer/gegl-buffer-iterator.h
@@ -80,6 +80,15 @@ gint gegl_buffer_iterator_add (GeglBufferIterator *iterator,
/**
+ * gegl_buffer_iterator_stop:
+ * @iterator: a GeglBufferIterator
+ *
+ * Cancels the current iteration, freeing up any temporary resources. You have
+ * to bail out of any loop you are currently.
+ */
+void gegl_buffer_iterator_stop (GeglBufferIterator *iterator);
+
+/**
* gegl_buffer_iterator_next:
* @iterator: a #GeglBufferIterator
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]