aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2010-01-15 16:35:02 +0100
committerThomas White <taw@bitwiz.org.uk>2010-01-16 14:19:26 +0100
commit094e18eed46ea514ca108f0c3dfc602f0e5eeb0c (patch)
treef2a6ed104f07fffe3c6615c85ccd053f083ad576
parent6e1012c31081a4e41cef2a0088750d03f5d49491 (diff)
Better handling of image switching
-rw-r--r--src/hdf5-file.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index bc7552ec..4406ce63 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -29,6 +29,7 @@ struct hdfile {
const char *path; /* Current data path */
struct image *image;
+ int image_dirty;
size_t nx; /* Image width */
size_t ny; /* Image height */
@@ -54,6 +55,8 @@ struct hdfile *hdfile_open(const char *filename)
return NULL;
}
+ f->image_dirty = 1;
+
return f;
}
@@ -80,6 +83,8 @@ int hdfile_set_image(struct hdfile *f, const char *path)
f->nx = size[0];
f->ny = size[1];
+ f->image_dirty = 1;
+
return 0;
}
@@ -150,13 +155,21 @@ int16_t *hdfile_get_image_binned(struct hdfile *f, int binning, int16_t *max)
struct image *image;
int16_t *data;
- if ( f->image == NULL ) {
+ if ( (f->image == NULL) || (f->image_dirty) ) {
image = malloc(sizeof(struct image));
if ( image == NULL ) return NULL;
image->features = NULL;
hdf5_read(f, image);
+
+ /* Deal with the old image, if existing */
+ if ( f->image != NULL ) {
+ image->features = f->image->features;
+ if ( f->image->data != NULL ) free(f->image->data);
+ free(f->image);
+ }
+
f->image = image;
}
@@ -265,6 +278,8 @@ int hdf5_read(struct hdfile *f, struct image *image)
image->camera_len = 75.0e-3; /* 75 mm camera length */
image->resolution = 13333.3; /* 75 micron pixel size */
+ f->image_dirty = 0;
+
return 0;
}