aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/image.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-07-10 11:57:47 +0200
committerThomas White <taw@physics.org>2020-07-29 18:53:45 +0200
commitf7ea70e422fafdc886d5829d1bb5f9f3e75d726f (patch)
tree487df5d5269c9b63ce2d322d564d0058adab86a2 /libcrystfel/src/image.c
parent2c9de4119c0fe2338f5f6e54ee91294e3f0f6a74 (diff)
Move image structure creation up to image_read()
Diffstat (limited to 'libcrystfel/src/image.c')
-rw-r--r--libcrystfel/src/image.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index b70b920f..b9450fc0 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -479,27 +479,37 @@ struct image *image_read(DataTemplate *dtempl, const char *filename,
{
struct image *image;
int i;
+ int r;
if ( dtempl == NULL ) {
ERROR("NULL data template!\n");
return NULL;
}
+ image = image_new();
+ if ( image == NULL ) {
+ ERROR("Couldn't allocate image structure.\n");
+ return NULL;
+ }
+
if ( is_hdf5_file(filename) ) {
- image = image_hdf5_read(dtempl, filename, event);
+ r = image_hdf5_read(image, dtempl, filename, event);
} else if ( is_cbf_file(filename) ) {
- image = image_cbf_read(dtempl, filename, event, 0);
+ r = image_cbf_read(image, dtempl, filename, event, 0);
} else if ( is_cbfgz_file(filename) ) {
- image = image_cbf_read(dtempl, filename, event, 1);
+ r = image_cbf_read(image, dtempl, filename, event, 1);
} else {
ERROR("Unrecognised file type: %s\n", filename);
- return NULL;
+ r = 1;
}
- if ( image == NULL ) return NULL;
+ if ( r ) {
+ image_free(image);
+ return NULL;
+ }
/* Wavelength might be needed to create detgeom (adu_per_eV) */
image->lambda = convert_to_m(get_value(image,