From 11ad6d1580893142577f4e192c346cf8dabe4596 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 11 Jan 2021 12:01:05 +0100 Subject: create_badmap: Break down into subroutines Also flips the order of iteration for (negligibly) better performance --- libcrystfel/src/image.c | 115 ++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 48 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 54171321..e8504f23 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -660,6 +660,67 @@ static int flag_value(float pixel, struct panel_template *p) } +static void mark_bad_regions(struct panel_template *p, + float *dp, int *bad, + const DataTemplate *dtempl, + int i) +{ + int p_w, p_h; + int fs, ss; + fenv_t envp; + + fegetenv(&envp); + fesetround(1); /* Round to nearest (for flag_value) */ + + p_w = p->orig_max_fs - p->orig_min_fs + 1; + p_h = p->orig_max_ss - p->orig_min_ss + 1; + + for ( ss=0; ssn_panels; i++ ) { - const char *mask_fn; int p_w, p_h; struct panel_template *p = &dtempl->panels[i]; @@ -696,64 +756,23 @@ static int create_badmap(struct image *image, /* Add bad regions (skip if panel is bad anyway) */ if ( !p->bad ) { - - int fs, ss; - fenv_t envp; - - fegetenv(&envp); - fesetround(1); /* Round to nearest - * (for flag_value) */ - - for ( fs=0; fsdp[i][fs+ss*p_w]; - if ( data_template_in_bad_region(dtempl, i, fs, ss) - || isnan(val) - || isinf(val) - || flag_value(val, p) ) - { - image->bad[i][fs+ss*p_w] = 1; - } - } - } - - fesetenv(&envp); + mark_bad_regions(p, image->dp[i], image->bad[i], + dtempl, i); } /* Load mask (skip if panel is bad anyway) */ if ( (!no_mask_data) && (!p->bad) && (p->mask != NULL) ) { + const char *mask_fn; + if ( p->mask_file == NULL ) { mask_fn = image->filename; } else { mask_fn = p->mask_file; } - if ( is_hdf5_file(mask_fn) ) { - image_hdf5_read_mask(p, mask_fn, - image->ev, - image->bad[i], - dtempl->mask_good, - dtempl->mask_bad); - - } else if ( is_cbf_file(mask_fn) ) { - image_cbf_read_mask(p, mask_fn, - image->ev, - 0, image->bad[i], - dtempl->mask_good, - dtempl->mask_bad); - - } else if ( is_cbfgz_file(mask_fn) ) { - image_cbf_read_mask(p, mask_fn, - image->ev, - 1, image->bad[i], - dtempl->mask_good, - dtempl->mask_bad); - } else { - ERROR("Unrecognised mask file type" - " (%s)\n", mask_fn); - return 1; - } + load_mask(p, mask_fn, image->ev, image->bad[i], + dtempl->mask_good, dtempl->mask_bad); } } return 0; -- cgit v1.2.3