This is the altered gegl_scanline_processor, gegl_image_data, and
gegl_image_iterator.
It compiles, but fails when it tries to test at the point where the op
starts to process a GList of data as though it was an iterator.
--
Dan
? gegl/docs/reference/gegl/version.xml
Index: gegl/gegl/gegl-image-data.c
===================================================================
RCS file: /cvs/gnome/gegl/gegl/gegl-image-data.c,v
retrieving revision 1.3
diff -u -p -r1.3 gegl-image-data.c
--- gegl/gegl/gegl-image-data.c 12 Feb 2003 01:39:10 -0000 1.3
+++ gegl/gegl/gegl-image-data.c 15 Mar 2003 04:14:17 -0000
@@ -69,3 +69,69 @@ gegl_image_data_set_rect (GeglImageData
gegl_rect_copy(&self->rect,rect);
}
+
+GeglImageIterator*
+gegl_image_data_make_iterator(GeglImageData * self)
+{
+ GeglData* data=GEGL_DATA(self);
+ GValue *value=NULL;
+ GeglImage* image=NULL;
+
+ g_return_val_if_fail(GEGL_IS_DATA(data),NULL);
+ g_return_val_if_fail(GEGL_IS_IMAGE_DATA(self),NULL);
+
+ if (self->iterator!=NULL)
+ {
+ g_object_unref(self->iterator);
+ self->iterator=NULL;
+ }
+
+ value=gegl_data_get_value(data);
+
+ g_return_val_if_fail(value!=NULL,NULL);
+
+ image=g_value_get_object(value);
+
+ self->iterator=g_object_new (GEGL_TYPE_IMAGE_ITERATOR,
+ "image", image,
+ "area", &(self->rect),
+ NULL);
+ return self->iterator;
+}
+
+
+GeglImageIterator*
+gegl_image_data_get_iterator(GeglImageData * self)
+{
+ g_return_val_if_fail(!GEGL_IS_IMAGE_DATA(self),NULL);
+ return self->iterator;
+
+}
+
+void
+gegl_image_data_set_iterator(GeglImageData * self,
+ GeglImageIterator * iterator)
+{
+
+ g_return_if_fail(!GEGL_IS_IMAGE_DATA(self));
+ g_return_if_fail(!GEGL_IS_IMAGE_ITERATOR(iterator));
+
+ g_object_ref(iterator);
+ if (self->iterator != NULL)
+ {
+ g_object_unref(self->iterator);
+ self->iterator=NULL;
+ }
+ self->iterator=iterator;
+}
+
+void
+gegl_image_data_remove_iterator(GeglImageData *self)
+{
+ g_return_if_fail(!GEGL_IS_IMAGE_DATA(self));
+ if (self->iterator !=NULL)
+ {
+ g_object_unref(self->iterator);
+ }
+ self->iterator=NULL;
+}
Index: gegl/gegl/gegl-image-data.h
===================================================================
RCS file: /cvs/gnome/gegl/gegl/gegl-image-data.h,v
retrieving revision 1.3
diff -u -p -r1.3 gegl-image-data.h
--- gegl/gegl/gegl-image-data.h 12 Feb 2003 01:39:10 -0000 1.3
+++ gegl/gegl/gegl-image-data.h 15 Mar 2003 04:14:17 -0000
@@ -2,6 +2,7 @@
#define __GEGL_IMAGE_DATA_H__
#include "gegl-color-data.h"
+#include "gegl-image-iterator.h"
#ifdef __cplusplus
extern "C" {
@@ -21,6 +22,7 @@ struct _GeglImageData
/*< private >*/
GeglRect rect;
+ GeglImageIterator * iterator;
};
typedef struct _GeglImageDataClass GeglImageDataClass;
@@ -34,6 +36,11 @@ void gegl_image_data_get_rect
GeglRect * rect);
void gegl_image_data_set_rect (GeglImageData * self,
GeglRect * rect);
+GeglImageIterator* gegl_image_data_make_iterator (GeglImageData * self);
+GeglImageIterator* gegl_image_data_get_iterator (GeglImageData * self);
+void gegl_image_data_set_iterator (GeglImageData * self,
+ GeglImageIterator * iterator);
+void gegl_image_data_remove_iterator(GeglImageData *self);
#ifdef __cplusplus
}
Index: gegl/gegl/gegl-image-iterator.c
===================================================================
RCS file: /cvs/gnome/gegl/gegl/gegl-image-iterator.c,v
retrieving revision 1.1
diff -u -p -r1.1 gegl-image-iterator.c
--- gegl/gegl/gegl-image-iterator.c 12 Feb 2003 01:39:10 -0000 1.1
+++ gegl/gegl/gegl-image-iterator.c 15 Mar 2003 04:14:17 -0000
@@ -359,3 +359,13 @@ gegl_image_iterator_alpha_channel(GeglIm
return alpha_pointer;
}
+
+gint
+gegl_image_iterator_length(GeglImageIterator *self)
+{
+
+ g_return_val_if_fail(self!=NULL,0);
+ g_return_val_if_fail(GEGL_IS_IMAGE_ITERATOR(self), 0);
+
+ return self->rect.h;
+}
Index: gegl/gegl/gegl-image-iterator.h
===================================================================
RCS file: /cvs/gnome/gegl/gegl/gegl-image-iterator.h,v
retrieving revision 1.1
diff -u -p -r1.1 gegl-image-iterator.h
--- gegl/gegl/gegl-image-iterator.h 12 Feb 2003 01:39:10 -0000 1.1
+++ gegl/gegl/gegl-image-iterator.h 15 Mar 2003 04:14:17 -0000
@@ -56,6 +56,7 @@ void gegl_image_iterator_set_
void gegl_image_iterator_set_scanline (GeglImageIterator * self,
gint y);
+gint gegl_image_iterator_length (GeglImageIterator * self);
#ifdef __cplusplus
}
#endif /* __cplusplus */
Index: gegl/gegl/gegl-scanline-processor.c
===================================================================
RCS file: /cvs/gnome/gegl/gegl/gegl-scanline-processor.c,v
retrieving revision 1.8
diff -u -p -r1.8 gegl-scanline-processor.c
--- gegl/gegl/gegl-scanline-processor.c 12 Feb 2003 01:39:11 -0000 1.8
+++ gegl/gegl/gegl-scanline-processor.c 15 Mar 2003 04:14:17 -0000
@@ -10,6 +10,10 @@
static void class_init (GeglScanlineProcessorClass * klass);
static gpointer parent_class = NULL;
+static inline void make_iterator(gpointer data, gpointer user_data);
+static inline void advance_iterator(gpointer data, gpointer user_data);
+static inline void remove_iterator(gpointer data, gpointer user_data);
+
GType
gegl_scanline_processor_get_type (void)
{
@@ -59,17 +63,16 @@ gegl_scanline_processor_process (GeglSca
GList *data_outputs,
GList *data_inputs)
{
- gint i,j;
- GeglRect rect;
- GeglImage *image;
- gint width, height;
- gint num_inputs = g_list_length(data_inputs);
- gint num_outputs = g_list_length(data_outputs);
- GeglData *data = g_list_nth_data(data_outputs,0);
- GValue *value = gegl_data_get_value(data);
- GeglImageData *image_data = GEGL_IMAGE_DATA(data);
- GeglImageIterator **iters = g_new (GeglImageIterator*, num_inputs + num_outputs);
-
+ gint i;
+ gint length;
+ gint num_inputs = 0;
+ gint num_outputs = 0;
+
+ g_return_if_fail((data_outputs != NULL) || (data_inputs != NULL) );
+
+ num_inputs = g_list_length(data_inputs);
+ num_outputs = g_list_length(data_outputs);
+
#if 1
LOG_DEBUG("processor_process", "%s %p",
G_OBJECT_TYPE_NAME(self->op), self->op);
@@ -77,107 +80,113 @@ gegl_scanline_processor_process (GeglSca
LOG_DEBUG("processor_process", "inputs %d outputs %d",
num_inputs, num_outputs);
#endif
-
+
+ GArray * iterator_lengths=g_array_sized_new(FALSE,TRUE,sizeof(gint),num_inputs+num_outputs);
/* Get image iterators for outputs. */
- if (num_outputs == 1)
+ g_list_foreach(data_outputs,make_iterator,iterator_lengths);
+ /* Get image iterators for inputs. */
+ g_list_foreach(data_outputs,make_iterator,iterator_lengths);
+ /* If itertor_lengths is null, it means there are no image inputs or outputs,
+ * I wonder if we should be here in that case, but I'll pretend things are ok.
+ */
+
+ /* We should check to make sure that all the interators have the
+ same length. They all should. (this should have been checked in
+ validate_(in)|(out)puts, but it never hurts to check
+ */
+ length=0;
+ if (iterator_lengths->len==0)
{
- /*
- LOG_DEBUG("processor_process",
- "getting image iterator for output %d",
- i);
- */
-
- image = (GeglImage*)g_value_get_object(value);
- gegl_image_data_get_rect(image_data, &rect);
-
- /* Get the image, if it is not NULL */
- if(image)
- {
- LOG_DEBUG("processor_process",
- "output value image is %p",
- image);
-
- iters[0] = g_object_new (GEGL_TYPE_IMAGE_ITERATOR,
- "image", image,
- "area", &rect,
- NULL);
-
- gegl_image_iterator_first (iters[0]);
- }
+ length=0;
}
-
- /* Get image iterators for inputs. */
- for (i = 0; i < num_inputs; i++)
+ else
{
- /*
- LOG_DEBUG("processor_process",
- "getting image iterator for input %d",
- i);
- */
-
-
- GeglData *data_input = (GeglData*)g_list_nth_data(data_inputs,i);
- GeglImageData *image_data_input = GEGL_IMAGE_DATA(data_input);
- GValue *data_input_value = gegl_data_get_value(data_input);
- image = (GeglImage*)g_value_get_object(data_input_value);
- gegl_image_data_get_rect(image_data_input, &rect);
+ length=g_array_index(iterator_lengths,gint,0);
+ for (i=0;i<iterator_lengths->len;i++)
+ {
+ if (length != g_array_index(iterator_lengths,gint,i))
+ {
+ LOG_DEBUG("processor_process",
+ "image iterators are of unequal length.");
+ g_array_free(iterator_lengths,FALSE);
+ return;
+ }
+ }
+ }
+ g_array_free(iterator_lengths,FALSE);
+ LOG_DEBUG("processor_process", "length: %d", length);
- /* Get the image, if it is not NULL */
- if(image)
- {
- LOG_DEBUG("processor_process",
- "input value image is %p",
- image);
+ /* Now iterate over the scanlines */
+ /* Since we have checked that all the iterators have exactly the
+ * same length, we can just use length
+ */
+ for (i=0;i<length;i++)
+ {
+ (self->func)(self->op, data_outputs,data_inputs);
+ g_list_foreach(data_inputs,advance_iterator,NULL);
+ g_list_foreach(data_outputs,advance_iterator,NULL);
+ }
+ /* Free the iterators */
+ g_list_foreach(data_inputs,remove_iterator,NULL);
+ g_list_foreach(data_outputs,remove_iterator,NULL);
- iters[i + num_outputs] = g_object_new (GEGL_TYPE_IMAGE_ITERATOR,
- "image", image,
- "area", &rect,
- NULL);
+
+}
- gegl_image_iterator_first (iters[i + num_outputs]);
- }
- else
- iters[i + num_outputs] = NULL;
+static inline void
+make_iterator(gpointer element,
+ gpointer user_data)
+{
+ GeglData * data=element;
+ GeglImageData * image_data=element;
+ GeglImageIterator * image_iterator=NULL;
+ GArray * iterator_lengths=user_data;
+
+ g_return_if_fail(data!=NULL);
+
+ /* Don't check IS_IMAGE_DATA in a g_return_if_fail 'cause
+ * g_return_if_fail causes a fatal error in the testing sequence
+ */
+ if (GEGL_IS_IMAGE_DATA(image_data))
+ {
+ image_iterator=gegl_image_data_make_iterator(image_data);
}
+ if ((image_iterator != NULL)&&(iterator_lengths != NULL))
+ {
+ gint length=gegl_image_iterator_length(image_iterator);
+ g_array_append_val(iterator_lengths,length);
+ }
+}
- /* Get the height and width of dest rect we want to process */
-
- image = (GeglImage*)g_value_get_object(value);
- gegl_image_data_get_rect(image_data, &rect);
- width = rect.w;
- height = rect.h;
-
- LOG_DEBUG("processor_process", "width height %d %d", width, height);
+static inline void
+advance_iterator(gpointer element,
+ gpointer user_data)
+{
+ GeglImageData * image_data=element;
+ GeglImageIterator * image_iterator=NULL;
- /* Now iterate over the scanlines */
- for(j=0; j < height; j++)
+ if (!GEGL_IS_IMAGE_DATA(image_data))
{
- /*
- LOG_DEBUG("processor_process",
- "doing scanline %d",
- j);
- */
-
- /* Call the subclass scanline func. */
- (self->func)(self->op, iters, width);
-
- /* Advance all the scanlines. */
- for (i = 0; i < num_inputs + num_outputs; i++)
- {
- if(iters[i])
- gegl_image_iterator_next(iters[i]);
- }
+ return;
+ }
+ image_iterator=gegl_image_data_get_iterator(image_data);
+ if (image_iterator != NULL)
+ {
+ gegl_image_iterator_next(image_iterator);
+ }
+}
- }
- /* Free the iterators */
- for (i = 0; i < num_inputs + num_outputs; i++)
+static inline void
+remove_iterator(gpointer element,
+ gpointer user_data)
+{
+ GeglImageData * image_data=element;
+
+ if(!GEGL_IS_IMAGE_DATA(image_data))
{
- if (iters[i])
- g_object_unref (iters[i]);
+ return;
}
-
- /* Free the array of iterator pointers */
- g_free (iters);
+ gegl_image_data_remove_iterator(image_data);
}