/* * hdfsee-render.c * * Rendering bits for hdfsee * * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2011-2012 Thomas White * * This file is part of CrystFEL. * * CrystFEL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CrystFEL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrystFEL. If not, see . * */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_GTK #include #include #include #include #ifdef HAVE_TIFF #include #endif #include #include static float *get_binned_panel(struct image *image, int binning, int min_fs, int max_fs, int min_ss, int max_ss) { float *data; int x, y; int w, h; int fw; float *in; fw = image->width; in = image->data; /* Some pixels might get discarded */ w = (max_fs - min_fs + 1) / binning; h = (max_ss - min_ss + 1) / binning; data = malloc(w*h*sizeof(float)); for ( x=0; xwidth*image->height; i++ ) { if ( image->data[i] > max ) max = image->data[i]; } hdr = get_binned_panel(image, binning, min_fs, max_fs, min_ss, max_ss); if ( hdr == NULL ) return NULL; /* Rendered (colourful) version */ data = malloc(3*w*h); if ( data == NULL ) { free(hdr); return NULL; } max /= boost; if ( max <= 6 ) { max = 10; } /* These x,y coordinates are measured relative to the bottom-left * corner */ for ( y=0; ydet->n_panels; GdkPixbuf **pixbufs; pixbufs = calloc(np, sizeof(GdkPixbuf*)); if ( pixbufs == NULL ) { *n_pixbufs = 0; return NULL; } for ( i=0; idet->panels[i].min_fs, image->det->panels[i].max_fs, image->det->panels[i].min_ss, image->det->panels[i].max_ss); } *n_pixbufs = np; return pixbufs; } GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale) { guchar *data; size_t x, y; int max; data = malloc(3*w*h); if ( data == NULL ) return NULL; max = h; for ( y=0; ywidth); 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; yheight; y++ ) { memcpy(line, &image->data[(image->height-1-y)*image->width], image->width*4); TIFFWriteScanline(th, line, y, 0); } _TIFFfree(line); TIFFClose(th); #else STATUS("No TIFF support.\n"); #endif return 0; } int render_tiff_int16(struct image *image, const char *filename, double boost) { #ifdef HAVE_TIFF TIFF *th; int16_t *line; int x, y; double max; 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; yheight; y++ ) { for ( x=0;xwidth; x++ ) { double val; val = image->data[x+image->height*y]; 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 *= ((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); } _TIFFfree(line); TIFFClose(th); #else STATUS("No TIFF support.\n"); #endif return 0; } #endif /* HAVE_GTK */