From cb47e755858296d59f4ceb373bcd20b045004f56 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 26 Feb 2020 14:20:04 +0100 Subject: Move colour scale and pixbuf rendering to libcrystfel Also, split into two files (colscale and render), and remove TIFF stuff. --- src/geoptimiser.c | 3 +- src/hdfsee-render.c | 419 ---------------------------------------------------- src/hdfsee-render.h | 53 ------- src/render_hkl.c | 2 +- 4 files changed, 2 insertions(+), 475 deletions(-) delete mode 100644 src/hdfsee-render.c delete mode 100644 src/hdfsee-render.h (limited to 'src') diff --git a/src/geoptimiser.c b/src/geoptimiser.c index 233edac4..136cca39 100644 --- a/src/geoptimiser.c +++ b/src/geoptimiser.c @@ -60,8 +60,7 @@ #include "image.h" #include "utils.h" #include "render.h" - -#include "hdfsee-render.h" +#include "colscale.h" struct imagefeature; diff --git a/src/hdfsee-render.c b/src/hdfsee-render.c deleted file mode 100644 index 38f6ddfc..00000000 --- a/src/hdfsee-render.c +++ /dev/null @@ -1,419 +0,0 @@ -/* - * hdfsee-render.c - * - * Rendering bits for hdfsee - * - * Copyright © 2012-2020 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. - * - * Authors: - * 2011-2012,2015 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 - -#include -#include -#include -#include - - -#ifdef HAVE_GDKPIXBUF -#include -#endif - -#ifdef HAVE_TIFF -#include -#endif - -#include -#include - -static float *get_binned_panel(struct image *image, int binning, - int pi, double *max, int *pw, int *ph) -{ - float *data; - int x, y; - int w, h; - struct panel *p = &image->det->panels[pi]; - - /* Some pixels might get discarded */ - w = p->w / binning; - h = p->h / binning; - *pw = w; - *ph = h; - - data = malloc(w*h*sizeof(float)); - - *max = 0.0; - for ( x=0; xdp[pi][fs+ss*p->w]; - total += v; - - if ( (image->bad != NULL) - && (image->bad[pi][fs+ss*p->w]) ) bad = 1; - - } - } - - val = total / ((double)binning * (double)binning); - - if ( bad ) { - data[x+w*y] = -INFINITY; - } else { - data[x+w*y] = val; - if ( val > *max ) *max = val; - } - - } - } - - return data; -} - - -#ifdef HAVE_GDKPIXBUF - -/* 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(float *hdr, int scale, double max, int w, int h) -{ - guchar *data; - int x, y; - - /* Rendered (colourful) version */ - data = malloc(3*w*h); - if ( data == NULL ) return NULL; - - /* These x,y coordinates are measured relative to the bottom-left - * corner */ - for ( y=0; y -INFINITY ) { - - 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; - - } else { - - data[3*( x+w*y )+0] = 30; - data[3*( x+w*y )+1] = 20; - data[3*( x+w*y )+2] = 0; - - } - - } - } - - /* 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; - float **hdrs; - double max; - int *ws, *hs; - - hdrs = calloc(np, sizeof(float *)); - ws = calloc(np, sizeof(int)); - hs = calloc(np, sizeof(int)); - if ( (hdrs == NULL) || (ws == NULL) || (hs == NULL) ) { - *n_pixbufs = 0; - return NULL; - } - - /* Find overall max value for whole image */ - max = 0.0; - for ( i=0; i max ) max = this_max; - } - - max /= boost; - if ( max <= 6 ) { max = 10; } - - pixbufs = calloc(np, sizeof(GdkPixbuf*)); - if ( pixbufs == NULL ) { - *n_pixbufs = 0; - return NULL; - } - - for ( i=0; idet == 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, &p, &dfs, &dss); - if ( invalid ) continue; - - fs = dfs; - ss = dss; /* Explicit rounding */ - - pn = panel_number(image->det, p); - assert(pn != -1); - p = &image->det->panels[pn]; - 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, 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, 0)); - - line = _TIFFmalloc(TIFFScanlineSize(th)); - - for ( y=0; ydet == 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, &p, &dfs, &dss); - if ( invalid ) continue; - - fs = dfs; - ss = dss; /* Explicit rounding */ - - pn = panel_number(image->det, p); - assert(pn != -1); - p = &image->det->panels[pn]; - 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, 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, 0)); - - line = _TIFFmalloc(TIFFScanlineSize(th)); - - for ( y=0; y - * - * 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 . - * - */ - -#ifndef HDFSEE_RENDER_H -#define HDFSEE_RENDER_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_GDKPIXBUF -#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); - -#endif /* HAVE_GDKPIXBUF */ - -extern int render_tiff_fp(struct image *image, const char *filename, int min_x, - int max_x, int min_y, int max_y); - -extern int render_tiff_int16(struct image *image, const char *filename, double boost, - int min_x, int max_x, int min_y, int max_y); - -#endif /* HDFSEE_RENDER_H */ diff --git a/src/render_hkl.c b/src/render_hkl.c index 5f39766c..715bd73c 100644 --- a/src/render_hkl.c +++ b/src/render_hkl.c @@ -47,7 +47,7 @@ #include "utils.h" #include "symmetry.h" -#include "render.h" +#include "colscale.h" #include "render_hkl.h" #include "reflist.h" #include "reflist-utils.h" -- cgit v1.2.3