summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Farago <sensej007@email.cz>2021-09-27 13:32:15 +0200
committerTomas Farago <sensej007@email.cz>2021-09-27 13:32:15 +0200
commitec1eb24c5dbca3152cffa17d8bba7ba9cc1bea9a (patch)
treef6ed53af499947a9f28bb1fe8bbb058ba28dd975
parente71db172c8a91a070f5def73168d45786c6ad139 (diff)
downloadufo-filters-ec1eb24c5dbca3152cffa17d8bba7ba9cc1bea9a.tar.gz
ufo-filters-ec1eb24c5dbca3152cffa17d8bba7ba9cc1bea9a.tar.bz2
ufo-filters-ec1eb24c5dbca3152cffa17d8bba7ba9cc1bea9a.tar.xz
ufo-filters-ec1eb24c5dbca3152cffa17d8bba7ba9cc1bea9a.zip
stack: force nonfactor generation
If the number of images in the stack hadn't been a divisor of the number of input images, the last images would have been dropped. This makes sure all images are processed and fills the last positions of the stack (when the total number of stacked images starts to exceed the number of input images) with arbitrary previous images. Fixes #210.
-rw-r--r--docs/filters.rst4
-rw-r--r--src/ufo-stack-task.c26
2 files changed, 26 insertions, 4 deletions
diff --git a/docs/filters.rst b/docs/filters.rst
index 5227f3b..f2b32ec 100644
--- a/docs/filters.rst
+++ b/docs/filters.rst
@@ -751,7 +751,9 @@ Stacking
.. gobj:class:: stack
Symmetrical to the slice filter, the stack filter stacks two-dimensional
- input.
+ input. If ``number`` is not a divisor of the number of input images, the
+ last produced stack at index which starts to exceed the number of input
+ images will contain arbitrary images from the previous iterations.
.. gobj:prop:: number:uint
diff --git a/src/ufo-stack-task.c b/src/ufo-stack-task.c
index b8a5446..0d35dad 100644
--- a/src/ufo-stack-task.c
+++ b/src/ufo-stack-task.c
@@ -25,6 +25,8 @@
struct _UfoStackTaskPrivate {
guint n_items;
guint current;
+ gboolean inputs_stopped;
+ gboolean finished;
gboolean generated;
};
@@ -113,12 +115,11 @@ ufo_stack_task_process (UfoTask *task,
size = ufo_buffer_get_size (inputs[0]);
in_mem = (guint8 *) ufo_buffer_get_host_array (inputs[0], NULL);
out_mem = (guint8 *) ufo_buffer_get_host_array (output, NULL);
- memcpy (out_mem + priv->current * size, in_mem, size);
+ memcpy (out_mem + (priv->current % priv->n_items) * size, in_mem, size);
priv->current++;
- if (priv->current == priv->n_items) {
+ if (priv->current % priv->n_items == 0) {
// g_warning ("StackTask: stack full, ready for generating. [current %d]", priv->current);
- priv->current = 0;
priv->generated = FALSE;
return FALSE;
}
@@ -135,6 +136,15 @@ ufo_stack_task_generate (UfoTask *task,
priv = UFO_STACK_TASK_GET_PRIVATE (task);
+ if (priv->inputs_stopped && !priv->finished) {
+ /* If the inputs stopped and n_items is not a divisor of the length of
+ * the input stream, force generation to make sure the last chunk of
+ * data is produced, even though with invalid last elements (leftovers
+ * from previous stack filling) */
+ priv->generated = FALSE;
+ priv->finished = TRUE;
+ }
+
if (!priv->generated) {
priv->generated = TRUE;
return TRUE;
@@ -144,6 +154,13 @@ ufo_stack_task_generate (UfoTask *task,
}
}
+static void inputs_stopped_callback (UfoTask *task)
+{
+ UfoStackTaskPrivate *priv = UFO_STACK_TASK_GET_PRIVATE (task);
+
+ priv->inputs_stopped = TRUE;
+}
+
static void
ufo_stack_task_set_property (GObject *object,
guint property_id,
@@ -225,4 +242,7 @@ ufo_stack_task_init(UfoStackTask *self)
{
self->priv = UFO_STACK_TASK_GET_PRIVATE(self);
self->priv->n_items = 1;
+ self->priv->inputs_stopped = FALSE;
+ self->priv->finished = FALSE;
+ g_signal_connect (self, "inputs_stopped", (GCallback) inputs_stopped_callback, NULL);
}