aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-04-28 12:07:59 +0200
committerThomas White <taw@physics.org>2010-04-28 12:07:59 +0200
commitaad3b1798b9ef488e7fb04e2a91f9b46c67d6eb6 (patch)
treeea663fbf7a0f7fd03b681bc4b39f579230cf70f2
parente05ea5a21fc22aefe147d1ec519c4cfe536d6704 (diff)
hdfsee: Add 16-bit TIFF export
-rw-r--r--src/displaywindow.c6
-rw-r--r--src/render.c63
2 files changed, 65 insertions, 4 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 1d737748..d6f47ac5 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -587,11 +587,11 @@ static gint displaywindow_save(GtkWidget *widget, DisplayWindow *dw)
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 (colour, binned)");
+ "PNG - 8 bit RGB (colour, binned, filtered, boosted)");
gtk_combo_box_append_text(GTK_COMBO_BOX(cb),
- "TIFF - Floating point (mono, unbinned)");
+ "TIFF - Floating point (mono, unbinned, filtered, not boosted)");
gtk_combo_box_append_text(GTK_COMBO_BOX(cb),
- "TIFF - 16 bit integer (mono, unbinned)");
+ "TIFF - 16 bit integer (mono, unbinned, filtered, boosted)");
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 627c5233..00fac1ed 100644
--- a/src/render.c
+++ b/src/render.c
@@ -472,5 +472,66 @@ int render_tiff_fp(DisplayWindow *dw, const char *filename)
int render_tiff_int16(DisplayWindow *dw, const char *filename)
{
- return 1;
+ TIFF *th;
+ struct image *image;
+ int16_t *line;
+ int x, y;
+ float max;
+
+ /* 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_INT); /* (signed) */
+ TIFFSetField(th, TIFFTAG_BITSPERSAMPLE, 16);
+ 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));
+ max = 0.0;
+ for ( y=0; y<image->height; y++ ) {
+ for ( x=0;x<image->width; x++ ) {
+ float val;
+ val = image->data[x+image->height*y];
+ if ( val > max ) max = val;
+ }
+ }
+ max /= 32767;
+
+ for ( y=0; y<image->height; y++ ) {
+ for ( x=0;x<image->width; x++ ) {
+
+ float val;
+
+ val = image->data[x+(image->height-1-y)*image->width];
+ val *= ((float)dw->boostint/max);
+
+ /* Clamp to 16-bit range */
+ if ( val > 32767 ) val = 32767;
+ if ( val < -32768 ) val = -32768;
+
+ line[x] = val;
+ }
+
+ TIFFWriteScanline(th, line, y, 0);
+ }
+ _TIFFfree(line);
+
+ TIFFClose(th);
+
+ return 0;
}