From b49667bfc9892e6546abfc4ead10cc0a85364957 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 20 Mar 2020 11:17:47 +0100 Subject: Actually load the mask --- libcrystfel/src/image.c | 98 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 27 deletions(-) diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index ce3ba4af..63c9ba93 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -1537,35 +1537,50 @@ static struct image *image_read_hdf5(DataTemplate *dtempl, } -#if 0 -static struct image *read_mask_hdf5(DataTemplate *dtempl, const char *filename, - const char *event) +static int load_mask_cbf(struct panel_template *p, + const char *filename, const char *event, + int gz, int *bad, int mask_good, int mask_bad) { - if ( p->mask != NULL ) { - int *flags = malloc(dims[0]*dims[1]*sizeof(int)); - if ( !load_mask(f, ev, p, flags, f_offset, f_count, p->dim_structure) ) { - image->bad[pi] = make_badmask(flags, image->det, - image->dp[pi], p); - } else { - image->bad[pi] = make_badmask(NULL, image->det, - image->dp[pi], p); - } - free(flags); - } else { - image->bad[pi] = make_badmask(NULL, image->det, - image->dp[pi], p); - } + ERROR("Mask loading from CBF not yet supported\n"); + return 1; +} - if ( p->satmap != NULL ) { - if ( load_satmap(f, ev, p, f_offset, f_count, p->dim_structure, - image->sat[pi]) ) - { - ERROR("Failed to load sat map for panel %s\n", - p->name); - } - } + +/* Load bad pixels for this panel from given filename/event, and merge + * with (already allocated/initialised) mask "bad" */ +static int load_mask_hdf5(struct panel_template *p, + const char *filename, const char *event, + int *bad, int mask_good, int mask_bad) +{ + int p_w, p_h; + int *mask; + long unsigned int j; + + p_w = p->orig_max_fs - p->orig_min_fs + 1; + p_h = p->orig_max_ss - p->orig_min_ss + 1; + + if ( load_hdf5_hyperslab(p, filename, event, + (void *)&mask, H5T_NATIVE_INT, + sizeof(int)) ) + { + ERROR("Failed to load mask data\n"); + free(mask); + return 1; + } + + for ( j=0; jbad) && (p->mask != NULL) ) { + if ( p->mask_file == NULL ) { + mask_fn = filename; + } else { + mask_fn = p->mask_file; + } + if ( H5Fis_hdf5(mask_fn) > 0 ) { + load_mask_hdf5(p, mask_fn, event, + image->bad[i], + dtempl->mask_good, + dtempl->mask_bad); + + } else if ( is_cbf_file(filename) > 0 ) { + load_mask_cbf(p, mask_fn, event, + 0, image->bad[i], + dtempl->mask_good, + dtempl->mask_bad); + + } else if ( is_cbfgz_file(filename) ) { + load_mask_cbf(p, mask_fn, event, + 1, image->bad[i], + dtempl->mask_good, + dtempl->mask_bad); + } else { + ERROR("Unrecognised mask file type" + " (%s)\n", filename); + return NULL; + } + } } /* FIXME: Load saturation map */ -- cgit v1.2.3