diff options
author | Thomas White <taw@physics.org> | 2022-08-18 14:20:16 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-08-18 15:57:46 +0200 |
commit | eaf9e6250654e65daabbe98b6b4d5b5f8cd6924f (patch) | |
tree | ecaa9a88d1bfe1b03d36961d58f26f1dc2ab7c1d /libcrystfel/src/image-msgpack.c | |
parent | e8847558c3831e309d0325382589f34b273e96c8 (diff) |
Restructure image data array creation
This adds a central procedure (image_create_dp_bad_sat) to create all
the arrays. Then it's up to the loading procedure to put the values
into the arrays.
This also makes the loading procedures responsible for marking NaN/inf
pixels in the bad pixel map. This avoids an additional sweep through
the image data, and makes it possible to skip the NaN/inf check
altogether if the image data comes, as it often does, in format which
can't represent NaN/inf anyway.
Finally, it removes quite a lot of duplicated code.
Diffstat (limited to 'libcrystfel/src/image-msgpack.c')
-rw-r--r-- | libcrystfel/src/image-msgpack.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/libcrystfel/src/image-msgpack.c b/libcrystfel/src/image-msgpack.c index 11876b7c..f6d6f2dd 100644 --- a/libcrystfel/src/image-msgpack.c +++ b/libcrystfel/src/image-msgpack.c @@ -318,7 +318,7 @@ int image_msgpack_read_header_to_cache(struct image *image, static int load_msgpack_data(struct panel_template *p, msgpack_object *map_obj, - float **pdata) + float *data, int *bad) { msgpack_object *obj; msgpack_object *type_obj; @@ -326,7 +326,6 @@ static int load_msgpack_data(struct panel_template *p, msgpack_object *data_obj; char *dtype; int data_size_fs, data_size_ss; - void *data = NULL; obj = find_msgpack_kv(map_obj, p->data); if ( obj == NULL ) { @@ -398,45 +397,36 @@ static int load_msgpack_data(struct panel_template *p, if ( strcmp(dtype, "<i4") == 0 ) { int fs, ss; - float *fdata; int32_t *in_data = (int32_t *)data_obj->via.bin.ptr; - fdata = malloc(PANEL_WIDTH(p) * PANEL_HEIGHT(p) * sizeof(float)); - if ( fdata == NULL ) return 1; - for ( ss=0; ss<PANEL_HEIGHT(p); ss++ ) { for ( fs=0; fs<PANEL_WIDTH(p); fs++ ) { size_t idx = fs+p->orig_min_fs + (ss+p->orig_min_ss)*data_size_fs; - fdata[fs+ss*PANEL_WIDTH(p)] = in_data[idx]; + data[fs+ss*PANEL_WIDTH(p)] = in_data[idx]; + /* Integer data -> no need to check NaN/inf */ } } - data = fdata; - } else if ( strcmp(dtype, "<f4") == 0 ) { int fs, ss; - float *fdata; float *in_data = (float *)data_obj->via.bin.ptr; - fdata = malloc(PANEL_WIDTH(p) * PANEL_HEIGHT(p) * sizeof(float)); - if ( fdata == NULL ) return 1; - for ( ss=0; ss<PANEL_HEIGHT(p); ss++ ) { for ( fs=0; fs<PANEL_WIDTH(p); fs++ ) { size_t idx = fs+p->orig_min_fs + (ss+p->orig_min_ss)*data_size_fs; - fdata[fs+ss*PANEL_WIDTH(p)] = in_data[idx]; + data[fs+ss*PANEL_WIDTH(p)] = in_data[idx]; + if ( !isfinite(in_data[idx]) ) { + bad[idx] = 1; + } } } - data = fdata; - } else { ERROR("Unrecognised data type '%s'\n", dtype); } free(dtype); - *pdata = data; return 0; } @@ -476,18 +466,9 @@ int image_msgpack_read(struct image *image, return 1; } - image->dp = malloc(dtempl->n_panels*sizeof(float *)); - if ( image->dp == NULL ) { - ERROR("Failed to allocate data array.\n"); - msgpack_unpacked_destroy(&unpacked); - return 1; - } - - /* Set all pointers to NULL for easier clean-up */ - for ( i=0; i<dtempl->n_panels; i++ ) image->dp[i] = NULL; - for ( i=0; i<dtempl->n_panels; i++ ) { - if ( load_msgpack_data(&dtempl->panels[i], obj, &image->dp[i]) ) + if ( load_msgpack_data(&dtempl->panels[i], obj, + image->dp[i], image->bad[i]) ) { ERROR("Failed to load data for panel '%s'\n", dtempl->panels[i].name); |