diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2019-07-16 14:29:29 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2019-07-16 14:29:29 +0200 |
commit | 84887c191149b8b4d5a9ea4f78286477fe0a82b2 (patch) | |
tree | 2fe6b0c4876dfc53761047f3a3571a048b3c02ad /src/e2e.c | |
parent | 7a61c9bf86178de625a8431160ee6b4a3f745f2c (diff) |
Fundus image exporting
Diffstat (limited to 'src/e2e.c')
-rw-r--r-- | src/e2e.c | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -86,6 +86,12 @@ static int make_pointer(const struct e2e_data *data, const char *pos, static int read_fundus(struct e2e_data *data, const char *cursor, struct e2e_image *image) { + if (cursor + image->width * image->height > data->end) { + errorf("Fundus image at %td ends past the end of file.\n", + cursor - data->start); + return 1; + } + // This cast is _technically_ illegal, but I can't think of a way in // which this would cause problems in practice. image->fundus = (const uint8_t*)cursor; @@ -96,6 +102,12 @@ static int read_fundus(struct e2e_data *data, const char *cursor, static int read_tomogram(struct e2e_data *data, const char *cursor, struct e2e_image *image) { + if (cursor + image->width * image->height * 2 > data->end) { + errorf("Tomogram image at %td ends past the end of file.\n", + cursor - data->start); + return 1; + } + image->tomogram = calloc(image->width * image->height, sizeof(float)); if (!image->tomogram) return ENOMEM; @@ -407,17 +419,29 @@ static int post_process(struct e2e_data *data) eli_for(dir, data->dirs, data_list) for (size_t i = 0; i < dir->num_entries; i++) { struct e2e_entry *entry = dir->entries + i; + struct e2e_series *series; struct e2e_slice *slice; rv = ensure_slice(data, entry->patient_id, entry->study_id, entry->series_id, entry->slice_id, - NULL, NULL, NULL, &slice); + NULL, NULL, &series, &slice); if (rv) return rv; - if (slice && entry->has_chunk - && entry->chunk.type == E2E_CHUNK_IMAGE) - slice->image = &entry->chunk.image; + if (entry->has_chunk && entry->chunk.type == E2E_CHUNK_IMAGE) { + struct e2e_image *image = &entry->chunk.image; + + if (slice && + entry->chunk.image.type == E2E_IMAGE_TOMOGRAM) + slice->image = image; + + if (series && + entry->chunk.image.type == E2E_IMAGE_FUNDUS) { + eli_append(&series->fundi, image, + series_fundi_list); + series->num_fundi++; + } + } } return 0; |