From 4dae413b8134c937e848c54fbdbdf6603bb17bb2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 18 Sep 2010 15:44:36 +0200 Subject: cubeit: Reinstate output --- src/cubeit.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) (limited to 'src') diff --git a/src/cubeit.c b/src/cubeit.c index ff6b18c6..53194c66 100644 --- a/src/cubeit.c +++ b/src/cubeit.c @@ -23,10 +23,12 @@ #include #include #include +#include #include "utils.h" #include "hdf5-file.h" #include "diffraction.h" +#include "render.h" #define MAX_THREADS (256) @@ -277,6 +279,112 @@ static void *worker_thread(void *pargsv) } +static void write_slice(const char *filename, double *vals, int z, + int xs, int ys, int zs, double boost) +{ +#ifdef HAVE_LIBPNG + FILE *fh; + png_structp png_ptr; + png_infop info_ptr; + png_bytep *row_pointers; + int x, y; + float max = 0.0; + int w, h; + + w = xs; + h = ys; + + for ( y=0; y max ) max = val; + + } + } + + fh = fopen(filename, "wb"); + if ( !fh ) { + ERROR("Couldn't open output file.\n"); + return; + } + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + if ( !png_ptr ) { + ERROR("Couldn't create PNG write structure.\n"); + fclose(fh); + return; + } + info_ptr = png_create_info_struct(png_ptr); + if ( !info_ptr ) { + png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + ERROR("Couldn't create PNG info structure.\n"); + fclose(fh); + return; + } + if ( setjmp(png_jmpbuf(png_ptr)) ) { + png_destroy_write_struct(&png_ptr, &info_ptr); + fclose(fh); + ERROR("PNG write failed.\n"); + return; + } + png_init_io(png_ptr, fh); + + png_set_IHDR(png_ptr, info_ptr, w, h, 8, + PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + row_pointers = malloc(h*sizeof(png_bytep *)); + + /* Write the image data */ + max /= boost; + if ( max <= 6 ) { max = 10; } + + for ( y=0; y