aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-11-15 17:19:47 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:41 +0100
commitd3ec66174fbfcb3780e106ca25134fd58a45506c (patch)
tree1734f11b4149d9d49ff085633ecbe15f3f4cf2d7
parentc4c3127127ce984896c1af10da82e69dca2a632f (diff)
Remove libcrystfel dependency on GTK et al.
-rw-r--r--Makefile.am4
-rw-r--r--Makefile.in16
-rw-r--r--libcrystfel/Makefile.am3
-rw-r--r--libcrystfel/Makefile.in1
-rw-r--r--libcrystfel/src/render.c299
-rw-r--r--libcrystfel/src/render.h22
-rw-r--r--src/dw-hdfsee.c1
-rw-r--r--src/hdfsee-render.c317
-rw-r--r--src/hdfsee-render.h37
9 files changed, 371 insertions, 329 deletions
diff --git a/Makefile.am b/Makefile.am
index 513a11ea..cbf0aec6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,7 +50,7 @@ src_process_hkl_SOURCES = src/process_hkl.c
src_indexamajig_SOURCES = src/indexamajig.c
if BUILD_HDFSEE
-src_hdfsee_SOURCES = src/hdfsee.c src/dw-hdfsee.c
+src_hdfsee_SOURCES = src/hdfsee.c src/dw-hdfsee.c src/hdfsee-render.c
endif
src_get_hkl_SOURCES = src/get_hkl.c
@@ -88,7 +88,7 @@ INCLUDES = -I$(top_srcdir)/libcrystfel/src -I$(top_srcdir)/data
EXTRA_DIST += src/dw-hdfsee.h src/hdfsee.h src/render_hkl.h \
src/post-refinement.h src/hrs-scaling.h src/scaling-report.h \
- src/cl-utils.h
+ src/cl-utils.h src/hdfsee-render.h
crystfeldir = $(datadir)/crystfel
crystfel_DATA = data/diffraction.cl data/hdfsee.ui
diff --git a/Makefile.in b/Makefile.in
index 56dbddd8..8f6f65ed 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -116,9 +116,11 @@ src_get_hkl_OBJECTS = $(am_src_get_hkl_OBJECTS)
src_get_hkl_LDADD = $(LDADD)
src_get_hkl_DEPENDENCIES = $(top_builddir)/lib/libgnu.a \
$(top_builddir)/libcrystfel/libcrystfel.la
-am__src_hdfsee_SOURCES_DIST = src/hdfsee.c src/dw-hdfsee.c
+am__src_hdfsee_SOURCES_DIST = src/hdfsee.c src/dw-hdfsee.c \
+ src/hdfsee-render.c
@BUILD_HDFSEE_TRUE@am_src_hdfsee_OBJECTS = src/hdfsee.$(OBJEXT) \
-@BUILD_HDFSEE_TRUE@ src/dw-hdfsee.$(OBJEXT)
+@BUILD_HDFSEE_TRUE@ src/dw-hdfsee.$(OBJEXT) \
+@BUILD_HDFSEE_TRUE@ src/hdfsee-render.$(OBJEXT)
src_hdfsee_OBJECTS = $(am_src_hdfsee_OBJECTS)
src_hdfsee_LDADD = $(LDADD)
src_hdfsee_DEPENDENCIES = $(top_builddir)/lib/libgnu.a \
@@ -555,8 +557,8 @@ EXTRA_DIST = configure m4/gnulib-cache.m4 tests/first_merge_check \
tests/third_merge_check.hkl tests/fourth_merge_check.hkl \
src/dw-hdfsee.h src/hdfsee.h src/render_hkl.h \
src/post-refinement.h src/hrs-scaling.h src/scaling-report.h \
- src/cl-utils.h $(crystfel_DATA) doc/twin-calculator.pdf \
- doc/examples/lcls-dec.geom \
+ src/cl-utils.h src/hdfsee-render.h $(crystfel_DATA) \
+ doc/twin-calculator.pdf doc/examples/lcls-dec.geom \
doc/examples/lcls-june-r0013-r0128.geom \
doc/examples/lcls-xpp-estimate.geom doc/examples/simple.geom \
doc/examples/lcls-dec.beam doc/examples/lcls-june.beam \
@@ -584,7 +586,7 @@ src_pattern_sim_SOURCES = src/pattern_sim.c src/diffraction.c \
src_process_hkl_SOURCES = src/process_hkl.c
src_indexamajig_SOURCES = src/indexamajig.c
-@BUILD_HDFSEE_TRUE@src_hdfsee_SOURCES = src/hdfsee.c src/dw-hdfsee.c
+@BUILD_HDFSEE_TRUE@src_hdfsee_SOURCES = src/hdfsee.c src/dw-hdfsee.c src/hdfsee-render.c
src_get_hkl_SOURCES = src/get_hkl.c
src_compare_hkl_SOURCES = src/compare_hkl.c
src_check_hkl_SOURCES = src/check_hkl.c
@@ -764,6 +766,8 @@ src/hdfsee.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
src/dw-hdfsee.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
+src/hdfsee-render.$(OBJEXT): src/$(am__dirstamp) \
+ src/$(DEPDIR)/$(am__dirstamp)
src/hdfsee$(EXEEXT): $(src_hdfsee_OBJECTS) $(src_hdfsee_DEPENDENCIES) src/$(am__dirstamp)
@rm -f src/hdfsee$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(src_hdfsee_OBJECTS) $(src_hdfsee_LDADD) $(LIBS)
@@ -856,6 +860,7 @@ mostlyclean-compile:
-rm -f src/diffraction.$(OBJEXT)
-rm -f src/dw-hdfsee.$(OBJEXT)
-rm -f src/get_hkl.$(OBJEXT)
+ -rm -f src/hdfsee-render.$(OBJEXT)
-rm -f src/hdfsee.$(OBJEXT)
-rm -f src/hrs-scaling.$(OBJEXT)
-rm -f src/indexamajig.$(OBJEXT)
@@ -884,6 +889,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/diffraction.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dw-hdfsee.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/get_hkl.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/hdfsee-render.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/hdfsee.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/hrs-scaling.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/indexamajig.Po@am__quote@
diff --git a/libcrystfel/Makefile.am b/libcrystfel/Makefile.am
index 40846412..e813699b 100644
--- a/libcrystfel/Makefile.am
+++ b/libcrystfel/Makefile.am
@@ -1,4 +1,5 @@
-lib_LTLIBRARIES = libcrystfel.la
+lib_LTLIBRARIES = libcrystfel.la
+LDADD = $(top_builddir)/lib/libgnu.a @IGNORE_UNUSED_LIBRARIES_CFLAGS@
libcrystfel_la_SOURCES = src/reflist.c src/utils.c src/cell.c src/detector.c \
src/thread-pool.c src/image.c src/hdf5-file.c \
diff --git a/libcrystfel/Makefile.in b/libcrystfel/Makefile.in
index 0a03ee42..e02c47a7 100644
--- a/libcrystfel/Makefile.in
+++ b/libcrystfel/Makefile.in
@@ -346,6 +346,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
lib_LTLIBRARIES = libcrystfel.la
+LDADD = $(top_builddir)/lib/libgnu.a @IGNORE_UNUSED_LIBRARIES_CFLAGS@
libcrystfel_la_SOURCES = src/reflist.c src/utils.c src/cell.c src/detector.c \
src/thread-pool.c src/image.c src/hdf5-file.c \
src/beam-parameters.c src/geometry.c src/statistics.c \
diff --git a/libcrystfel/src/render.c b/libcrystfel/src/render.c
index dbaca2fd..896d3eca 100644
--- a/libcrystfel/src/render.c
+++ b/libcrystfel/src/render.c
@@ -14,18 +14,10 @@
#endif
-#ifdef HAVE_GTK
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#endif
-
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
-#ifdef HAVE_TIFF
-#include <tiffio.h>
-#endif
-
#include "hdf5-file.h"
#include "render.h"
@@ -149,294 +141,3 @@ void render_scale(double val, double max, int scale,
break;
}
}
-
-
-#ifdef HAVE_GTK
-
-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; x<w; x++ ) {
- for ( y=0; y<h; y++ ) {
-
- double total;
- size_t xb, yb;
-
- total = 0;
- for ( xb=0; xb<binning; xb++ ) {
- for ( yb=0; yb<binning; yb++ ) {
-
- double v;
- v = in[binning*x+xb+min_fs + (binning*y+yb+min_ss)*fw];
- total += v;
-
- }
- }
-
- data[x+w*y] = total / ((double)binning * (double)binning);
-
- }
- }
-
- return data;
-}
-
-
-/* NB This function is shared between render_get_image() and
- * render_get_colour_scale() */
-static void render_free_data(guchar *data, gpointer p)
-{
- free(data);
-}
-
-
-static GdkPixbuf *render_panel(struct image *image,
- int binning, int scale, double boost,
- int min_fs, int max_fs, int min_ss, int max_ss)
-{
- int w, h;
- guchar *data;
- float *hdr;
- int x, y;
- double max;
- int pw, ph;
- int i;
-
- /* Calculate panel width and height
- * (add one because min and max are inclusive) */
- pw = max_fs - min_fs + 1;
- ph = max_ss - min_ss + 1;
- w = pw / binning;
- h = ph / binning;
-
- /* High dynamic range version */
- max = 0.0;
- for ( i=0; i<image->width*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; y<h; y++ ) {
- for ( x=0; x<w; x++ ) {
-
- double val;
- double r, g, b;
-
- val = hdr[x+w*y];
- render_scale(val, max, scale, &r, &g, &b);
-
- /* Stuff inside square brackets makes this pixel go to
- * the expected location in the pixbuf (which measures
- * from the top-left corner */
- data[3*( x+w*y )+0] = 255*r;
- data[3*( x+w*y )+1] = 255*g;
- data[3*( x+w*y )+2] = 255*b;
-
- }
- }
-
- /* Finished with this */
- free(hdr);
-
- /* Create the pixbuf from the 8-bit display data */
- return gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, FALSE, 8,
- w, h, w*3, render_free_data, NULL);
-
-}
-
-
-/* Render an image into multiple pixbufs according to geometry */
-GdkPixbuf **render_panels(struct image *image,
- int binning, int scale, double boost,
- int *n_pixbufs)
-{
- int i;
- int np = image->det->n_panels;
- GdkPixbuf **pixbufs;
-
- pixbufs = calloc(np, sizeof(GdkPixbuf*));
- if ( pixbufs == NULL ) {
- *n_pixbufs = 0;
- return NULL;
- }
-
- for ( i=0; i<np; i++ ) {
-
- pixbufs[i] = render_panel(image, binning, scale, boost,
- image->det->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; y<h; y++ ) {
-
- double r, g, b;
- int val;
-
- val = y;
-
- render_scale(val, max, scale, &r, &g, &b);
-
- data[3*( 0+w*(h-1-y) )+0] = 0;
- data[3*( 0+w*(h-1-y) )+1] = 0;
- data[3*( 0+w*(h-1-y) )+2] = 0;
- for ( x=1; x<w; x++ ) {
- data[3*( x+w*(h-1-y) )+0] = 255*r;
- data[3*( x+w*(h-1-y) )+1] = 255*g;
- data[3*( x+w*(h-1-y) )+2] = 255*b;
- }
-
- }
-
- return gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, FALSE, 8,
- w, h, w*3, render_free_data, NULL);
-}
-
-
-int render_tiff_fp(struct image *image, const char *filename)
-{
-#ifdef HAVE_TIFF
- TIFF *th;
- float *line;
- int y;
-
- 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_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; y<image->height; 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; y<image->height; y++ ) {
- for ( x=0;x<image->width; x++ ) {
- double val;
- val = image->data[x+image->height*y];
- if ( val > max ) max = val;
- }
- }
- max /= 32767.0;
-
- for ( y=0; y<image->height; y++ ) {
- for ( x=0;x<image->width; 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/libcrystfel/src/render.h b/libcrystfel/src/render.h
index fbfbbdb2..f456616f 100644
--- a/libcrystfel/src/render.h
+++ b/libcrystfel/src/render.h
@@ -18,10 +18,6 @@
#define RENDER_H
-#include <stddef.h>
-
-#include "image.h"
-
enum {
SCALE_COLOUR,
SCALE_MONO,
@@ -34,22 +30,4 @@ extern void render_scale(double val, double max, int scale,
double *rp, double *gp, double *bp);
-#ifdef HAVE_GTK
-
-#include <gdk-pixbuf/gdk-pixbuf.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);
-
-#endif /* HAVE_GTK */
-
-
-
#endif /* RENDER_H */
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 <gdk-pixbuf/gdk-pixbuf.h>
#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 <taw@physics.org>
+ *
+ * Part of CrystFEL - crystallography with a FEL
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_GTK
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include <stdlib.h>
+#include <math.h>
+#include <stdint.h>
+
+#ifdef HAVE_TIFF
+#include <tiffio.h>
+#endif
+
+#include <render.h>
+#include <image.h>
+
+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; x<w; x++ ) {
+ for ( y=0; y<h; y++ ) {
+
+ double total;
+ size_t xb, yb;
+
+ total = 0;
+ for ( xb=0; xb<binning; xb++ ) {
+ for ( yb=0; yb<binning; yb++ ) {
+
+ double v;
+ v = in[binning*x+xb+min_fs + (binning*y+yb+min_ss)*fw];
+ total += v;
+
+ }
+ }
+
+ data[x+w*y] = total / ((double)binning * (double)binning);
+
+ }
+ }
+
+ return data;
+}
+
+
+/* NB This function is shared between render_get_image() and
+ * render_get_colour_scale() */
+static void render_free_data(guchar *data, gpointer p)
+{
+ free(data);
+}
+
+
+static GdkPixbuf *render_panel(struct image *image,
+ int binning, int scale, double boost,
+ int min_fs, int max_fs, int min_ss, int max_ss)
+{
+ int w, h;
+ guchar *data;
+ float *hdr;
+ int x, y;
+ double max;
+ int pw, ph;
+ int i;
+
+ /* Calculate panel width and height
+ * (add one because min and max are inclusive) */
+ pw = max_fs - min_fs + 1;
+ ph = max_ss - min_ss + 1;
+ w = pw / binning;
+ h = ph / binning;
+
+ /* High dynamic range version */
+ max = 0.0;
+ for ( i=0; i<image->width*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; y<h; y++ ) {
+ for ( x=0; x<w; x++ ) {
+
+ double val;
+ double r, g, b;
+
+ val = hdr[x+w*y];
+ render_scale(val, max, scale, &r, &g, &b);
+
+ /* Stuff inside square brackets makes this pixel go to
+ * the expected location in the pixbuf (which measures
+ * from the top-left corner */
+ data[3*( x+w*y )+0] = 255*r;
+ data[3*( x+w*y )+1] = 255*g;
+ data[3*( x+w*y )+2] = 255*b;
+
+ }
+ }
+
+ /* Finished with this */
+ free(hdr);
+
+ /* Create the pixbuf from the 8-bit display data */
+ return gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, FALSE, 8,
+ w, h, w*3, render_free_data, NULL);
+
+}
+
+
+/* Render an image into multiple pixbufs according to geometry */
+GdkPixbuf **render_panels(struct image *image,
+ int binning, int scale, double boost,
+ int *n_pixbufs)
+{
+ int i;
+ int np = image->det->n_panels;
+ GdkPixbuf **pixbufs;
+
+ pixbufs = calloc(np, sizeof(GdkPixbuf*));
+ if ( pixbufs == NULL ) {
+ *n_pixbufs = 0;
+ return NULL;
+ }
+
+ for ( i=0; i<np; i++ ) {
+
+ pixbufs[i] = render_panel(image, binning, scale, boost,
+ image->det->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; y<h; y++ ) {
+
+ double r, g, b;
+ int val;
+
+ val = y;
+
+ render_scale(val, max, scale, &r, &g, &b);
+
+ data[3*( 0+w*(h-1-y) )+0] = 0;
+ data[3*( 0+w*(h-1-y) )+1] = 0;
+ data[3*( 0+w*(h-1-y) )+2] = 0;
+ for ( x=1; x<w; x++ ) {
+ data[3*( x+w*(h-1-y) )+0] = 255*r;
+ data[3*( x+w*(h-1-y) )+1] = 255*g;
+ data[3*( x+w*(h-1-y) )+2] = 255*b;
+ }
+
+ }
+
+ return gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, FALSE, 8,
+ w, h, w*3, render_free_data, NULL);
+}
+
+
+int render_tiff_fp(struct image *image, const char *filename)
+{
+#ifdef HAVE_TIFF
+ TIFF *th;
+ float *line;
+ int y;
+
+ 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_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; y<image->height; 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; y<image->height; y++ ) {
+ for ( x=0;x<image->width; x++ ) {
+ double val;
+ val = image->data[x+image->height*y];
+ if ( val > max ) max = val;
+ }
+ }
+ max /= 32767.0;
+
+ for ( y=0; y<image->height; y++ ) {
+ for ( x=0;x<image->width; 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 <taw@physics.org>
+ *
+ * Part of CrystFEL - crystallography with a FEL
+ *
+ */
+
+#ifndef HDFSEE_RENDER_H
+#define HDFSEE_RENDER_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#ifdef HAVE_GTK
+
+#include <gdk-pixbuf/gdk-pixbuf.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);
+
+#endif /* HAVE_GTK */
+
+
+#endif /* HDFSEE_RENDER_H */