aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in5
-rw-r--r--src/render.c134
-rw-r--r--src/render.h3
-rw-r--r--src/render_hkl.c40
5 files changed, 93 insertions, 91 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8d4cdec2..8c78fc48 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,7 +47,7 @@ powder_plot_SOURCES = powder_plot.c cell.c utils.c image.c hdf5-file.c \
powder_plot_LDADD = @LIBS@
render_hkl_SOURCES = render_hkl.c cell.c reflections.c utils.c povray.c \
- symmetry.c
+ symmetry.c render.c hdf5-file.c image.c filters.c
render_hkl_LDADD = @LIBS@
calibrate_detector_SOURCES = calibrate_detector.c utils.c hdf5-file.c image.c \
diff --git a/src/Makefile.in b/src/Makefile.in
index 5de55c96..31de7f83 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -109,7 +109,8 @@ process_hkl_OBJECTS = $(am_process_hkl_OBJECTS)
process_hkl_DEPENDENCIES =
am_render_hkl_OBJECTS = render_hkl.$(OBJEXT) cell.$(OBJEXT) \
reflections.$(OBJEXT) utils.$(OBJEXT) povray.$(OBJEXT) \
- symmetry.$(OBJEXT)
+ symmetry.$(OBJEXT) render.$(OBJEXT) hdf5-file.$(OBJEXT) \
+ image.$(OBJEXT) filters.$(OBJEXT)
render_hkl_OBJECTS = $(am_render_hkl_OBJECTS)
render_hkl_DEPENDENCIES =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -263,7 +264,7 @@ powder_plot_SOURCES = powder_plot.c cell.c utils.c image.c hdf5-file.c \
powder_plot_LDADD = @LIBS@
render_hkl_SOURCES = render_hkl.c cell.c reflections.c utils.c povray.c \
- symmetry.c
+ symmetry.c render.c hdf5-file.c image.c filters.c
render_hkl_LDADD = @LIBS@
calibrate_detector_SOURCES = calibrate_detector.c utils.c hdf5-file.c image.c \
diff --git a/src/render.c b/src/render.c
index df2e288f..606f090a 100644
--- a/src/render.c
+++ b/src/render.c
@@ -101,12 +101,11 @@ float *render_get_image_binned(DisplayWindow *dw, int binning, float *max)
}
-static inline void render_rgb(float val, float max,
- guchar *rp, guchar *gp, guchar *bp)
+static void render_rgb(float val, float max, float *rp, float *gp, float *bp)
{
int s;
float p;
- guchar r, g, b;
+ float r, g, b;
s = val / (max/6);
p = fmod(val, max/6);
@@ -123,31 +122,31 @@ static inline void render_rgb(float val, float max,
}
switch ( s ) {
case 0 : { /* Black to blue */
- r = 0; g = 0; b = p*255;
+ r = 0; g = 0; b = p;
break;
}
case 1 : { /* Blue to pink */
- r = 255*p; g = 0; b = 255;
+ r = p; g = 0; b = 1.0;
break;
}
case 2 : { /* Pink to red */
- r = 255; g = 0; b = (1-p)*255;
+ r = 1.0; g = 0; b = (1.0-p)*1.0;
break;
}
case 3 : { /* Red to Orange */
- r = 255; g = 127*p; b = 0;
+ r = 1.0; g = 0.5*p; b = 0;
break;
}
case 4 : { /* Orange to Yellow */
- r = 255; g = 127 + 127*p; b = 0;
+ r = 1.0; g = 0.5 + 0.5*p; b = 0;
break;
}
case 5 : { /* Yellow to White */
- r = 255; g = 255; b = 255*p;
+ r = 1.0; g = 1.0; b = 1.0*p;
break;
}
case 6 : { /* Pixel has hit the maximum value */
- r = 255; g = 255; b = 255;
+ r = 1.0; g = 1.0; b = 1.0;
break;
}
}
@@ -158,30 +157,46 @@ static inline void render_rgb(float val, float max,
}
-static inline void render_mono(float val, float max,
- guchar *rp, guchar *gp, guchar *bp)
+static void render_mono(float val, float max, float *rp, float *gp, float *bp)
{
float p;
- p = (float)val / (float)max;
+ p = val / max;
if ( val < 0.0 ) p = 0.0;
if ( val > max ) p = 1.0;
- *rp = 255.0*p;
- *gp = 255.0*p;
- *bp = 255.0*p;
+ *rp = p;
+ *gp = p;
+ *bp = p;
}
-static inline void render_invmono(float val, float max,
- guchar *rp, guchar *gp, guchar *bp)
+static void render_invmono(float val, float max,
+ float *rp, float *gp, float *bp)
{
float p;
- p = (float)val / (float)max;
+ p = val / max;
p = 1.0 - p;
if ( val < 0.0 ) p = 1.0;
if ( val > max ) p = 0.0;
- *rp = 255.0*p;
- *gp = 255.0*p;
- *bp = 255.0*p;
+ *rp = p;
+ *gp = p;
+ *bp = p;
+}
+
+
+void render_scale(float val, float max, int scale,
+ float *rp, float *gp, float *bp)
+{
+ switch ( scale ) {
+ case SCALE_COLOUR :
+ render_rgb(val, max, rp, gp, bp);
+ break;
+ case SCALE_MONO :
+ render_mono(val, max, rp, gp, bp);
+ break;
+ case SCALE_INVMONO :
+ render_invmono(val, max, rp, gp, bp);
+ break;
+ }
}
@@ -269,32 +284,17 @@ GdkPixbuf *render_get_image(DisplayWindow *dw)
for ( x=0; x<w; x++ ) {
float val;
- guchar r = 0;
- guchar g = 0;
- guchar b = 0;
+ float r, g, b;
val = hdr[x+w*y];
- switch ( dw->scale ) {
- case SCALE_COLOUR : {
- render_rgb(val, max, &r, &g, &b);
- break;
- }
- case SCALE_MONO : {
- render_mono(val, max, &r, &g, &b);
- break;
- }
- case SCALE_INVMONO : {
- render_invmono(val, max, &r, &g, &b);
- break;
- }
- }
+ render_scale(val, max, dw->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*(h-1-y) )+0] = r;
- data[3*( x+w*(h-1-y) )+1] = g;
- data[3*( x+w*(h-1-y) )+2] = b;
+ 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;
}
}
@@ -322,35 +322,20 @@ GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale)
for ( y=0; y<h; y++ ) {
- guchar r = 0;
- guchar g = 0;
- guchar b = 0;
+ float r, g, b;
int val;
val = y;
- switch ( scale ) {
- case SCALE_COLOUR : {
- render_rgb(val, max, &r, &g, &b);
- break;
- }
- case SCALE_MONO : {
- render_mono(val, max, &r, &g, &b);
- break;
- }
- case SCALE_INVMONO : {
- render_invmono(val, max, &r, &g, &b);
- break;
- }
- }
+ 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] = r;
- data[3*( x+w*(h-1-y) )+1] = g;
- data[3*( x+w*(h-1-y) )+2] = b;
+ 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;
}
}
@@ -421,30 +406,15 @@ int render_png(DisplayWindow *dw, const char *filename)
for ( x=0; x<w; x++ ) {
- guchar r = 0;
- guchar g = 0;
- guchar b = 0;
+ float r, g, b;
float val;
val = hdr[x+w*y];
- switch ( dw->scale ) {
- case SCALE_COLOUR : {
- render_rgb(val, max, &r, &g, &b);
- break;
- }
- case SCALE_MONO : {
- render_mono(val, max, &r, &g, &b);
- break;
- }
- case SCALE_INVMONO : {
- render_invmono(val, max, &r, &g, &b);
- break;
- }
- }
- row_pointers[y][3*x] = (png_byte)r;
- row_pointers[y][3*x+1] = (png_byte)g;
- row_pointers[y][3*x+2] = (png_byte)b;
+ render_scale(val, max, dw->scale, &r, &g, &b);
+ row_pointers[y][3*x] = (png_byte)255*r;
+ row_pointers[y][3*x+1] = (png_byte)255*g;
+ row_pointers[y][3*x+2] = (png_byte)255*b;
}
}
diff --git a/src/render.h b/src/render.h
index c0570d2f..0be9ae97 100644
--- a/src/render.h
+++ b/src/render.h
@@ -30,6 +30,9 @@ enum {
SCALE_INVMONO
};
+extern void render_scale(float val, float max, int scale,
+ float *rp, float *gp, float *bp);
+
extern GdkPixbuf *render_get_image(DisplayWindow *dw);
extern GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale);
diff --git a/src/render_hkl.c b/src/render_hkl.c
index de8e3021..60153652 100644
--- a/src/render_hkl.c
+++ b/src/render_hkl.c
@@ -29,6 +29,7 @@
#include "reflections.h"
#include "povray.h"
#include "symmetry.h"
+#include "render.h"
enum {
WGHT_I,
@@ -66,7 +67,7 @@ static void show_help(const char *s)
#ifdef HAVE_CAIRO
static void render_za(UnitCell *cell, double *ref, unsigned int *c,
- double boost, const char *sym, int wght)
+ double boost, const char *sym, int wght, int colscale)
{
cairo_surface_t *surface;
cairo_t *dctx;
@@ -217,12 +218,11 @@ static void render_za(UnitCell *cell, double *ref, unsigned int *c,
abort();
}
- val = boost*val/max_val;
-
nequiv = num_equivs(h, k, 0, sym);
for ( p=0; p<nequiv; p++ ) {
signed int he, ke, le;
+ float r, g, b;
get_equiv(h, k, 0, &he, &ke, &le, sym, p);
u = (double)he*as*sin(theta);
@@ -232,7 +232,8 @@ static void render_za(UnitCell *cell, double *ref, unsigned int *c,
((double)ht/2)+v*scale, max_r,
0, 2*M_PI);
- cairo_set_source_rgb(dctx, val, val, val);
+ render_scale(val, max_val/boost, colscale, &r, &g, &b);
+ cairo_set_source_rgb(dctx, r, g, b);
cairo_fill(dctx);
}
@@ -300,6 +301,8 @@ int main(int argc, char *argv[])
char *sym = NULL;
char *weighting = NULL;
int wght;
+ int colscale;
+ char *cscale = NULL;
/* Long options */
const struct option longopts[] = {
@@ -310,12 +313,14 @@ int main(int argc, char *argv[])
{"boost", 1, NULL, 'b'},
{"symmetry", 1, NULL, 'y'},
{"weighting", 1, NULL, 'w'},
+ {"colscale", 1, NULL, 'c'},
{"counts", 0, &config_sqrt, 1},
{0, 0, NULL, 0}
};
/* Short options */
- while ((c = getopt_long(argc, argv, "hj:p:w:", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "hj:p:w:c:y:",
+ longopts, NULL)) != -1) {
switch (c) {
case 'h' :
@@ -342,6 +347,10 @@ int main(int argc, char *argv[])
weighting = strdup(optarg);
break;
+ case 'c' :
+ cscale = strdup(optarg);
+ break;
+
case 0 :
break;
@@ -381,6 +390,25 @@ int main(int argc, char *argv[])
ERROR("Unrecognised weighting '%s'\n", weighting);
return 1;
}
+ free(weighting);
+
+ if ( cscale == NULL ) {
+ cscale = strdup("mono");
+ }
+
+ if ( strcmp(cscale, "mono") == 0 ) {
+ colscale = SCALE_MONO;
+ } else if ( strcmp(cscale, "invmono") == 0 ) {
+ colscale = SCALE_INVMONO;
+ } else if ( strcmp(cscale, "colour") == 0 ) {
+ colscale = SCALE_COLOUR;
+ } else if ( strcmp(cscale, "color") == 0 ) {
+ colscale = SCALE_COLOUR;
+ } else {
+ ERROR("Unrecognised colour scale '%s'\n", cscale);
+ return 1;
+ }
+ free(cscale);
infile = argv[optind];
@@ -400,7 +428,7 @@ int main(int argc, char *argv[])
r = povray_render_animation(cell, ref, cts, nproc);
} else if ( config_zoneaxis ) {
#ifdef HAVE_CAIRO
- render_za(cell, ref, cts, boost, sym, wght);
+ render_za(cell, ref, cts, boost, sym, wght, colscale);
#else
ERROR("This version of CrystFEL was compiled without Cairo");
ERROR(" support, which is required to plot a zone axis");