diff options
author | Thomas White <taw@physics.org> | 2010-03-11 17:47:01 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2010-03-11 17:47:01 +0100 |
commit | 5f9185acec99456eb0673c9edb97cc8ae82de7ac (patch) | |
tree | 733579154170796c5ceb94560de595fc7145d74b /src | |
parent | 6ae81306a1be86cf47a7ec97a485b2184e22b4ff (diff) |
Multiple choice of colour scales
Diffstat (limited to 'src')
-rw-r--r-- | src/displaywindow.c | 37 | ||||
-rw-r--r-- | src/displaywindow.h | 2 | ||||
-rw-r--r-- | src/render.c | 25 | ||||
-rw-r--r-- | src/render.h | 8 |
4 files changed, 56 insertions, 16 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c index 12c31a5c..2501f38b 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -82,7 +82,7 @@ static void displaywindow_update(DisplayWindow *dw) if ( dw->col_scale != NULL ) { gdk_pixbuf_unref(dw->col_scale); } - dw->col_scale = render_get_colour_scale(20, dw->height, dw->monochrome); + dw->col_scale = render_get_colour_scale(20, dw->height, dw->scale); gdk_window_invalidate_rect(dw->drawingarea->window, NULL, FALSE); } @@ -525,14 +525,6 @@ static gint displaywindow_set_colscale(GtkWidget *widget, DisplayWindow *dw) } -static gint displaywindow_set_mono(GtkWidget *widget, DisplayWindow *dw) -{ - dw->monochrome = 1 - dw->monochrome; - displaywindow_update(dw); - return 0; -} - - static gint displaywindow_numbers_response(GtkWidget *widget, gint response, DisplayWindow *dw) { @@ -687,6 +679,16 @@ static void displaywindow_addui_callback(GtkUIManager *ui, GtkWidget *widget, } +static gint displaywindow_setscale(GtkWidget *widget, GtkRadioAction *action, + DisplayWindow *dw) +{ + dw->scale = gtk_radio_action_get_current_value(action); + displaywindow_update(dw); + + return 0; +} + + static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox) { GError *error = NULL; @@ -720,15 +722,26 @@ static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox) GtkToggleActionEntry toggles[] = { { "ColScaleAction", NULL, "Show Colour Scale", NULL, NULL, G_CALLBACK(displaywindow_set_colscale), FALSE }, - { "MonoAction", NULL, "Monochrome", NULL, NULL, - G_CALLBACK(displaywindow_set_mono), FALSE }, }; guint n_toggles = G_N_ELEMENTS(toggles); + GtkRadioActionEntry radios[] = { + { "ColAction", NULL, "Colour", NULL, NULL, + SCALE_COLOUR }, + { "MonoAction", NULL, "Monochrome", NULL, NULL, + SCALE_MONO }, + { "InvMonoAction", NULL, "Inverse Monochrome", NULL, NULL, + SCALE_INVMONO }, + }; + guint n_radios = G_N_ELEMENTS(radios); dw->action_group = gtk_action_group_new("hdfseedisplaywindow"); gtk_action_group_add_actions(dw->action_group, entries, n_entries, dw); gtk_action_group_add_toggle_actions(dw->action_group, toggles, n_toggles, dw); + gtk_action_group_add_radio_actions(dw->action_group, radios, n_radios, + SCALE_COLOUR, + G_CALLBACK(displaywindow_setscale), + dw); dw->ui = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(dw->ui, dw->action_group, 0); @@ -981,7 +994,7 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, dw->binning_dialog = NULL; dw->show_col_scale = 0; dw->col_scale = NULL; - dw->monochrome = 0; + dw->scale = SCALE_COLOUR; dw->boostint_dialog = NULL; dw->boostint = 1; dw->motion_callback = 0; diff --git a/src/displaywindow.h b/src/displaywindow.h index 63630abf..0ca59933 100644 --- a/src/displaywindow.h +++ b/src/displaywindow.h @@ -66,7 +66,7 @@ typedef struct { int clean; /* Whether or not to clean the image */ int show_col_scale; - int monochrome; + int scale; GdkPixbuf *col_scale; } DisplayWindow; diff --git a/src/render.c b/src/render.c index 1ea36ea1..385944df 100644 --- a/src/render.c +++ b/src/render.c @@ -153,6 +153,14 @@ float *render_get_image_binned(DisplayWindow *dw, int binning, float *max) if ( val > max ) p = 1.0; \ r = 255.0*p; g = 255.0*p; b = 255.0*p; +#define RENDER_INVMONO \ + float p; \ + p = (float)val / (float)max; \ + p = 1.0 - p; \ + if ( val < 0.0 ) p = 1.0; \ + if ( val > max ) p = 0.0; \ + r = 255.0*p; g = 255.0*p; b = 255.0*p; + /* NB This function is shared between render_get_image() and * render_get_colour_scale() */ @@ -238,10 +246,23 @@ GdkPixbuf *render_get_image(DisplayWindow *dw) guchar r, g, b; val = hdr[x+w*y]; - if ( !dw->monochrome ) { + switch ( dw->scale ) { + case SCALE_COLOUR : { RENDER_RGB - } else { + break; + } + case SCALE_MONO : { RENDER_MONO + break; + } + case SCALE_INVMONO : { + RENDER_INVMONO + break; + } + default : { + RENDER_RGB; + break; + } } /* Stuff inside square brackets makes this pixel go to diff --git a/src/render.h b/src/render.h index e030f27b..29f69ec4 100644 --- a/src/render.h +++ b/src/render.h @@ -23,8 +23,14 @@ #include "displaywindow.h" +enum { + SCALE_COLOUR, + SCALE_MONO, + SCALE_INVMONO +}; + extern GdkPixbuf *render_get_image(DisplayWindow *dw); -extern GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int monochrome); +extern GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale); #endif /* RENDER_H */ |