diff options
author | Thomas White <taw@physics.org> | 2010-04-28 12:07:59 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2010-04-28 12:07:59 +0200 |
commit | aad3b1798b9ef488e7fb04e2a91f9b46c67d6eb6 (patch) | |
tree | ea663fbf7a0f7fd03b681bc4b39f579230cf70f2 /src/render.c | |
parent | e05ea5a21fc22aefe147d1ec519c4cfe536d6704 (diff) |
hdfsee: Add 16-bit TIFF export
Diffstat (limited to 'src/render.c')
-rw-r--r-- | src/render.c | 63 |
1 files changed, 62 insertions, 1 deletions
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; } |