From caf2225f7b7192a16fbe6917a0bc4e81bbe8b698 Mon Sep 17 00:00:00 2001 From: Maria Date: Mon, 21 Oct 2013 11:00:58 +0200 Subject: Added jet. --- bin/gui/control.c | 268 ++++++++++++++++++++++++++++---------------------- bin/gui/control.glade | 195 ++++++++++++++++++++++++------------ 2 files changed, 280 insertions(+), 183 deletions(-) (limited to 'bin') diff --git a/bin/gui/control.c b/bin/gui/control.c index 0ea2a31..35e2267 100644 --- a/bin/gui/control.c +++ b/bin/gui/control.c @@ -46,6 +46,7 @@ typedef struct { GtkWidget *acquisition_expander; GtkWidget *properties_expander; GtkWidget *zoom_box; + GtkWidget *colormap_box; GtkLabel *mean_label; GtkLabel *sigma_label; GtkLabel *max_label; @@ -57,9 +58,6 @@ typedef struct { GtkAdjustment *count; GtkAdjustment *hadjustment, *vadjustment; - GtkPaned *paned; - GtkRequisition child_requisition; - GtkWidget *histogram_view; GtkToggleButton *histogram_button; GtkToggleButton *log_button; @@ -69,6 +67,7 @@ typedef struct { guchar *pixels; gint display_width, display_height; gint page_width, page_height; + gint colormap; gdouble zoom_factor; State state; guint n_recorded; @@ -83,92 +82,7 @@ static UcaPluginManager *plugin_manager; static gsize mem_size = 2048; static void -down_scale (ThreadData *data, gpointer buffer) -{ - gdouble min; - gdouble max; - gdouble factor; - gdouble dval; - gboolean do_log; - guint8 *output; - gint stride; - gint i = 0; - gint start_wval; - gint start_hval; - - egg_histogram_get_range (EGG_HISTOGRAM_VIEW (data->histogram_view), &min, &max); - factor = 255.0 / (max - min); - output = data->pixels; - stride = (gint) 1 / data->zoom_factor; - do_log = gtk_toggle_button_get_active (data->log_button); - - if (data->state == RUNNING) { - gint page_width = gtk_adjustment_get_page_size (GTK_ADJUSTMENT (data->hadjustment)); - gint page_height = gtk_adjustment_get_page_size (GTK_ADJUSTMENT (data->vadjustment)); - start_wval = gtk_adjustment_get_value (GTK_ADJUSTMENT (data->hadjustment)); - start_hval = gtk_adjustment_get_value (GTK_ADJUSTMENT (data->vadjustment)); - data->page_width = (page_width + start_wval); - data->page_height = (page_height + start_hval); - } - else { - start_wval = 0; - start_hval = 0; - data->page_width = data->display_width; - data->page_height = data->display_height; - } - - if (data->pixel_size == 1) { - guint8 *input = (guint8 *) buffer; - - for (gint y = 0; y < data->display_height; y++){ - gint offset = y * stride * data->width; - - for (gint x = 0; x < data->display_width; x++, offset += stride) { - if (y >= start_hval && y < data->page_height) { - if (x >= start_wval && x < data->page_width) { - - if (do_log) - dval = log ((input[offset] - min) * factor); - else - dval = (input[offset] - min) * factor; - } - } - - guchar val = (guchar) CLAMP(dval, 0.0, 255.0); - output[i++] = val; - output[i++] = val; - output[i++] = val; - } - } - } - else if (data->pixel_size == 2) { - guint16 *input = (guint16 *) buffer; - - for (gint y = 0; y < data->display_height; y++){ - gint offset = y * stride * data->width; - - for (gint x = 0; x < data->display_width; x++, offset += stride) { - if (y >= start_hval && y < data->page_height) { - if (x >= start_wval && x < data->page_width) { - - if (do_log) - dval = log ((input[offset] - min) * factor); - else - dval = (input[offset] - min) * factor; - } - } - - guchar val = (guchar) CLAMP(dval, 0.0, 255.0); - output[i++] = val; - output[i++] = val; - output[i++] = val; - } - } - } -} - -static void -up_scale (ThreadData *data, gpointer buffer) +up_and_down_scale (ThreadData *data, gpointer buffer) { gdouble min; gdouble max; @@ -178,6 +92,8 @@ up_scale (ThreadData *data, gpointer buffer) guint8 *output; gint i = 0; gint zoom; + gint stride; + gint offset; gint start_wval; gint start_hval; @@ -185,6 +101,7 @@ up_scale (ThreadData *data, gpointer buffer) factor = 255.0 / (max - min); output = data->pixels; zoom = (gint) data->zoom_factor; + stride = (gint) 1 / zoom; do_log = gtk_toggle_button_get_active (data->log_button); if (data->state == RUNNING) { @@ -206,10 +123,17 @@ up_scale (ThreadData *data, gpointer buffer) guint8 *input = (guint8 *) buffer; for (gint y = 0; y < data->display_height; y++) { + if (zoom <= 1){ + offset = y * stride * data->width; + } + for (gint x = 0; x < data->display_width; x++) { - gint offset = ((gint) (y / zoom) * data->width) + ((gint) (x / zoom)); + if (zoom <= 1) + offset += stride; + else + offset = ((gint) (y / zoom) * data->width) + ((gint) (x / zoom)); - if (y >= start_hval && y < data->page_height) { + if (y >= start_hval && y < data->page_height) { if (x >= start_wval && x < data->page_width) { if (do_log) @@ -218,11 +142,50 @@ up_scale (ThreadData *data, gpointer buffer) dval = (input[offset] - min) * factor; } } - guchar val = (guchar) CLAMP(dval, 0.0, 255.0); - output[i++] = val; - output[i++] = val; - output[i++] = val; + + if (data->colormap == 1) { + output[i++] = val; + output[i++] = val; + output[i++] = val; + } + else { + val = (float) val; + float red = 0; + float green = 0; + float blue = 0; + + if (val == 255) { + red = 255; + green = 255; + blue = 255; + } + else if (val == 0) { + } + else if (val <= 31.875) { + blue = 255 - 4 * (31.875 - val); + } + else if (val <= 95.625) { + green = 255 - 4 * (95.625 - val); + blue = 255; + } + else if (val <= 159.375) { + red = 255 - 4 * (159.375 - val); + green = 255; + blue = 255 + 4 * (95.625 - val); + } + else if (val <= 223.125) { + red = 255; + green = 255 + 4 * (159.375 - val); + } + else { + red = 255 + 4 * (223.125 - val); + } + + output[i++] = (guchar) red; + output[i++] = (guchar) green; + output[i++] = (guchar) blue; + } } } } @@ -230,10 +193,17 @@ up_scale (ThreadData *data, gpointer buffer) guint16 *input = (guint16 *) buffer; for (gint y = 0; y < data->display_height; y++) { + if (zoom <= 1){ + offset = y * stride * data->width; + } + for (gint x = 0; x < data->display_width; x++) { - gint offset = ((gint) (y / zoom) * data->width) + ((gint) (x / zoom)); + if (zoom <= 1) + offset += stride; + else + offset = ((gint) (y / zoom) * data->width) + ((gint) (x / zoom)); - if (y >= start_hval && y < data->page_height) { + if (y >= start_hval && y < data->page_height) { if (x >= start_wval && x < data->page_width) { if (do_log) @@ -242,11 +212,50 @@ up_scale (ThreadData *data, gpointer buffer) dval = (input[offset] - min) * factor; } } - guchar val = (guchar) CLAMP(dval, 0.0, 255.0); - output[i++] = val; - output[i++] = val; - output[i++] = val; + + if (data->colormap == 1) { + output[i++] = val; + output[i++] = val; + output[i++] = val; + } + else { + val = (float) val; + float red = 0; + float green = 0; + float blue = 0; + + if (val == 255) { + red = 65535; + green = 65535; + blue = 65535; + } + else if (val == 0) { + } + else if (val <= 31.875) { + blue = (255 - 4 * (31.875 - val)) * 257; + } + else if (val <= 95.625) { + green = (255 - 4 * (95.625 - val)) * 257; + blue = 65535; + } + else if (val <= 159.375) { + red = (255 - 4 * (159.375 - val)) * 257; + green = 65535; + blue = (255 + 4 * (95.625 - val)) * 257; + } + else if (val <= 223.125) { + red = 65535; + green = (255 + 4 * (159.375 - val)) * 257; + } + else { + red = (255 + 4 * (223.125 - val)) * 257; + } + + output[i++] = (guchar) red; + output[i++] = (guchar) green; + output[i++] = (guchar) blue; + } } } } @@ -307,15 +316,6 @@ get_statistics (ThreadData *data, gdouble *mean, gdouble *sigma, guint *_max, gu *_max = max; } -static void -convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) -{ - if (data->zoom_factor <= 1) - down_scale (data, buffer); - else - up_scale (data, buffer); -} - static void update_pixbuf (ThreadData *data) { @@ -392,6 +392,8 @@ set_tool_button_state (ThreadData *data) data->state == IDLE); gtk_widget_set_sensitive (data->zoom_box, data->state == IDLE); + gtk_widget_set_sensitive (data->colormap_box, + data->state == IDLE); } static gpointer @@ -409,7 +411,7 @@ preview_frames (void *args) uca_camera_grab (data->camera, buffer, &error); if (error == NULL) { - convert_grayscale_to_rgb (data, buffer); + up_and_down_scale (data, buffer); gdk_threads_enter (); update_pixbuf (data); @@ -506,7 +508,7 @@ update_current_frame (ThreadData *data) ring_buffer_set_current_pointer (data->buffer, index); buffer = ring_buffer_get_current_pointer (data->buffer); - convert_grayscale_to_rgb (data, buffer); + up_and_down_scale (data, buffer); update_pixbuf (data); } @@ -721,7 +723,30 @@ on_zoom_changed (GtkComboBox *widget, ThreadData *data) data->zoom_factor = factor; update_pixbuf_dimensions (data); - convert_grayscale_to_rgb (data, ring_buffer_get_current_pointer (data->buffer)); + up_and_down_scale (data, ring_buffer_get_current_pointer (data->buffer)); + update_pixbuf (data); +} + +static void +on_colormap_changed (GtkComboBox *widget, ThreadData *data) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gint map; + + enum { + DISPLAY2_COLUMN, + MAP_COLUMN + }; + + model = gtk_combo_box_get_model (widget); + gtk_combo_box_get_active_iter (widget, &iter); + gtk_tree_model_get (model, &iter, MAP_COLUMN, &map, -1); + + data->colormap = map; + update_pixbuf_dimensions (data); + + up_and_down_scale (data, ring_buffer_get_current_pointer (data->buffer)); update_pixbuf (data); } @@ -786,19 +811,20 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.properties_expander = GTK_WIDGET (gtk_builder_get_object (builder, "properties-expander")); td.zoom_box = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-box")); + td.colormap_box = GTK_WIDGET (gtk_builder_get_object (builder, "colormap-box")); td.start_button = GTK_WIDGET (gtk_builder_get_object (builder, "start-button")); td.stop_button = GTK_WIDGET (gtk_builder_get_object (builder, "stop-button")); td.record_button = GTK_WIDGET (gtk_builder_get_object (builder, "record-button")); td.download_button = GTK_WIDGET (gtk_builder_get_object (builder, "download-button")); td.histogram_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "histogram-checkbutton")); - td.log_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "logarithmus-checkbutton")); + td.log_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "logarithm-checkbutton")); td.frame_slider = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "frames-adjustment")); td.count = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "acquisitions-adjustment")); - td.hadjustment = GTK_ADJUSTMENT (gtk_builder_get_object(builder, "adjustment1")); - td.vadjustment = GTK_ADJUSTMENT (gtk_builder_get_object(builder, "adjustment2")); - td.page_width = gtk_adjustment_get_page_size(GTK_ADJUSTMENT(td.hadjustment)); - td.page_height = gtk_adjustment_get_page_size(GTK_ADJUSTMENT(td.vadjustment)); + td.hadjustment = GTK_ADJUSTMENT (gtk_builder_get_object(builder, "hadjustment")); + td.vadjustment = GTK_ADJUSTMENT (gtk_builder_get_object(builder, "vadjustment")); + td.page_width = gtk_adjustment_get_page_size(GTK_ADJUSTMENT(td.hadjustment)); + td.page_height = gtk_adjustment_get_page_size(GTK_ADJUSTMENT(td.vadjustment)); td.mean_label = GTK_LABEL (gtk_builder_get_object (builder, "mean-label")); td.sigma_label = GTK_LABEL (gtk_builder_get_object (builder, "sigma-label")); @@ -817,7 +843,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) egg_histogram_view_update (EGG_HISTOGRAM_VIEW (histogram_view), ring_buffer_get_current_pointer (ring_buffer)); - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); gtk_adjustment_set_value (max_bin_adjustment, pow (2, bits_per_sample) - 1); @@ -836,6 +862,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.width = td.display_width = width; td.height = td.display_height = height; td.zoom_factor = 1.0; + td.colormap = 1; td.histogram_view = histogram_view; td.data_in_camram = FALSE; td.main_window = window; @@ -865,6 +892,9 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) g_signal_connect (gtk_builder_get_object (builder, "zoom-box"), "changed", G_CALLBACK (on_zoom_changed), &td); + g_signal_connect (gtk_builder_get_object (builder, "colormap-box"), + "changed", G_CALLBACK (on_colormap_changed), &td); + g_signal_connect (td.frame_slider, "value-changed", G_CALLBACK (on_frame_slider_changed), &td); g_signal_connect (td.start_button, "clicked", G_CALLBACK (on_start_button_clicked), &td); g_signal_connect (td.stop_button, "clicked", G_CALLBACK (on_stop_button_clicked), &td); diff --git a/bin/gui/control.glade b/bin/gui/control.glade index 7a339cf..a8b90ca 100644 --- a/bin/gui/control.glade +++ b/bin/gui/control.glade @@ -6,16 +6,6 @@ 1 10 - - 100 - 1 - 10 - - - 100 - 1 - 10 - @@ -82,10 +72,10 @@ gtk-quit + False True True True - False True @@ -98,10 +88,10 @@ gtk-ok + False True True True - False True @@ -121,6 +111,24 @@ + + + + + + + + + + grayscale + 1 + + + jet + 2 + + + 100 1 @@ -142,7 +150,19 @@ False end - + + gtk-close + False + True + True + True + True + + + False + False + 0 + @@ -192,6 +212,9 @@ + + download-close-button + 100 @@ -202,6 +225,11 @@ 1 10 + + 100 + 1 + 10 + 65535 256 @@ -213,11 +241,46 @@ 1 10 + + 100 + 1 + 10 + + + + + + + + + + + 400 % + 4 + + + 200 % + 2 + + + 100 % + 1 + + + 50 % + 0.5 + + + 25 % + 0.25 + + + False Camera Control 1024 - 767 + 768 @@ -229,9 +292,9 @@ False + False True False - False _File True @@ -241,9 +304,9 @@ gtk-new + False True False - False True True @@ -251,9 +314,9 @@ gtk-open + False True False - False True True @@ -261,9 +324,9 @@ gtk-save-as + False True False - False True True @@ -277,9 +340,9 @@ gtk-quit + False True False - False True True @@ -291,9 +354,9 @@ + False True False - False _Help True @@ -303,9 +366,9 @@ gtk-about + False True False - False True True @@ -327,9 +390,9 @@ False + False True False - False Run True gtk-media-play @@ -341,9 +404,9 @@ + False True False - False Record True gtk-media-record @@ -355,9 +418,9 @@ + False True False - False Stop True gtk-media-stop @@ -369,9 +432,9 @@ + False True False - False Download True network-receive @@ -399,8 +462,8 @@ 480 True True - adjustment1 - adjustment2 + hadjustment + vadjustment automatic automatic @@ -419,8 +482,8 @@ - False - False + True + True @@ -580,10 +643,10 @@ Repeat + False True True False - False 0 True @@ -820,11 +883,11 @@ Live Update + False True True False 6 - False 0 True True @@ -1024,6 +1087,37 @@ 1 + + + True + False + 0 + Colormap: + + + False + False + 2 + + + + + True + False + colormaps + + + + 0 + + + + + False + False + 3 + + True @@ -1032,13 +1126,16 @@ - - Logarithmus + + + + + Logarithm + False True True False 10 - False 0 True @@ -1115,34 +1212,4 @@ - - - - - - - - - - 400 % - 4 - - - 200 % - 2 - - - 100 % - 1 - - - 50 % - 0.5 - - - 25 % - 0.25 - - - -- cgit v1.2.3