diff options
Diffstat (limited to 'src/ufo-read-task.c')
-rw-r--r-- | src/ufo-read-task.c | 142 |
1 files changed, 90 insertions, 52 deletions
diff --git a/src/ufo-read-task.c b/src/ufo-read-task.c index 1587031..b2a0457 100644 --- a/src/ufo-read-task.c +++ b/src/ufo-read-task.c @@ -70,6 +70,7 @@ struct _UfoReadTaskPrivate { guint current; guint step; guint start; + guint image_start; guint number; guint retries; guint retry_timeout; @@ -82,6 +83,7 @@ struct _UfoReadTaskPrivate { guint roi_y; guint roi_height; guint roi_step; + guint image_step; UfoReader *reader; UfoEdfReader *edf_reader; @@ -110,11 +112,13 @@ enum { PROP_0, PROP_PATH, PROP_START, + PROP_IMAGE_START, PROP_NUMBER, PROP_STEP, PROP_ROI_Y, PROP_ROI_HEIGHT, PROP_ROI_STEP, + PROP_IMAGE_STEP, PROP_CONVERT, PROP_RAW_WIDTH, PROP_RAW_HEIGHT, @@ -224,7 +228,6 @@ ufo_read_task_setup (UfoTask *task, return; } - priv->start = 0; priv->current = 0; } @@ -258,69 +261,73 @@ ufo_read_task_get_requisition (UfoTask *task, { UfoReadTaskPrivate *priv; const gchar *filename; + gsize num_images = 0; priv = UFO_READ_TASK_GET_PRIVATE (UFO_READ_TASK (task)); - if (priv->reader == NULL) { - filename = (gchar *) priv->current_element->data; - priv->reader = get_reader (priv, filename); - - if (!ufo_reader_open (priv->reader, filename, priv->start, error)) - return; - - priv->start = 0; - } - - if (!ufo_reader_data_available (priv->reader)) { + if (!priv->reader || !ufo_reader_data_available (priv->reader)) { GList *last_element; guint tries; - ufo_reader_close (priv->reader); - last_element = priv->current_element; - priv->current_element = g_list_nth (priv->current_element, priv->step); - - if (priv->current_element == NULL) { - if (priv->retries == 0 || priv->current == priv->number) { - priv->done = TRUE; - priv->reader = NULL; - return; + while (TRUE) { + /* Keep skipping files until we find one with enough images to start + * reading at priv->image_start index. */ + if (priv->reader) { + ufo_reader_close (priv->reader); + last_element = priv->current_element; + priv->current_element = g_list_nth (priv->current_element, priv->step); } - for (tries = 0; tries < priv->retries && priv->current_element == NULL; tries++) { - GList *new_list; - GList *match; - - g_debug ("read: retry %i/%i, waiting %is for new files", tries + 1, priv->retries, priv->retry_timeout); - g_usleep (priv->retry_timeout * G_USEC_PER_SEC); - new_list = g_list_sort (read_filenames (priv), (GCompareFunc) g_strcmp0); - match = g_list_find_custom (new_list, last_element->data, (GCompareFunc) g_strcmp0); - - if (match != g_list_last (new_list)) { - g_list_free_full (priv->filenames, (GDestroyNotify) g_free); - priv->filenames = new_list; - priv->current_element = g_list_next (match); - } - else { - g_list_free_full (new_list, (GDestroyNotify) g_free); - } + if (priv->current_element == NULL) { + if (priv->retries == 0 || priv->current == priv->number) { + priv->done = TRUE; + priv->reader = NULL; + return; + } + + for (tries = 0; tries < priv->retries && priv->current_element == NULL; tries++) { + GList *new_list; + GList *match; + + g_debug ("read: retry %i/%i, waiting %is for new files", tries + 1, priv->retries, priv->retry_timeout); + g_usleep (priv->retry_timeout * G_USEC_PER_SEC); + new_list = g_list_sort (read_filenames (priv), (GCompareFunc) g_strcmp0); + match = g_list_find_custom (new_list, last_element->data, (GCompareFunc) g_strcmp0); + + if (match != g_list_last (new_list)) { + g_list_free_full (priv->filenames, (GDestroyNotify) g_free); + priv->filenames = new_list; + priv->current_element = g_list_next (match); + } + else { + g_list_free_full (new_list, (GDestroyNotify) g_free); + } + } + + if (priv->current_element == NULL) { + priv->done = TRUE; + priv->reader = NULL; + return; + } } - if (priv->current_element == NULL) { - priv->done = TRUE; - priv->reader = NULL; + filename = (gchar *) priv->current_element->data; + priv->reader = get_reader (priv, filename); + + if (!ufo_reader_open (priv->reader, filename, priv->image_start, error)) return; + if (!ufo_reader_get_meta (priv->reader, requisition, &num_images, &priv->depth, error)) + return; + + if (priv->image_start >= num_images) { + priv->image_start -= num_images; + } else { + priv->image_start = 0; + break; } } - - filename = (gchar *) priv->current_element->data; - priv->reader = get_reader (priv, filename); - - if (!ufo_reader_open (priv->reader, filename, 0, error)) - return; } - if (!ufo_reader_get_meta (priv->reader, requisition, &priv->depth, error)) - return; if (priv->depth > 32) /* @@ -376,13 +383,16 @@ ufo_read_task_generate (UfoTask *task, UfoRequisition *requisition) { UfoReadTaskPrivate *priv; + guint num_processed; priv = UFO_READ_TASK_GET_PRIVATE (UFO_READ_TASK (task)); if (priv->current == priv->number || priv->done) return FALSE; - ufo_reader_read (priv->reader, output, requisition, priv->roi_y, priv->roi_height, priv->roi_step); + num_processed = ufo_reader_read (priv->reader, output, requisition, priv->roi_y, priv->roi_height, + priv->roi_step, priv->image_step); + priv->image_start = priv->image_step - num_processed; if ((priv->depth != UFO_BUFFER_DEPTH_32F) && priv->convert) ufo_buffer_convert (output, priv->depth); @@ -416,12 +426,18 @@ ufo_read_task_set_property (GObject *object, case PROP_ROI_STEP: priv->roi_step = g_value_get_uint (value); break; + case PROP_IMAGE_STEP: + priv->image_step = g_value_get_uint (value); + break; case PROP_CONVERT: priv->convert = g_value_get_boolean (value); break; case PROP_START: priv->start = g_value_get_uint (value); break; + case PROP_IMAGE_START: + priv->image_start = g_value_get_uint (value); + break; case PROP_NUMBER: priv->number = g_value_get_uint (value); break; @@ -479,12 +495,18 @@ ufo_read_task_get_property (GObject *object, case PROP_ROI_STEP: g_value_set_uint (value, priv->roi_step); break; + case PROP_IMAGE_STEP: + g_value_set_uint (value, priv->image_step); + break; case PROP_CONVERT: g_value_set_boolean (value, priv->convert); break; case PROP_START: g_value_set_uint (value, priv->start); break; + case PROP_IMAGE_START: + g_value_set_uint (value, priv->image_start); + break; case PROP_NUMBER: g_value_set_uint (value, priv->number); break; @@ -613,6 +635,13 @@ ufo_read_task_class_init(UfoReadTaskClass *klass) 1, G_MAXUINT, 1, G_PARAM_READWRITE); + properties[PROP_IMAGE_STEP] = + g_param_spec_uint ("image-step", + "Read every \"step\" image", + "Read every \"step\" image", + 1, G_MAXUINT, 1, + G_PARAM_READWRITE); + properties[PROP_CONVERT] = g_param_spec_boolean ("convert", "Enable automatic conversion", @@ -627,10 +656,17 @@ ufo_read_task_class_init(UfoReadTaskClass *klass) 0, G_MAXUINT, 0, G_PARAM_READWRITE); + properties[PROP_IMAGE_START] = + g_param_spec_uint ("image-start", + "Offset to the first read image in a multi-image file", + "Offset to the first read image in a multi-image file", + 0, G_MAXUINT, 0, + G_PARAM_READWRITE); + properties[PROP_NUMBER] = g_param_spec_uint ("number", - "Number of files that will be read at most", - "Number of files that will be read at most", + "Number of images that will be read at most", + "Number of images that will be read at most", 0, G_MAXUINT, G_MAXUINT, G_PARAM_READWRITE); @@ -708,8 +744,10 @@ ufo_read_task_init(UfoReadTask *self) priv->roi_y = 0; priv->roi_height = 0; priv->roi_step = 1; + priv->image_step = 1; priv->convert = TRUE; priv->start = 0; + priv->image_start = 0; priv->number = G_MAXUINT; priv->retries = 0; priv->retry_timeout = 1; |