From ba3e9a22be54bea244227ff19fa6914da9456734 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 10 Aug 2011 10:06:15 +0200 Subject: Add user-adjustable scale parameter --- test/control.c | 21 ++++++++-- test/control.glade | 113 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 106 insertions(+), 28 deletions(-) diff --git a/test/control.c b/test/control.c index 5ff54c6..0db1079 100644 --- a/test/control.c +++ b/test/control.c @@ -16,6 +16,7 @@ typedef struct { int pixel_size; struct uca_camera *cam; struct uca *u; + float scale; } ThreadData; @@ -43,11 +44,11 @@ void convert_8bit_to_rgb(guchar *output, guchar *input, int width, int height) } } -void convert_16bit_to_rgb(guchar *output, guchar *input, int width, int height) +void convert_16bit_to_rgb(guchar *output, guchar *input, int width, int height, float scale) { uint16_t *in = (uint16_t *) input; for (int i = 0, j = 0; i < width*height; i++) { - guchar val = (uint8_t) ((in[i]/65536.0f)*256.0f); + guchar val = (uint8_t) ((in[i]/scale)*256.0f); output[j++] = val; output[j++] = val; output[j++] = val; @@ -83,7 +84,7 @@ void *grab_thread(void *args) if (data->pixel_size == 1) convert_8bit_to_rgb(data->pixels, data->buffer, data->width, data->height); else if (data->pixel_size == 2) - convert_16bit_to_rgb(data->pixels, data->buffer, data->width, data->height); + convert_16bit_to_rgb(data->pixels, data->buffer, data->width, data->height, data->scale); gdk_threads_enter(); gdk_flush(); @@ -108,6 +109,12 @@ void on_destroy(GtkWidget *widget, gpointer data) gtk_main_quit(); } +void on_adjustment_scale_value_changed(GtkAdjustment* adjustment, gpointer user_data) +{ + ThreadData *data = (ThreadData *) user_data; + data->scale = gtk_adjustment_get_value(adjustment); +} + void on_toolbutton_run_clicked(GtkWidget *widget, gpointer args) { ThreadData *data = (ThreadData *) args; @@ -350,15 +357,23 @@ int main(int argc, char *argv[]) td.u = u; td.running = FALSE; td.pixel_size = pixel_size; + td.scale = 65535.0f; gtk_builder_connect_signals(builder, &td); + /* Configure value cell */ ValueCellData value_cell_data; value_cell_data.thread_data = &td; value_cell_data.tree_store = tree_store; g_signal_connect(gtk_builder_get_object(builder, "valuecell"), "edited", G_CALLBACK(on_valuecell_edited), &value_cell_data); + + /* Configure scale adjustment */ + GtkAdjustment *adjustment = (GtkAdjustment *) gtk_builder_get_object(builder, "adjustment_scale"); + gtk_adjustment_configure(adjustment, 65535.0, 1.0, 65535.0, 0.5, 10.0, 0.0); + g_signal_connect(adjustment, "value-changed", + G_CALLBACK(on_adjustment_scale_value_changed), &td); gtk_widget_show(image); gtk_widget_show(window); diff --git a/test/control.glade b/test/control.glade index e20f9ff..a370c72 100644 --- a/test/control.glade +++ b/test/control.glade @@ -186,46 +186,102 @@ - + True - True - cameraproperties - - Name + + True + True + automatic + automatic - - - 0 - + + True + True + cameraproperties + False + 0 + + + Name + + + + 0 + + + + + + + Value + + + + 1 + + + + + + + Unit + + + + 2 + + + + + + + 0 + - - Value + + True + 2 + 6 - - - 1 - + + True + 16-Bit Scale <i>1/x</i>: + True + + + + - - - - - Unit - - - 2 - + + True + True + + adjustment_scale + 0.02 + 2 + True + + + 1 + 2 + + + False + False + 6 + 1 + - False + True True @@ -247,4 +303,11 @@ + + 65534.999999999774 + 1 + 65535 + 1 + 10 + -- cgit v1.2.3