From 5f1a2731f3d6ad16214bd83095f8e1511cf1d76b Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Tue, 9 Aug 2011 10:16:26 +0200 Subject: Use GtkBuilder.connect_signals and optimize data conversion --- test/CMakeLists.txt | 3 +- test/control.c | 76 ++++++++++++++++++-------------------------- test/control.glade | 91 ++++++++--------------------------------------------- 3 files changed, 44 insertions(+), 126 deletions(-) (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 89351d9..728da6a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,8 +10,7 @@ pkg_check_modules(GTHREAD2 gthread-2.0) include_directories(${CMAKE_SOURCE_DIR}/src) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/control.glade - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/control.glade ${CMAKE_CURRENT_BINARY_DIR}) # --- Build targets ----------------------------------------------------------- add_executable(enum enum.c) diff --git a/test/control.c b/test/control.c index 00bda8c..5ff54c6 100644 --- a/test/control.c +++ b/test/control.c @@ -36,27 +36,21 @@ enum { void convert_8bit_to_rgb(guchar *output, guchar *input, int width, int height) { - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - const int off = y*width + x; - output[off*3] = input[off]; - output[off*3+1] = input[off]; - output[off*3+2] = input[off]; - } + for (int i = 0, j = 0; i < width*height; i++) { + output[j++] = input[i]; + output[j++] = input[i]; + output[j++] = input[i]; } } void convert_16bit_to_rgb(guchar *output, guchar *input, int width, int height) { uint16_t *in = (uint16_t *) input; - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - const int off = y*width + x; - guchar val = (uint8_t) ((in[off]/65536.0f)*256.0f); - output[off*3] = val; - output[off*3+1] = val; - output[off*3+2] = val; - } + for (int i = 0, j = 0; i < width*height; i++) { + guchar val = (uint8_t) ((in[i]/65536.0f)*256.0f); + output[j++] = val; + output[j++] = val; + output[j++] = val; } } @@ -79,19 +73,6 @@ void reallocate_buffers(ThreadData *td, int width, int height) g_print("Couldn't allocate buffer for 20 frames\n"); } -static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) -{ - return FALSE; -} - -static void destroy(GtkWidget *widget, gpointer data) -{ - ThreadData *td = (ThreadData *) data; - td->running = FALSE; - uca_destroy(td->u); - gtk_main_quit(); -} - void *grab_thread(void *args) { ThreadData *data = (ThreadData *) args; @@ -114,7 +95,20 @@ void *grab_thread(void *args) return NULL; } -static void on_toolbutton_run_clicked(GtkWidget *widget, gpointer args) +gboolean on_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + return FALSE; +} + +void on_destroy(GtkWidget *widget, gpointer data) +{ + ThreadData *td = (ThreadData *) data; + td->running = FALSE; + uca_destroy(td->u); + gtk_main_quit(); +} + +void on_toolbutton_run_clicked(GtkWidget *widget, gpointer args) { ThreadData *data = (ThreadData *) args; GError *error = NULL; @@ -126,14 +120,14 @@ static void on_toolbutton_run_clicked(GtkWidget *widget, gpointer args) } } -static void on_toolbutton_stop_clicked(GtkWidget *widget, gpointer args) +void on_toolbutton_stop_clicked(GtkWidget *widget, gpointer args) { ThreadData *data = (ThreadData *) args; data->running = FALSE; uca_cam_stop_recording(data->cam); } -static void on_valuecell_edited(GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer data) +void on_valuecell_edited(GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer data) { ValueCellData *value_data = (ValueCellData *) data; @@ -163,7 +157,7 @@ static void on_valuecell_edited(GtkCellRendererText *renderer, gchar *path, gcha } } -void get_first_level_root(GtkTreeStore *store, GtkTreeIter *iter, gchar *group) +static void get_first_level_root(GtkTreeStore *store, GtkTreeIter *iter, gchar *group) { GtkTreeIter root; if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &root)) { @@ -193,7 +187,7 @@ void get_first_level_root(GtkTreeStore *store, GtkTreeIter *iter, gchar *group) gtk_tree_store_set(store, iter, 0, group, -1); } -void find_recursively(GtkTreeStore *store, GtkTreeIter *root, GtkTreeIter *result, gchar **tokens, int depth) +static void find_recursively(GtkTreeStore *store, GtkTreeIter *root, GtkTreeIter *result, gchar **tokens, int depth) { GtkTreeIter iter; gchar *str; @@ -232,7 +226,7 @@ void find_recursively(GtkTreeStore *store, GtkTreeIter *root, GtkTreeIter *resul find_recursively(store, &iter, result, tokens, depth+1); } -void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera *cam) +static void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera *cam) { GtkTreeIter iter, child; struct uca_property *property; @@ -284,7 +278,7 @@ void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera *cam) g_free(value_string); } -void value_cell_data_func(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) +static void value_cell_data_func(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) { uint32_t prop_id; @@ -357,17 +351,7 @@ int main(int argc, char *argv[]) td.running = FALSE; td.pixel_size = pixel_size; - g_signal_connect(window, "delete-event", - G_CALLBACK (delete_event), NULL); - - g_signal_connect(window, "destroy", - G_CALLBACK (destroy), &td); - - g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "toolbutton_run")), "clicked", - G_CALLBACK(on_toolbutton_run_clicked), &td); - - g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "toolbutton_stop")), "clicked", - G_CALLBACK(on_toolbutton_stop_clicked), &td); + gtk_builder_connect_signals(builder, &td); ValueCellData value_cell_data; value_cell_data.thread_data = &td; diff --git a/test/control.glade b/test/control.glade index 4847767..e20f9ff 100644 --- a/test/control.glade +++ b/test/control.glade @@ -1,4 +1,4 @@ - + @@ -18,27 +18,26 @@ Camera Control 800 600 + + True - vertical True True - False _File True - + True gtk-new True - False True True @@ -47,7 +46,6 @@ gtk-open True - False True True @@ -56,7 +54,6 @@ gtk-save True - False True True @@ -65,7 +62,6 @@ gtk-save-as True - False True True @@ -73,93 +69,33 @@ True - False - + gtk-quit True - False True True + - - - True - False - _Edit - True - - - True - - - gtk-cut - True - False - True - True - - - - - gtk-copy - True - False - True - True - - - - - gtk-paste - True - False - True - True - - - - - gtk-delete - True - False - True - True - - - - - - - - - True - False - _View - True - - True - False _Help True - + True - + gtk-about True - False True True @@ -180,10 +116,10 @@ True - False Run True gtk-media-play + False @@ -193,7 +129,6 @@ True - False Record True gtk-media-record @@ -206,10 +141,10 @@ True - False Stop True gtk-media-stop + False @@ -257,7 +192,7 @@ cameraproperties - Name + Name @@ -268,7 +203,7 @@ - Value + Value @@ -279,7 +214,7 @@ - Unit + Unit -- cgit v1.2.3