aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/image-cbf.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-08-18 14:20:16 +0200
committerThomas White <taw@physics.org>2022-08-18 15:57:46 +0200
commiteaf9e6250654e65daabbe98b6b4d5b5f8cd6924f (patch)
treeecaa9a88d1bfe1b03d36961d58f26f1dc2ab7c1d /libcrystfel/src/image-cbf.c
parente8847558c3831e309d0325382589f34b273e96c8 (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-cbf.c')
-rw-r--r--libcrystfel/src/image-cbf.c68
1 files changed, 30 insertions, 38 deletions
diff --git a/libcrystfel/src/image-cbf.c b/libcrystfel/src/image-cbf.c
index 51003934..ecbc3209 100644
--- a/libcrystfel/src/image-cbf.c
+++ b/libcrystfel/src/image-cbf.c
@@ -572,55 +572,47 @@ static int unpack_panels(struct image *image,
const DataTemplate *dtempl,
float *data, int data_width, int data_height)
{
- int pi;
-
- image->dp = malloc(dtempl->n_panels * sizeof(float *));
- if ( image->dp == NULL ) {
- ERROR("Failed to allocate panels.\n");
- return 1;
- }
-
- for ( pi=0; pi<dtempl->n_panels; pi++ ) {
-
- struct panel_template *p;
- int fs, ss;
- int p_w, p_h;
-
- p = &dtempl->panels[pi];
- p_w = p->orig_max_fs - p->orig_min_fs + 1;
- p_h = p->orig_max_ss - p->orig_min_ss + 1;
- image->dp[pi] = malloc(p_w*p_h*sizeof(float));
- if ( image->dp[pi] == NULL ) {
- ERROR("Failed to allocate panel\n");
- return 1;
- }
+ int pi;
+
+ for ( pi=0; pi<dtempl->n_panels; pi++ ) {
+
+ struct panel_template *p;
+ int fs, ss;
+ int p_w, p_h;
- if ( (p->orig_min_fs + p_w > data_width)
- || (p->orig_min_ss + p_h > data_height) )
- {
- ERROR("Panel %s is outside range of data in CBF file\n",
- p->name);
- return 1;
+ p = &dtempl->panels[pi];
+ p_w = p->orig_max_fs - p->orig_min_fs + 1;
+ p_h = p->orig_max_ss - p->orig_min_ss + 1;
+
+ if ( (p->orig_min_fs + p_w > data_width)
+ || (p->orig_min_ss + p_h > data_height) )
+ {
+ ERROR("Panel %s is outside range of data in CBF file\n",
+ p->name);
+ return 1;
}
for ( ss=0; ss<p_h; ss++ ) {
for ( fs=0; fs<p_w; fs++ ) {
- int idx;
- int cfs, css;
+ int idx;
+ int cfs, css;
- cfs = fs+p->orig_min_fs;
- css = ss+p->orig_min_ss;
- idx = cfs + css*data_width;
+ cfs = fs+p->orig_min_fs;
+ css = ss+p->orig_min_ss;
+ idx = cfs + css*data_width;
- image->dp[pi][fs+p_w*ss] = data[idx];
+ image->dp[pi][fs+p_w*ss] = data[idx];
+ if ( !isfinite(data[idx]) ) {
+ image->bad[pi][fs+p_w*ss] = 1;
+ }
- }
- }
+ }
+ }
- }
+ }
- return 0;
+ return 0;
}