aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent094d92718b28d35444292bd30306761a91a2f6c8 (diff)
hdfsee: Add floating point TIFF exporter
Diffstat (limited to 'src')
-rw-r--r--src/displaywindow.c9
-rw-r--r--src/render.c41
2 files changed, 46 insertions, 4 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 259cb454..1d737748 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -586,9 +586,12 @@ static gint displaywindow_save(GtkWidget *widget, DisplayWindow *dw)
l = gtk_label_new("Save as type:");
gtk_box_pack_end(GTK_BOX(hbox), GTK_WIDGET(l), FALSE, FALSE, 5);
- gtk_combo_box_append_text(GTK_COMBO_BOX(cb), "PNG - 8 bit RGB");
- gtk_combo_box_append_text(GTK_COMBO_BOX(cb), "TIFF - Floating point");
- gtk_combo_box_append_text(GTK_COMBO_BOX(cb), "TIFF - 16 bit integer");
+ gtk_combo_box_append_text(GTK_COMBO_BOX(cb),
+ "PNG - 8 bit RGB (colour, binned)");
+ gtk_combo_box_append_text(GTK_COMBO_BOX(cb),
+ "TIFF - Floating point (mono, unbinned)");
+ gtk_combo_box_append_text(GTK_COMBO_BOX(cb),
+ "TIFF - 16 bit integer (mono, unbinned)");
gtk_combo_box_set_active(GTK_COMBO_BOX(cb), 0);
cd = malloc(sizeof(*cd));
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;
}