summaryrefslogtreecommitdiffstats
path: root/src/ufo-read-task.c
blob: 8c8b3b515b8f5e345510a4cafe7dfed965d35a6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/*
 * Copyright (C) 2011-2013 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <gmodule.h>
#include <stdlib.h>
#include <string.h>
#include <glob.h>

#include "config.h"
#include "ufo-read-task.h"

#include "readers/ufo-reader.h"
#include "readers/ufo-edf-reader.h"
#include "readers/ufo-raw-reader.h"

#ifdef HAVE_TIFF
#include "readers/ufo-tiff-reader.h"
#endif

#ifdef WITH_HDF5
#include "readers/ufo-hdf5-reader.h"
#endif

/* XXX: keep enum and values array in sync! */
typedef enum {
    TYPE_EDF,
    TYPE_RAW,
#ifdef HAVE_TIFF
    TYPE_TIFF,
#endif
#ifdef WITH_HDF5
    TYPE_HDF5,
#endif
    TYPE_UNSPECIFIED
} FileType;

static GEnumValue type_values[] = {
    { TYPE_EDF,     "TYPE_EDF",     "edf" },
    { TYPE_RAW,     "TYPE_RAW",     "raw" },
#ifdef HAVE_TIFF
    { TYPE_TIFF,    "TYPE_TIFF",    "tiff" },
#endif
#ifdef WITH_HDF5
    { TYPE_HDF5,    "TYPE_HDF5",    "hdf5" },
#endif
    { TYPE_UNSPECIFIED, "TYPE_UNSPECIFIED", "unspecified" },
    { 0, NULL, NULL}
};

struct _UfoReadTaskPrivate {
    gchar   *path;
    GList   *filenames;
    GList   *current_element;
    guint    current;
    guint    step;
    guint    start;
    guint    image_start;
    guint    number;
    gboolean done;
    gboolean single;

    UfoBufferDepth  depth;
    gboolean convert;

    guint    roi_y;
    guint    roi_height;
    guint    roi_step;
    guint    image_step;

    UfoReader       *reader;
    UfoEdfReader    *edf_reader;
    UfoRawReader    *raw_reader;

#ifdef HAVE_TIFF
    UfoTiffReader   *tiff_reader;
#endif

#ifdef WITH_HDF5
    UfoHdf5Reader   *hdf5_reader;
#endif

    FileType         type;
};

static void ufo_task_interface_init (UfoTaskIface *iface);

G_DEFINE_TYPE_WITH_CODE (UfoReadTask, ufo_read_task, UFO_TYPE_TASK_NODE,
                         G_IMPLEMENT_INTERFACE (UFO_TYPE_TASK,
                                                ufo_task_interface_init))

#define UFO_READ_TASK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_READ_TASK, UfoReadTaskPrivate))

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,
    PROP_RAW_BITDEPTH,
    PROP_RAW_PRE_OFFSET,
    PROP_RAW_POST_OFFSET,
    PROP_TYPE,
    N_PROPERTIES
};

static GParamSpec *properties[N_PROPERTIES] = { NULL, };

UfoNode *
ufo_read_task_new (void)
{
    return UFO_NODE (g_object_new (UFO_TYPE_READ_TASK, NULL));
}

static GList *
read_filenames (UfoReadTaskPrivate *priv)
{
    GList *result;
    gchar *pattern;
    glob_t filenames;

    result = NULL;

#ifdef WITH_HDF5
    if (ufo_reader_can_open (UFO_READER (priv->hdf5_reader), priv->path) || priv->type == TYPE_HDF5)
        return g_list_append (NULL, g_strdup (priv->path));
#endif

    if (g_file_test (priv->path, G_FILE_TEST_IS_REGULAR)) {
        /* This is a single file without any asterisks */
        priv->single = TRUE;
        pattern = g_strdup (priv->path);
    }
    else {
        /* This is a directory which we may have to glob */
        priv->single = FALSE;
        pattern = strstr (priv->path, "*") != NULL ? g_strdup (priv->path) : g_build_filename (priv->path, "*", NULL);
    }

    glob (pattern, GLOB_MARK | GLOB_TILDE, NULL, &filenames);

    for (guint i = 0; i < filenames.gl_pathc; i++) {
        const gchar *filename = filenames.gl_pathv[i];

#ifdef HAVE_TIFF
        if (ufo_reader_can_open (UFO_READER (priv->tiff_reader), filename) || priv->type == TYPE_TIFF) {
            result = g_list_append (result, g_strdup (filename));
            continue;
        }
#endif

        if (ufo_reader_can_open (UFO_READER (priv->edf_reader), filename) || priv->type == TYPE_EDF) {
            result = g_list_append (result, g_strdup (filename));
            continue;
        }

        if (ufo_reader_can_open (UFO_READER (priv->raw_reader), filename) || priv->type == TYPE_RAW) {
            result = g_list_append (result, g_strdup (filename));
            continue;
        }
    }

    globfree (&filenames);
    g_free (pattern);
    return result;
}

static void
ufo_read_task_setup (UfoTask *task,
                     UfoResources *resources,
                     GError **error)
{
    UfoReadTaskPrivate *priv;

    priv = UFO_READ_TASK_GET_PRIVATE (task);

    priv->filenames = read_filenames (priv);

    if (priv->filenames == NULL) {
        g_set_error (error, UFO_TASK_ERROR, UFO_TASK_ERROR_SETUP,
                     "`%s' does not match any files", priv->path);
        return;
    }

    priv->filenames = g_list_sort (priv->filenames, (GCompareFunc) g_strcmp0);

    if (priv->single)
        priv->current_element = g_list_first (priv->filenames);
    else
        priv->current_element = g_list_nth (priv->filenames, priv->start);

    if (priv->current_element == NULL) {
        g_set_error (error, UFO_TASK_ERROR, UFO_TASK_ERROR_SETUP,
                     "start=%i skips too many files", priv->start);
        return;
    }

    priv->current = 0;
}

static UfoReader *
get_reader (UfoReadTaskPrivate *priv, const gchar *filename)
{
#ifdef HAVE_TIFF
    if (ufo_reader_can_open (UFO_READER (priv->tiff_reader), filename) || priv->type == TYPE_TIFF)
        return UFO_READER (priv->tiff_reader);
#endif

#ifdef WITH_HDF5
    if (ufo_reader_can_open (UFO_READER (priv->hdf5_reader), filename) || priv->type == TYPE_HDF5)
        return UFO_READER (priv->hdf5_reader);
#endif

    if (ufo_reader_can_open (UFO_READER (priv->edf_reader), filename) || priv->type == TYPE_EDF)
        return UFO_READER (priv->edf_reader);

    if (ufo_reader_can_open (UFO_READER (priv->raw_reader), filename) || priv->type == TYPE_RAW)
        return UFO_READER (priv->raw_reader);

    return NULL;
}

static void
ufo_read_task_get_requisition (UfoTask *task,
                               UfoBuffer **inputs,
                               UfoRequisition *requisition,
                               GError **error)
{
    UfoReadTaskPrivate *priv;
    const gchar *filename;
    gsize num_images = 0;

    priv = UFO_READ_TASK_GET_PRIVATE (UFO_READ_TASK (task));

    if (!priv->reader || !ufo_reader_data_available (priv->reader)) {
        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);
                priv->current_element = g_list_nth (priv->current_element, priv->step);
            }

            if (priv->current_element == NULL) {
                priv->done = TRUE;
                priv->reader = NULL;
                return;
            }

            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->roi_y >= requisition->dims[1]) {
                g_set_error (error, UFO_TASK_ERROR, UFO_TASK_ERROR_GET_REQUISITION,
                             "read: vertical ROI start %i >= height %zu",
                             priv->roi_y, requisition->dims[1]);
                return;
            }

            if (!priv->roi_height) {
                priv->roi_height = requisition->dims[1] - priv->roi_y;
            }
            else {
                if (priv->roi_y + priv->roi_height > requisition->dims[1]) {
                    g_set_error (error, UFO_TASK_ERROR, UFO_TASK_ERROR_GET_REQUISITION,
                                 "read: vertical ROI start + height %i >= height %zu",
                                 priv->roi_y + priv->roi_height, requisition->dims[1]);
                    return;
                }
            }
            if (priv->image_start >= num_images) {
                priv->image_start -= num_images;
            } else {
                priv->image_start = 0;
                break;
            }
        }
    }


    if (priv->depth > 32)
        /*
         * We have to take care of this in the writers, because we cannot
         * allocate larger buffers than those with float elements.
         */
        priv->depth = UFO_BUFFER_DEPTH_32F;

    /* update height for reduced vertical ROI and allow things like roi_height=1
     * and roi_step=20 */
    requisition->dims[1] = (priv->roi_height - 1) / priv->roi_step + 1;
}

static guint
ufo_read_task_get_num_inputs (UfoTask *task)
{
    return 0;
}

static guint
ufo_read_task_get_num_dimensions (UfoTask *task,
                               guint input)
{
    return 0;
}

static UfoTaskMode
ufo_read_task_get_mode (UfoTask *task)
{
    return UFO_TASK_MODE_GENERATOR | UFO_TASK_MODE_CPU;
}

static gboolean
ufo_read_task_generate (UfoTask *task,
                        UfoBuffer *output,
                        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;

    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);

    priv->current++;
    return TRUE;
}

static void
ufo_read_task_set_property (GObject *object,
                            guint property_id,
                            const GValue *value,
                            GParamSpec *pspec)
{
    UfoReadTaskPrivate *priv = UFO_READ_TASK_GET_PRIVATE (object);

    switch (property_id) {
        case PROP_PATH:
            g_free (priv->path);
            priv->path = g_value_dup_string (value);
            break;
        case PROP_STEP:
            priv->step = g_value_get_uint (value);
            break;
        case PROP_ROI_Y:
            priv->roi_y = g_value_get_uint (value);
            break;
        case PROP_ROI_HEIGHT:
            priv->roi_height = g_value_get_uint (value);
            break;
        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;
        case PROP_RAW_WIDTH:
            g_object_set_property (G_OBJECT (priv->raw_reader), "width", value);
            break;
        case PROP_RAW_HEIGHT:
            g_object_set_property (G_OBJECT (priv->raw_reader), "height", value);
            break;
        case PROP_RAW_BITDEPTH:
            g_object_set_property (G_OBJECT (priv->raw_reader), "bitdepth", value);
            break;
        case PROP_RAW_PRE_OFFSET:
            g_object_set_property (G_OBJECT (priv->raw_reader), "pre-offset", value);
            break;
        case PROP_RAW_POST_OFFSET:
            g_object_set_property (G_OBJECT (priv->raw_reader), "post-offset", value);
            break;
        case PROP_TYPE:
            priv->type = g_value_get_enum (value);
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
            break;
    }
}

static void
ufo_read_task_get_property (GObject *object,
                              guint property_id,
                              GValue *value,
                              GParamSpec *pspec)
{
    UfoReadTaskPrivate *priv = UFO_READ_TASK_GET_PRIVATE (object);

    switch (property_id) {
        case PROP_PATH:
            g_value_set_string (value, priv->path);
            break;
        case PROP_STEP:
            g_value_set_uint (value, priv->step);
            break;
        case PROP_ROI_Y:
            g_value_set_uint (value, priv->roi_y);
            break;
        case PROP_ROI_HEIGHT:
            g_value_set_uint (value, priv->roi_height);
            break;
        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;
        case PROP_RAW_WIDTH:
            g_object_get_property (G_OBJECT (priv->raw_reader), "width", value);
            break;
        case PROP_RAW_HEIGHT:
            g_object_get_property (G_OBJECT (priv->raw_reader), "height", value);
            break;
        case PROP_RAW_BITDEPTH:
            g_object_get_property (G_OBJECT (priv->raw_reader), "bitdepth", value);
            break;
        case PROP_RAW_PRE_OFFSET:
            g_object_get_property (G_OBJECT (priv->raw_reader), "pre-offset", value);
            break;
        case PROP_RAW_POST_OFFSET:
            g_object_get_property (G_OBJECT (priv->raw_reader), "post-offset", value);
            break;
        case PROP_TYPE:
            g_value_set_enum (value, priv->type);
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
            break;
    }
}

static void
ufo_read_task_dispose (GObject *object)
{
    UfoReadTaskPrivate *priv;

    priv = UFO_READ_TASK_GET_PRIVATE (object);

    g_object_unref (priv->edf_reader);
    g_object_unref (priv->raw_reader);

#ifdef HAVE_TIFF
    g_object_unref (priv->tiff_reader);
#endif

#ifdef WITH_HDF5
    g_object_unref (priv->hdf5_reader);
#endif

    G_OBJECT_CLASS (ufo_read_task_parent_class)->dispose (object);
}

static void
ufo_read_task_finalize (GObject *object)
{
    UfoReadTaskPrivate *priv;

    priv = UFO_READ_TASK_GET_PRIVATE (object);

    g_free (priv->path);
    priv->path = NULL;

    if (priv->filenames != NULL) {
        g_list_free_full (priv->filenames, (GDestroyNotify) g_free);
        priv->filenames = NULL;
    }

    G_OBJECT_CLASS (ufo_read_task_parent_class)->finalize (object);
}

static void
ufo_task_interface_init (UfoTaskIface *iface)
{
    iface->setup = ufo_read_task_setup;
    iface->get_num_inputs = ufo_read_task_get_num_inputs;
    iface->get_num_dimensions = ufo_read_task_get_num_dimensions;
    iface->get_mode = ufo_read_task_get_mode;
    iface->get_requisition = ufo_read_task_get_requisition;
    iface->generate = ufo_read_task_generate;
}

static void
ufo_read_task_class_init(UfoReadTaskClass *klass)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

    gobject_class->set_property = ufo_read_task_set_property;
    gobject_class->get_property = ufo_read_task_get_property;
    gobject_class->dispose = ufo_read_task_dispose;
    gobject_class->finalize = ufo_read_task_finalize;

    properties[PROP_PATH] =
        g_param_spec_string ("path",
            "Glob-style pattern.",
            "Glob-style pattern that describes the file path.",
            "*.tif",
            G_PARAM_READWRITE);

    properties[PROP_STEP] =
        g_param_spec_uint ("step",
            "Read every \"step\" file",
            "Read every \"step\" file",
            1, G_MAXUINT, 1,
            G_PARAM_READWRITE);

    properties[PROP_ROI_Y] =
        g_param_spec_uint ("y",
            "Vertical coordinate",
            "Vertical coordinate from where to start reading the image",
            0, G_MAXUINT, 0,
            G_PARAM_READWRITE);

    properties[PROP_ROI_HEIGHT] =
        g_param_spec_uint ("height",
            "Height",
            "Height of the region of interest to read",
            0, G_MAXUINT, 0,
            G_PARAM_READWRITE);

    properties[PROP_ROI_STEP] =
        g_param_spec_uint ("y-step",
            "Read every \"step\" row",
            "Read every \"step\" row",
            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",
            "Enable automatic conversion of input data types to float",
            TRUE,
            G_PARAM_READWRITE);

    properties[PROP_START] =
        g_param_spec_uint ("start",
            "Offset to the first read file",
            "Offset to the first read file",
            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 images that will be read at most",
            "Number of images that will be read at most",
            0, G_MAXUINT, G_MAXUINT,
            G_PARAM_READWRITE);

    properties[PROP_RAW_WIDTH] =
        g_param_spec_uint ("raw-width",
            "Width of raw image",
            "Width of raw image",
            0, G_MAXUINT, 0,
            G_PARAM_READWRITE);

    properties[PROP_RAW_HEIGHT] =
        g_param_spec_uint ("raw-height",
            "Height of raw image",
            "Height of raw image",
            0, G_MAXUINT, 0,
            G_PARAM_READWRITE);

    properties[PROP_RAW_BITDEPTH] =
        g_param_spec_uint ("raw-bitdepth",
            "Bitdepth of raw image",
            "Bitdepth of raw image",
            0, G_MAXUINT, UFO_BUFFER_DEPTH_INVALID,
            G_PARAM_READWRITE);

    properties[PROP_RAW_PRE_OFFSET] =
        g_param_spec_ulong ("raw-pre-offset",
            "Offset in bytes to skip before reading data",
            "Offset in bytes to skip before reading data",
            0, G_MAXULONG, 0,
            G_PARAM_READWRITE);

    properties[PROP_RAW_POST_OFFSET] =
        g_param_spec_ulong ("raw-post-offset",
            "Offset in bytes to skip after reading data",
            "Offset in bytes to skip after reading data",
            0, G_MAXULONG, 0,
            G_PARAM_READWRITE);

    properties[PROP_TYPE] =
        g_param_spec_enum ("type",
            "Override type detection based on extension",
            "Override type detection based on extension",
            g_enum_register_static ("ufo_read_type", type_values),
            TYPE_UNSPECIFIED,
            G_PARAM_READWRITE);

    for (guint i = PROP_0 + 1; i < N_PROPERTIES; i++)
        g_object_class_install_property (gobject_class, i, properties[i]);

    g_type_class_add_private (gobject_class, sizeof(UfoReadTaskPrivate));
}

static void
ufo_read_task_init(UfoReadTask *self)
{
    UfoReadTaskPrivate *priv = NULL;

    self->priv = priv = UFO_READ_TASK_GET_PRIVATE (self);
    priv->path = g_strdup (".");
    priv->step = 1;
    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->depth = UFO_BUFFER_DEPTH_32F;

    priv->edf_reader = ufo_edf_reader_new ();
    priv->raw_reader = ufo_raw_reader_new ();

#ifdef HAVE_TIFF
    priv->tiff_reader = ufo_tiff_reader_new ();
#endif

#ifdef WITH_HDF5
    priv->hdf5_reader = ufo_hdf5_reader_new ();
#endif

    priv->reader = NULL;
    priv->done = FALSE;
    priv->single = FALSE;
    priv->type = TYPE_UNSPECIFIED;
}