From d3ec66174fbfcb3780e106ca25134fd58a45506c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 15 Nov 2011 17:19:47 +0100 Subject: Remove libcrystfel dependency on GTK et al. --- src/dw-hdfsee.c | 1 + src/hdfsee-render.c | 317 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/hdfsee-render.h | 37 ++++++ 3 files changed, 355 insertions(+) create mode 100644 src/hdfsee-render.c create mode 100644 src/hdfsee-render.h (limited to 'src') diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 8f42b2d0..54c73711 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -22,6 +22,7 @@ #include #include "dw-hdfsee.h" +#include "hdfsee-render.h" #include "render.h" #include "hdf5-file.h" #include "hdfsee.h" diff --git a/src/hdfsee-render.c b/src/hdfsee-render.c new file mode 100644 index 00000000..bb29638a --- /dev/null +++ b/src/hdfsee-render.c @@ -0,0 +1,317 @@ +/* + * hdfsee-render.c + * + * Rendering bits for hdfsee + * + * (c) 2006-2011 Thomas White + * + * Part of CrystFEL - crystallography with a FEL + * + */ + +#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 */ diff --git a/src/hdfsee-render.h b/src/hdfsee-render.h new file mode 100644 index 00000000..6202feb5 --- /dev/null +++ b/src/hdfsee-render.h @@ -0,0 +1,37 @@ +/* + * hdfsee-render.h + * + * Rendering bits for hdfsee + * + * (c) 2006-2011 Thomas White + * + * Part of CrystFEL - crystallography with a FEL + * + */ + +#ifndef HDFSEE_RENDER_H +#define HDFSEE_RENDER_H + +#ifdef HAVE_CONFIG_H +#include +#endif + + +#ifdef HAVE_GTK + +#include + +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); + +#endif /* HAVE_GTK */ + + +#endif /* HDFSEE_RENDER_H */ -- cgit v1.2.3