From 938b9627b3f0c5665f1bf21b67f6ed3b277f1621 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 3 Nov 2015 14:40:04 +0100 Subject: hdfsee: Restore TIFF output --- src/dw-hdfsee.c | 14 ++--- src/hdfsee-render.c | 168 ++++++++++++++++++++++++++++++++++++---------------- src/hdfsee-render.h | 15 +++-- 3 files changed, 132 insertions(+), 65 deletions(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 6946e63a..2911e49c 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1650,7 +1650,7 @@ static gint displaywindow_save_response(GtkWidget *d, gint response, "Therefore, it can't be saved as TIFF."); r = 0; } else { - r = render_tiff_fp(dw->image, file); + r = render_tiff_fp(dw, dw->image, file); } } else if ( type == 2 ) { if ( !single_panel_data_source(dw->image->det, NULL) ) { @@ -1659,7 +1659,7 @@ static gint displaywindow_save_response(GtkWidget *d, gint response, "Therefore, it can't be saved as TIFF."); r = 0; } else { - r = render_tiff_int16(dw->image, file, + r = render_tiff_int16(dw, dw->image, file, dw->boostint); } } else if ( type == 3 ) { @@ -1727,15 +1727,13 @@ 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, filtered, boosted)"); + "PNG (colour)"); gtk_combo_box_append_text(GTK_COMBO_BOX(cb), - "TIFF - Floating point (mono, unbinned, filtered, not boosted)"); + "TIFF (floating point)"); gtk_combo_box_append_text(GTK_COMBO_BOX(cb), - "TIFF - 16 bit signed integer " - "(mono, unbinned, filtered, boosted)"); + "TIFF (16 bit signed integer)"); gtk_combo_box_append_text(GTK_COMBO_BOX(cb), - "ADSC - 16 bit unsigned integer " - "(unbinned, filtered, not boosted)"); + "ADSC (16 bit unsigned integer)"); gtk_combo_box_set_active(GTK_COMBO_BOX(cb), 0); cd = malloc(sizeof(*cd)); diff --git a/src/hdfsee-render.c b/src/hdfsee-render.c index 4c6c3114..a64832a0 100644 --- a/src/hdfsee-render.c +++ b/src/hdfsee-render.c @@ -3,11 +3,11 @@ * * Rendering bits for hdfsee * - * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2011-2012,2014 Thomas White + * 2011-2012,2015 Thomas White * * This file is part of CrystFEL. * @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef HAVE_TIFF #include @@ -45,6 +46,8 @@ #include #include +#include "dw-hdfsee.h" + static float *get_binned_panel(struct image *image, int binning, int pi, double *max, int *pw, int *ph) { @@ -260,38 +263,78 @@ GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale) } -int render_tiff_fp(struct image *image, const char *filename) +int render_tiff_fp(DisplayWindow *dw, struct image *image, const char *filename) { #ifdef HAVE_TIFF TIFF *th; - float *line; - int y; + int16_t *line; + int x, y; + int min_x = (int)dw->min_x; + int max_x = (int)dw->max_x; + int min_y = (int)dw->min_y; + int max_y = (int)dw->max_y; + int width = max_x - min_x; + int height = max_y - min_y; + float *buf; + + if ( image == NULL ) return 1; + if ( image->det == NULL ) return 1; + if ( image->det->n_panels == 0 ) return 1; + + buf = calloc(width * height, sizeof(float)); + if ( buf == NULL ) return 1; + + /* Prepare image data */ + for ( y=min_y; ydet); + if ( invalid ) continue; + + fs = dfs; + ss = dss; /* Explicit rounding */ + + pn = find_panel_number(image->det, fs, ss); + assert(pn != -1); + p = &image->det->panels[pn]; + fs -= p->min_fs; + ss -= p->min_ss; + val = image->dp[pn][fs + p->w* ss]; + + buf[(x - min_x) + (y - min_y) * width] = val; + + } + } th = TIFFOpen(filename, "w"); if ( th == NULL ) return 1; - TIFFSetField(th, TIFFTAG_IMAGEWIDTH, image->width); - TIFFSetField(th, TIFFTAG_IMAGELENGTH, image->height); + TIFFSetField(th, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(th, TIFFTAG_IMAGELENGTH, 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)); + TIFFSetField(th, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(th, 0)); line = _TIFFmalloc(TIFFScanlineSize(th)); - for ( y=0; yheight; y++ ) { - //memcpy(line, &image->data[(image->height-1-y)*image->width], - // image->width*4); - // FIXME! - TIFFWriteScanline(th, line, y, 0); + + for ( y=0; ymin_x; + int max_x = (int)dw->max_x; + int min_y = (int)dw->min_y; + int max_y = (int)dw->max_y; + int width = max_x - min_x; + int height = max_y - min_y; + int16_t *buf; + + if ( image == NULL ) return 1; + if ( image->det == NULL ) return 1; + if ( image->det->n_panels == 0 ) return 1; + + buf = calloc(width * height, sizeof(int16_t)); + if ( buf == NULL ) return 1; + + /* Prepare image data */ + for ( y=min_y; ydet); + if ( invalid ) continue; + + fs = dfs; + ss = dss; /* Explicit rounding */ + + pn = find_panel_number(image->det, fs, ss); + assert(pn != -1); + p = &image->det->panels[pn]; + fs -= p->min_fs; + ss -= p->min_ss; + val = image->dp[pn][fs + p->w* ss]; + + if ( val < -32767 ) { + out = -32767; + } else if ( val > 32767 ) { + out = 32767; + } else { + out = val; + } + + buf[(x - min_x) + (y - min_y) * width] = out; + + } + } th = TIFFOpen(filename, "w"); if ( th == NULL ) return 1; - TIFFSetField(th, TIFFTAG_IMAGEWIDTH, image->width); - TIFFSetField(th, TIFFTAG_IMAGELENGTH, image->height); + TIFFSetField(th, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(th, TIFFTAG_IMAGELENGTH, 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)); + TIFFSetField(th, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(th, 0)); line = _TIFFmalloc(TIFFScanlineSize(th)); - max = 0.0; - for ( y=0; yheight; y++ ) { - for ( x=0;xwidth; x++ ) { - double val; - //val = image->data[x+image->height*y]; - val = 0.0; // FIXME! - if ( val > max ) max = val; - } - } - max /= 32767.0; - - for ( y=0; yheight; y++ ) { - for ( x=0;xwidth; x++ ) { - - double val; - - //val = image->data[x+(image->height-1-y)*image->width]; - val = 0.0; // FIXME! - val *= ((double)boost/max); - - /* Clamp to 16-bit range, - * and work round inability of most readers to deal - * with signed integers. */ - val += 1000.0; - if ( val > 32767.0 ) val = 32767.0; - if ( val < 0.0 ) val = 0.0; - - line[x] = val; - } - TIFFWriteScanline(th, line, y, 0); + for ( y=0; y + * 2011-2015 Thomas White * * This file is part of CrystFEL. * @@ -38,15 +38,18 @@ #include +#include "dw-hdfsee.h" + extern GdkPixbuf **render_panels(struct image *image, int binning, int scale, double boost, int *n_pixbufs); extern GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale); -extern int render_tiff_fp(struct image *image, const char *filename); -extern int render_tiff_int16(struct image *image, const char *filename, - double boost); +extern int render_tiff_fp(DisplayWindow *dw, struct image *image, + const char *filename); +extern int render_tiff_int16(DisplayWindow *dw, struct image *image, + const char *filename, double boost); #endif /* HAVE_GTK */ -- cgit v1.2.3