aboutsummaryrefslogtreecommitdiff
path: root/src/render.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-04-28 11:41:06 +0200
committerThomas White <taw@physics.org>2010-04-28 11:41:06 +0200
commite05ea5a21fc22aefe147d1ec519c4cfe536d6704 (patch)
tree565de60bdf19d9d4b6e2d70153ebf5c9ea4fcd05 /src/render.c
parent094d92718b28d35444292bd30306761a91a2f6c8 (diff)
hdfsee: Add floating point TIFF exporter
Diffstat (limited to 'src/render.c')
-rw-r--r--src/render.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/render.c b/src/render.c
index e0189b0a..627c5233 100644
--- a/src/render.c
+++ b/src/render.c
@@ -18,6 +18,7 @@
#include <math.h>
#include <stdint.h>
#include <png.h>
+#include <tiffio.h>
#include "hdf5-file.h"
#include "render.h"
@@ -427,7 +428,45 @@ int render_png(DisplayWindow *dw, const char *filename)
int render_tiff_fp(DisplayWindow *dw, const char *filename)
{
- return 1;
+ TIFF *th;
+ struct image *image;
+ float *line;
+ int y;
+
+ /* Get raw, unbinned image data */
+ image = malloc(sizeof(struct image));
+ if ( image == NULL ) return 1;
+ image->features = NULL;
+ image->data = NULL;
+ hdf5_read(dw->hdfile, image);
+ if ( dw->cmfilter ) filter_cm(image);
+ if ( dw->noisefilter ) filter_noise(image, NULL);
+
+ th = TIFFOpen(filename, "w");
+ if ( th == NULL ) return 1;
+
+ TIFFSetField(th, TIFFTAG_IMAGEWIDTH, image->width);
+ TIFFSetField(th, TIFFTAG_IMAGELENGTH, image->height);
+ TIFFSetField(th, TIFFTAG_SAMPLESPERPIXEL, 1);
+ TIFFSetField(th, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
+ TIFFSetField(th, TIFFTAG_BITSPERSAMPLE, 32);
+ TIFFSetField(th, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
+ TIFFSetField(th, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
+ TIFFSetField(th, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ TIFFSetField(th, TIFFTAG_ROWSPERSTRIP,
+ TIFFDefaultStripSize(th, image->width*4));
+
+ line = _TIFFmalloc(TIFFScanlineSize(th));
+ for ( y=0; y<image->height; y++ ) {
+ memcpy(line, &image->data[(image->height-1-y)*image->width],
+ image->width*4);
+ TIFFWriteScanline(th, line, y, 0);
+ }
+ _TIFFfree(line);
+
+ TIFFClose(th);
+
+ return 0;
}