diff options
author | Thomas White <taw@physics.org> | 2021-02-15 11:39:18 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-02-15 11:39:18 +0100 |
commit | 09e71ff37379f6827a50a0e2d4ec26971af2b00c (patch) | |
tree | cb1a38658554f99a0aa117cc050fe7cca6decb37 /libcrystfel | |
parent | 82e6750fd53bf0bea4bd665edb60cc244ce923ce (diff) |
Check that bad regions are actually within panel bounds
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/src/datatemplate.c | 28 | ||||
-rw-r--r-- | libcrystfel/src/image.c | 19 |
2 files changed, 43 insertions, 4 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index b92fcb0a..6712c280 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1285,11 +1285,31 @@ DataTemplate *data_template_new_from_string(const char *string_in) reject = 1; } else { struct panel_template *p; + struct dt_badregion *bad; + int r = 0; p = &dt->panels[dt->bad[i].panel_number]; - dt->bad[i].min_fs -= p->orig_min_fs; - dt->bad[i].max_fs -= p->orig_min_fs; - dt->bad[i].min_ss -= p->orig_min_ss; - dt->bad[i].max_ss -= p->orig_min_ss; + bad = &dt->bad[i]; + if ( bad->min_fs < p->orig_min_fs ) r = 1; + if ( bad->min_ss < p->orig_min_ss ) r = 1; + if ( bad->max_fs > p->orig_max_fs ) r = 1; + if ( bad->max_ss > p->orig_max_ss ) r = 1; + if ( r ) { + ERROR("Bad region '%s' is outside the " + "panel bounds (%s) as presented " + "in data (%i %i, %i %i inclusive): " + "Bad region %i,%i to %i, %i " + "inclusive\n", + bad->name, p->name, + p->orig_min_fs, p->orig_min_ss, + p->orig_max_fs, p->orig_max_ss, + bad->min_fs, bad->min_ss, + bad->max_fs, bad->max_ss); + reject = 1; + } + bad->min_fs -= p->orig_min_fs; + bad->max_fs -= p->orig_min_fs; + bad->min_ss -= p->orig_min_ss; + bad->max_ss -= p->orig_min_ss; } } } diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index aa388580..2a936011 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -717,6 +717,19 @@ static void mark_flagged_pixels(struct panel_template *p, } +static int region_within_panel(struct dt_badregion *region, + struct detgeom_panel *panel) +{ + assert(region->is_fsss); + + if ( region->min_fs < 0 ) return 0; + if ( region->min_ss < 0 ) return 0; + if ( region->max_fs >= panel->w ) return 0; + if ( region->max_ss >= panel->h ) return 0; + return 1; +} + + static void draw_bad_region_fsss(struct dt_badregion *region, int **bad, struct detgeom *detgeom) @@ -726,6 +739,12 @@ static void draw_bad_region_fsss(struct dt_badregion *region, panel = &detgeom->panels[region->panel_number]; + if ( !region_within_panel(region, panel) ) { + ERROR("Bad pixel region %s is (partially) outside panel - ignoring it\n", + region->name); + return; + } + for ( ss=region->min_ss; ss<=region->max_ss; ss++ ) { for ( fs=region->min_fs; fs<=region->max_fs; fs++ ) { bad[region->panel_number][fs+ss*panel->w] = 1; |