From e5ff011119ac42e48f3f3521b789a18bdfdfb51e Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 21 Sep 2012 19:24:36 +0200 Subject: Add documentation generator and mock docs --- tools/CMakeLists.txt | 24 ++++++++ tools/gen-doc.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 tools/CMakeLists.txt create mode 100644 tools/gen-doc.c (limited to 'tools') diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..957fdbf --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 2.8) + +add_definitions("--std=c99 -Wall") + +# --- Find packages and libraries --------------------------------------------- +find_package(PkgConfig) + +pkg_check_modules(GLIB2 glib-2.0>=2.24 REQUIRED) +pkg_check_modules(GOBJECT2 gobject-2.0>=2.24 REQUIRED) + +# --- Build targets ----------------------------------------------------------- +include_directories( + ${GLIB2_INCLUDE_DIRS} + ${GOBJECT2_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR}/../src/ + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ) + +add_executable(gen-doc gen-doc.c) + +target_link_libraries(gen-doc uca + ${GLIB2_LIBRARIES} + ${GOBJECT2_LIBRARIES} + ) diff --git a/tools/gen-doc.c b/tools/gen-doc.c new file mode 100644 index 0000000..d9b6b41 --- /dev/null +++ b/tools/gen-doc.c @@ -0,0 +1,151 @@ +/* Copyright (C) 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include "uca-plugin-manager.h" +#include "uca-camera.h" + + +static void +print_usage (void) +{ + GList *types; + UcaPluginManager *manager; + + manager = uca_plugin_manager_new (); + g_print ("Usage: gen-doc [ "); + types = uca_plugin_manager_get_available_cameras (manager); + + if (types == NULL) { + g_print ("] -- no camera plugin found\n"); + return; + } + + for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { + gchar *name = (gchar *) it->data; + if (g_list_next (it) == NULL) + g_print ("%s ]\n", name); + else + g_print ("%s, ", name); + } +} + +static const gchar * +get_flags_description (GParamSpec *pspec) +{ + static const gchar *descriptions[] = { + "", + "Read-only", + "Write-only", + "Read / Write", + "" + }; + + if (pspec->flags >= 3) + return descriptions[3]; + + return descriptions[pspec->flags]; +} + +static void +print_property_toc (GParamSpec **pspecs, guint n_props) +{ + g_print ("

Properties

    "); + + for (guint i = 0; i < n_props; i++) { + GParamSpec *pspec = pspecs[i]; + const gchar *name = g_param_spec_get_name (pspec); + + g_print ("
  • \"%s\"
  • ", name, name); + } + + g_print ("
"); +} + +static void +print_property_descriptions (GParamSpec **pspecs, guint n_props) +{ + g_print ("

Details

"); + + for (guint i = 0; i < n_props; i++) { + GParamSpec *pspec = pspecs[i]; + const gchar *name = g_param_spec_get_name (pspec); + + g_print ("
%s
\n", name, name); + g_print ("
"); + g_print ("
\"%s\" : %s : %s
\n", + name, + g_type_name (pspec->value_type), + get_flags_description (pspec)); + g_print ("

%s

\n", g_param_spec_get_blurb (pspec)); + g_print ("
"); + } + + g_print ("
"); +} + +static void +print_properties (UcaCamera *camera) +{ + GObjectClass *oclass; + GParamSpec **pspecs; + guint n_props; + + oclass = G_OBJECT_GET_CLASS (camera); + pspecs = g_object_class_list_properties (oclass, &n_props); + + print_property_toc (pspecs, n_props); + print_property_descriptions (pspecs, n_props); + + g_free (pspecs); +} + +static const gchar *html_header = "\ +\ +\ +%s — properties"; +static const gchar *html_footer = ""; + +int main(int argc, char *argv[]) +{ + UcaPluginManager *manager; + UcaCamera *camera; + GError *error = NULL; + + g_type_init(); + + if (argc < 2) { + print_usage(); + return 1; + } + + manager = uca_plugin_manager_new (); + camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + + if (camera == NULL) { + g_print("Error during initialization: %s\n", error->message); + return 1; + } + + g_print (html_header, argv[1]); + g_print ("

Property documentation of %s

", argv[1]); + print_properties (camera); + g_print ("%s\n", html_footer); + + g_object_unref (camera); + g_object_unref (manager); +} -- cgit v1.2.3 From 3a45434834999e1ac7c7a99cdaa644d939b859b0 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Tue, 25 Sep 2012 18:18:23 +0200 Subject: Move tools from test/ to tools/ directory --- tools/CMakeLists.txt | 20 +- tools/benchmark.c | 267 +++++++++++++++ tools/grab-async.c | 138 ++++++++ tools/grab.c | 160 +++++++++ tools/gui/control.c | 350 +++++++++++++++++++ tools/gui/control.glade | 302 +++++++++++++++++ tools/gui/egg-property-cell-renderer.c | 594 +++++++++++++++++++++++++++++++++ tools/gui/egg-property-cell-renderer.h | 55 +++ tools/gui/egg-property-tree-view.c | 113 +++++++ tools/gui/egg-property-tree-view.h | 54 +++ tools/perf-overhead.c | 181 ++++++++++ 11 files changed, 2230 insertions(+), 4 deletions(-) create mode 100644 tools/benchmark.c create mode 100644 tools/grab-async.c create mode 100644 tools/grab.c create mode 100644 tools/gui/control.c create mode 100644 tools/gui/control.glade create mode 100644 tools/gui/egg-property-cell-renderer.c create mode 100644 tools/gui/egg-property-cell-renderer.h create mode 100644 tools/gui/egg-property-tree-view.c create mode 100644 tools/gui/egg-property-tree-view.h create mode 100644 tools/perf-overhead.c (limited to 'tools') diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 957fdbf..0e4d28e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -16,9 +16,21 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../src ) +set(libs uca ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES}) + add_executable(gen-doc gen-doc.c) +target_link_libraries(gen-doc ${libs}) -target_link_libraries(gen-doc uca - ${GLIB2_LIBRARIES} - ${GOBJECT2_LIBRARIES} - ) +add_executable(grab grab.c) +target_link_libraries(grab ${libs}) + +add_executable(grab-async grab-async.c) +target_link_libraries(grab-async ${libs}) + +add_executable(benchmark benchmark.c) +target_link_libraries(benchmark ${libs}) + +add_executable(perf perf-overhead.c) +target_link_libraries(perf ${libs}) + +add_subdirectory(gui) diff --git a/tools/benchmark.c b/tools/benchmark.c new file mode 100644 index 0000000..ef99fd1 --- /dev/null +++ b/tools/benchmark.c @@ -0,0 +1,267 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include +#include +#include +#include "uca-camera.h" +#include "uca-plugin-manager.h" + +typedef void (*GrabFrameFunc) (UcaCamera *camera, gpointer buffer, guint n_frames); + +static UcaCamera *camera = NULL; + +static void +sigint_handler(int signal) +{ + g_print ("Closing down libuca\n"); + uca_camera_stop_recording (camera, NULL); + g_object_unref (camera); + exit (signal); +} + +static void +print_usage (void) +{ + GList *types; + UcaPluginManager *manager; + + manager = uca_plugin_manager_new (); + g_print ("Usage: benchmark [ "); + types = uca_plugin_manager_get_available_cameras (manager); + + if (types == NULL) { + g_print ("] -- no camera plugin found\n"); + return; + } + + for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { + gchar *name = (gchar *) it->data; + if (g_list_next (it) == NULL) + g_print ("%s ]\n", name); + else + g_print ("%s, ", name); + } +} + +static void +log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user) +{ + gsize n_written; + GError *error = NULL; + GIOChannel *channel = user; + +#if GLIB_CHECK_VERSION(2, 26, 0) + GTimeZone *tz; + GDateTime *date_time; + gchar *new_message; + + tz = g_time_zone_new_local (); + date_time = g_date_time_new_now (tz); + + new_message = g_strdup_printf ("[%s] %s\n", + g_date_time_format (date_time, "%FT%H:%M:%S%z"), message); + + g_time_zone_unref (tz); + g_date_time_unref (date_time); + + g_io_channel_write_chars (channel, new_message, strlen (new_message), &n_written, &error); + g_assert_no_error (error); + g_free (new_message); +#else + g_io_channel_write_chars (channel, message, strlen (message), &n_written, &error); + g_assert_no_error (error); +#endif + + g_io_channel_flush (channel, &error); + g_assert_no_error (error); +} + +static void +grab_frames_sync (UcaCamera *camera, gpointer buffer, guint n_frames) +{ + GError *error = NULL; + + uca_camera_start_recording (camera, &error); + + for (guint i = 0; i < n_frames; i++) { + uca_camera_grab(camera, &buffer, &error); + + if (error != NULL) { + g_warning ("Error grabbing frame %02i/%i: `%s'", i, n_frames, error->message); + g_error_free (error); + error = NULL; + } + } + + uca_camera_stop_recording (camera, &error); +} + +static void +grab_callback (gpointer data, gpointer user_data) +{ + guint *n_acquired_frames = user_data; + *n_acquired_frames += 1; +} + +static void +grab_frames_async (UcaCamera *camera, gpointer buffer, guint n_frames) +{ + GError *error = NULL; + guint n_acquired_frames = 0; + + uca_camera_set_grab_func (camera, grab_callback, &n_acquired_frames); + uca_camera_start_recording (camera, &error); + + /* + * Behold! Spinlooping is probably a bad idea but nowadays single core + * machines are relatively rare. + */ + while (n_acquired_frames < n_frames) + ; + + uca_camera_stop_recording (camera, &error); + +} + +static void +benchmark_method (UcaCamera *camera, gpointer buffer, GrabFrameFunc func, guint n_runs, guint n_frames, guint n_bytes) +{ + GTimer *timer; + gdouble fps; + gdouble bandwidth; + gdouble total_time = 0.0; + GError *error = NULL; + + g_print ("%-10i%-10i", n_frames, n_runs); + timer = g_timer_new (); + g_assert_no_error (error); + + for (guint run = 0; run < n_runs; run++) { + g_message ("Start run %i of %i", run, n_runs); + g_timer_start (timer); + + func (camera, buffer, n_frames); + + g_timer_stop (timer); + total_time += g_timer_elapsed (timer, NULL); + } + + g_assert_no_error (error); + + fps = n_runs * n_frames / total_time; + bandwidth = n_bytes * fps / 1024 / 1024; + g_print ("%-16.2f%-16.2f\n", fps, bandwidth); + + g_timer_destroy (timer); +} + +static void +benchmark (UcaCamera *camera) +{ + const guint n_runs = 3; + const guint n_frames = 100; + + guint sensor_width; + guint sensor_height; + guint roi_width; + guint roi_height; + guint bits; + guint n_bytes_per_pixel; + guint n_bytes; + gdouble exposure = 0.00001; + gpointer buffer; + + g_object_set (G_OBJECT (camera), + "exposure-time", exposure, + NULL); + + g_object_get (G_OBJECT (camera), + "sensor-width", &sensor_width, + "sensor-height", &sensor_height, + "sensor-bitdepth", &bits, + "roi-width", &roi_width, + "roi-height", &roi_height, + "exposure-time", &exposure, + NULL); + + g_print ("# --- General information ---\n"); + g_print ("# Sensor size: %ix%i\n", sensor_width, sensor_height); + g_print ("# ROI size: %ix%i\n", roi_width, roi_height); + g_print ("# Exposure time: %fs\n", exposure); + + /* Synchronous frame acquisition */ + g_print ("# %-10s%-10s%-10s%-16s%-16s\n", "type", "n_frames", "n_runs", "frames/s", "MiB/s"); + g_print (" %-10s", "sync"); + + g_message ("Start synchronous benchmark"); + + n_bytes_per_pixel = bits > 8 ? 2 : 1; + n_bytes = roi_width * roi_height * n_bytes_per_pixel; + buffer = g_malloc0(n_bytes); + + benchmark_method (camera, buffer, grab_frames_sync, n_runs, n_frames, n_bytes); + + /* Asynchronous frame acquisition */ + g_object_set (G_OBJECT(camera), + "transfer-asynchronously", TRUE, + NULL); + + g_message ("Start asynchronous benchmark"); + g_print (" %-10s", "async"); + + benchmark_method (camera, buffer, grab_frames_async, n_runs, n_frames, n_bytes); + + g_free (buffer); +} + +int +main (int argc, char *argv[]) +{ + UcaPluginManager *manager; + GIOChannel *log_channel; + GError *error = NULL; + + (void) signal (SIGINT, sigint_handler); + g_type_init(); + + if (argc < 2) { + print_usage(); + return 1; + } + + log_channel = g_io_channel_new_file ("error.log", "a+", &error); + g_assert_no_error (error); + g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, log_channel); + + manager = uca_plugin_manager_new (); + camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + + if (camera == NULL) { + g_error ("Initialization: %s", error->message); + return 1; + } + + benchmark (camera); + + g_object_unref (camera); + g_io_channel_shutdown (log_channel, TRUE, &error); + g_assert_no_error (error); + + return 0; +} diff --git a/tools/grab-async.c b/tools/grab-async.c new file mode 100644 index 0000000..6132829 --- /dev/null +++ b/tools/grab-async.c @@ -0,0 +1,138 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include +#include +#include +#include "uca-plugin-manager.h" +#include "uca-camera.h" + +static UcaCamera *camera = NULL; + +typedef struct { + guint roi_width; + guint roi_height; + guint counter; +} CallbackData; + +static void +sigint_handler(int signal) +{ + printf("Closing down libuca\n"); + uca_camera_stop_recording(camera, NULL); + g_object_unref(camera); + exit(signal); +} + +static void +grab_callback(gpointer data, gpointer user_data) +{ + CallbackData *cbd = (CallbackData *) user_data; + gchar *filename = g_strdup_printf("frame-%04i.raw", cbd->counter++); + FILE *fp = fopen(filename, "wb"); + + fwrite(data, sizeof(guint16), cbd->roi_width * cbd->roi_height, fp); + g_print("."); + fclose(fp); + g_free(filename); +} + +static void +print_usage (void) +{ + GList *types; + UcaPluginManager *manager; + + manager = uca_plugin_manager_new (); + g_print ("Usage: benchmark [ "); + types = uca_plugin_manager_get_available_cameras (manager); + + if (types == NULL) { + g_print ("] -- no camera plugin found\n"); + return; + } + + for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { + gchar *name = (gchar *) it->data; + if (g_list_next (it) == NULL) + g_print ("%s ]\n", name); + else + g_print ("%s, ", name); + } +} + +int +main(int argc, char *argv[]) +{ + CallbackData cbd; + guint sensor_width, sensor_height; + gchar *name; + UcaPluginManager *manager; + GError *error = NULL; + (void) signal(SIGINT, sigint_handler); + + g_type_init(); + + if (argc < 2) { + print_usage(); + return 1; + } + + manager = uca_plugin_manager_new (); + camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + + if (camera == NULL) { + g_print("Error during initialization: %s\n", error->message); + return 1; + } + + g_object_get(G_OBJECT(camera), + "name", &name, + "sensor-width", &sensor_width, + "sensor-height", &sensor_height, + NULL); + + g_object_set(G_OBJECT(camera), + "roi-x0", 0, + "roi-y0", 0, + "roi-width", sensor_width, + "roi-height", sensor_height, + "transfer-asynchronously", TRUE, + NULL); + + g_object_get(G_OBJECT(camera), + "roi-width", &cbd.roi_width, + "roi-height", &cbd.roi_height, + NULL); + + g_print("Camera: %s\n", name); + g_free(name); + + g_print("Start asynchronous recording\n"); + cbd.counter = 0; + uca_camera_set_grab_func(camera, grab_callback, &cbd); + uca_camera_start_recording(camera, &error); + g_assert_no_error(error); + g_usleep(2 * G_USEC_PER_SEC); + + g_print(" done\n"); + uca_camera_stop_recording(camera, NULL); + g_object_unref(camera); + + return error != NULL ? 1 : 0; +} diff --git a/tools/grab.c b/tools/grab.c new file mode 100644 index 0000000..1f5c917 --- /dev/null +++ b/tools/grab.c @@ -0,0 +1,160 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include +#include +#include +#include "uca-plugin-manager.h" +#include "uca-camera.h" + +static UcaCamera *camera = NULL; + +static void sigint_handler(int signal) +{ + printf("Closing down libuca\n"); + uca_camera_stop_recording(camera, NULL); + g_object_unref(camera); + exit(signal); +} + +static void +print_usage (void) +{ + GList *types; + UcaPluginManager *manager; + + manager = uca_plugin_manager_new (); + g_print ("Usage: benchmark [ "); + types = uca_plugin_manager_get_available_cameras (manager); + + if (types == NULL) { + g_print ("] -- no camera plugin found\n"); + return; + } + + for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { + gchar *name = (gchar *) it->data; + if (g_list_next (it) == NULL) + g_print ("%s ]\n", name); + else + g_print ("%s, ", name); + } +} + +int main(int argc, char *argv[]) +{ + UcaPluginManager *manager; + GError *error = NULL; + (void) signal(SIGINT, sigint_handler); + + guint sensor_width, sensor_height; + guint roi_width, roi_height, roi_x, roi_y, roi_width_multiplier, roi_height_multiplier; + guint bits; + gchar *name; + + g_type_init(); + + if (argc < 2) { + print_usage(); + return 1; + } + + manager = uca_plugin_manager_new (); + camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + + if (camera == NULL) { + g_print("Error during initialization: %s\n", error->message); + return 1; + } + + g_object_get(G_OBJECT(camera), + "sensor-width", &sensor_width, + "sensor-height", &sensor_height, + "name", &name, + NULL); + + g_object_set(G_OBJECT(camera), + "exposure-time", 0.001, + "roi-x0", 0, + "roi-y0", 0, + "roi-width", 1000, + "roi-height", sensor_height, + NULL); + + g_object_get(G_OBJECT(camera), + "roi-width", &roi_width, + "roi-height", &roi_height, + "roi-width-multiplier", &roi_width_multiplier, + "roi-height-multiplier", &roi_height_multiplier, + "roi-x0", &roi_x, + "roi-y0", &roi_y, + "sensor-bitdepth", &bits, + NULL); + + g_print("Camera: %s\n", name); + g_free(name); + + g_print("Sensor: %ix%i px\n", sensor_width, sensor_height); + g_print("ROI: %ix%i @ (%i, %i), steps: %i, %i\n", + roi_width, roi_height, roi_x, roi_y, roi_width_multiplier, roi_height_multiplier); + + const int pixel_size = bits == 8 ? 1 : 2; + gpointer buffer = g_malloc0(roi_width * roi_height * pixel_size); + gchar filename[FILENAME_MAX]; + GTimer *timer = g_timer_new(); + + for (int i = 0; i < 1; i++) { + gint counter = 0; + g_print("Start recording\n"); + uca_camera_start_recording(camera, &error); + g_assert_no_error(error); + + while (counter < 5) { + g_print(" grab frame ... "); + g_timer_start(timer); + uca_camera_grab(camera, &buffer, &error); + + if (error != NULL) { + g_print("\nError: %s\n", error->message); + goto cleanup; + } + + g_timer_stop(timer); + g_print("done (took %3.5fs)\n", g_timer_elapsed(timer, NULL)); + + snprintf(filename, FILENAME_MAX, "frame-%08i.raw", counter++); + FILE *fp = fopen(filename, "wb"); + fwrite(buffer, roi_width * roi_height, pixel_size, fp); + fclose(fp); + g_usleep(2 * G_USEC_PER_SEC); + } + + g_print("Stop recording\n"); + uca_camera_stop_recording(camera, &error); + g_assert_no_error(error); + } + + g_timer_destroy(timer); + +cleanup: + uca_camera_stop_recording(camera, NULL); + g_object_unref(camera); + g_free(buffer); + + return error != NULL ? 1 : 0; +} diff --git a/tools/gui/control.c b/tools/gui/control.c new file mode 100644 index 0000000..75b3cde --- /dev/null +++ b/tools/gui/control.c @@ -0,0 +1,350 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "uca-camera.h" +#include "uca-plugin-manager.h" +#include "egg-property-tree-view.h" + + +typedef struct { + gboolean running; + gboolean store; + + guchar *buffer, *pixels; + GdkPixbuf *pixbuf; + GtkWidget *image; + GtkTreeModel *property_model; + UcaCamera *camera; + + GtkStatusbar *statusbar; + guint statusbar_context_id; + + int timestamp; + int width; + int height; + int pixel_size; +} ThreadData; + +enum { + COLUMN_NAME = 0, + COLUMN_VALUE, + COLUMN_EDITABLE, + NUM_COLUMNS +}; + +static UcaPluginManager *plugin_manager; + +static void +convert_8bit_to_rgb (guchar *output, guchar *input, int width, int height) +{ + for (int i = 0, j = 0; i < width*height; i++) { + output[j++] = input[i]; + output[j++] = input[i]; + output[j++] = input[i]; + } +} + +static void +convert_16bit_to_rgb (guchar *output, guchar *input, int width, int height) +{ + guint16 *in = (guint16 *) input; + guint16 min = G_MAXUINT16, max = 0; + gfloat spread = 0.0f; + + for (int i = 0; i < width * height; i++) { + guint16 v = in[i]; + if (v < min) + min = v; + if (v > max) + max = v; + } + + spread = (gfloat) max - min; + + if (spread > 0.0f) { + for (int i = 0, j = 0; i < width*height; i++) { + guchar val = (guint8) (((in[i] - min) / spread) * 255.0f); + output[j++] = val; + output[j++] = val; + output[j++] = val; + } + } +} + +static void * +grab_thread (void *args) +{ + ThreadData *data = (ThreadData *) args; + gchar filename[FILENAME_MAX] = {0,}; + gint counter = 0; + + while (data->running) { + uca_camera_grab (data->camera, (gpointer) &data->buffer, NULL); + + if (data->store) { + snprintf (filename, FILENAME_MAX, "frame-%i-%08i.raw", data->timestamp, counter++); + FILE *fp = fopen (filename, "wb"); + fwrite (data->buffer, data->width*data->height, data->pixel_size, fp); + fclose (fp); + } + + /* FIXME: We should actually check if this is really a new frame and + * just do nothing if it is an already displayed one. */ + 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); + } + + gdk_threads_enter (); + gdk_flush (); + gtk_image_clear (GTK_IMAGE (data->image)); + gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); + gtk_widget_queue_draw_area (data->image, 0, 0, data->width, data->height); + gdk_threads_leave (); + } + return NULL; +} + +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; + g_object_unref (td->camera); + gtk_main_quit (); +} + +static void +on_toolbutton_run_clicked (GtkWidget *widget, gpointer args) +{ + ThreadData *data = (ThreadData *) args; + + if (data->running) + return; + + GError *error = NULL; + data->running = TRUE; + + uca_camera_start_recording (data->camera, &error); + + if (error != NULL) { + g_printerr ("Failed to start recording: %s\n", error->message); + return; + } + + if (!g_thread_create (grab_thread, data, FALSE, &error)) { + g_printerr ("Failed to create thread: %s\n", error->message); + return; + } +} + +static void +on_toolbutton_stop_clicked (GtkWidget *widget, gpointer args) +{ + ThreadData *data = (ThreadData *) args; + data->running = FALSE; + data->store = FALSE; + GError *error = NULL; + uca_camera_stop_recording (data->camera, &error); + + if (error != NULL) + g_printerr ("Failed to stop: %s\n", error->message); +} + +static void +on_toolbutton_record_clicked (GtkWidget *widget, gpointer args) +{ + ThreadData *data = (ThreadData *) args; + data->timestamp = (int) time (0); + data->store = TRUE; + GError *error = NULL; + + gtk_statusbar_push (data->statusbar, data->statusbar_context_id, "Recording..."); + + if (data->running != TRUE) { + data->running = TRUE; + uca_camera_start_recording (data->camera, &error); + + if (!g_thread_create (grab_thread, data, FALSE, &error)) + g_printerr ("Failed to create thread: %s\n", error->message); + } +} + +static void +create_main_window (GtkBuilder *builder, const gchar* camera_name) +{ + static ThreadData td; + + GError *error = NULL; + UcaCamera *camera = uca_plugin_manager_new_camera (plugin_manager, camera_name, &error); + + if ((camera == NULL) || (error != NULL)) { + g_error ("%s\n", error->message); + gtk_main_quit (); + } + + guint bits_per_sample; + g_object_get (camera, + "roi-width", &td.width, + "roi-height", &td.height, + "sensor-bitdepth", &bits_per_sample, + NULL); + + GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); + GtkWidget *image = GTK_WIDGET (gtk_builder_get_object (builder, "image")); + GtkWidget *property_tree_view = egg_property_tree_view_new (G_OBJECT (camera)); + GtkContainer *scrolled_property_window = GTK_CONTAINER (gtk_builder_get_object (builder, "scrolledwindow2")); + + gtk_container_add (scrolled_property_window, property_tree_view); + gtk_widget_show_all (GTK_WIDGET (scrolled_property_window)); + + GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, td.width, td.height); + gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); + + td.pixel_size = bits_per_sample > 8 ? 2 : 1; + td.image = image; + td.pixbuf = pixbuf; + td.buffer = (guchar *) g_malloc (td.pixel_size * td.width * td.height); + td.pixels = gdk_pixbuf_get_pixels (pixbuf); + td.running = FALSE; + td.statusbar = GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")); + td.statusbar_context_id = gtk_statusbar_get_context_id (td.statusbar, "Recording Information"); + td.store = FALSE; + td.camera = camera; + td.property_model = GTK_TREE_MODEL (gtk_builder_get_object (builder, "camera-properties")); + + g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); + g_signal_connect (gtk_builder_get_object (builder, "toolbutton_run"), + "clicked", G_CALLBACK (on_toolbutton_run_clicked), &td); + g_signal_connect (gtk_builder_get_object (builder, "toolbutton_stop"), + "clicked", G_CALLBACK (on_toolbutton_stop_clicked), &td); + g_signal_connect (gtk_builder_get_object (builder, "toolbutton_record"), + "clicked", G_CALLBACK (on_toolbutton_record_clicked), &td); + + gtk_widget_show (image); + gtk_widget_show (window); +} + +static void +on_button_proceed_clicked (GtkWidget *widget, gpointer data) +{ + GtkBuilder *builder = GTK_BUILDER (data); + GtkWidget *choice_window = GTK_WIDGET (gtk_builder_get_object (builder, "choice-window")); + GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview-cameras")); + GtkListStore *list_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "camera-types")); + + GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); + GList *selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL); + GtkTreeIter iter; + + gtk_widget_destroy (choice_window); + gboolean valid = gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, selected_rows->data); + + if (valid) { + gchar *data; + gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &data, -1); + create_main_window (builder, data); + g_free (data); + } + + g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL); + g_list_free (selected_rows); +} + +static void +on_treeview_keypress (GtkWidget *widget, GdkEventKey *event, gpointer data) +{ + if (event->keyval == GDK_KEY_Return) + gtk_widget_grab_focus (GTK_WIDGET (data)); +} + +static void +create_choice_window (GtkBuilder *builder) +{ + GList *camera_types = uca_plugin_manager_get_available_cameras (plugin_manager); + + GtkWidget *choice_window = GTK_WIDGET (gtk_builder_get_object (builder, "choice-window")); + GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview-cameras")); + GtkListStore *list_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "camera-types")); + GtkButton *proceed_button = GTK_BUTTON (gtk_builder_get_object (builder, "button-proceed")); + GtkTreeIter iter; + + for (GList *it = g_list_first (camera_types); it != NULL; it = g_list_next (it)) { + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, 0, g_strdup ((gchar *) it->data), -1); + } + + gboolean valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter); + + if (valid) { + GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); + gtk_tree_selection_unselect_all (selection); + gtk_tree_selection_select_path (selection, gtk_tree_model_get_path (GTK_TREE_MODEL (list_store), &iter)); + } + + g_signal_connect (proceed_button, "clicked", G_CALLBACK (on_button_proceed_clicked), builder); + g_signal_connect (treeview, "key-press-event", G_CALLBACK (on_treeview_keypress), proceed_button); + gtk_widget_show_all (GTK_WIDGET (choice_window)); + + g_list_foreach (camera_types, (GFunc) g_free, NULL); + g_list_free (camera_types); +} + +int +main (int argc, char *argv[]) +{ + GError *error = NULL; + + g_thread_init (NULL); + gdk_threads_init (); + gtk_init (&argc, &argv); + + GtkBuilder *builder = gtk_builder_new (); + + if (!gtk_builder_add_from_file (builder, CONTROL_GLADE_PATH, &error)) { + g_print ("Error: %s\n", error->message); + return 1; + } + + plugin_manager = uca_plugin_manager_new (); + create_choice_window (builder); + gtk_builder_connect_signals (builder, NULL); + + gdk_threads_enter (); + gtk_main (); + gdk_threads_leave (); + + g_object_unref (plugin_manager); + return 0; +} diff --git a/tools/gui/control.glade b/tools/gui/control.glade new file mode 100644 index 0000000..d7ba2fc --- /dev/null +++ b/tools/gui/control.glade @@ -0,0 +1,302 @@ + + + + + + + + + + + + + + + + + + + + + + Camera Control + 1024 + 768 + + + + True + + + True + + + True + _File + True + + + True + + + gtk-new + True + True + True + + + + + gtk-open + True + True + True + + + + + gtk-save + True + True + True + + + + + gtk-save-as + True + True + True + + + + + True + + + + + gtk-quit + True + True + True + + + + + + + + + + True + _Help + True + + + True + + + gtk-about + True + True + True + + + + + + + + + False + 0 + + + + + True + + + True + Run + True + gtk-media-play + + + False + True + + + + + True + Record + True + gtk-media-record + + + False + True + + + + + True + Stop + True + gtk-media-stop + + + False + True + + + + + False + 1 + + + + + True + True + 6 + + + 300 + True + True + automatic + automatic + + + True + queue + + + True + gtk-missing-image + + + + + + + True + False + + + + + True + True + automatic + automatic + + + + + + True + True + + + + + 2 + + + + + True + 2 + + + False + 3 + + + + + + + 65535 + 1 + 65535 + 1 + 10 + + + 6 + + + True + 2 + + + True + True + camera-types + + + Choose camera + + + + 0 + + + + + + + 0 + + + + + True + 6 + end + + + gtk-quit + True + True + True + True + + + + False + False + 0 + + + + + gtk-ok + True + True + True + True + + + False + False + 1 + + + + + False + 6 + 1 + + + + + + diff --git a/tools/gui/egg-property-cell-renderer.c b/tools/gui/egg-property-cell-renderer.c new file mode 100644 index 0000000..9df5cc3 --- /dev/null +++ b/tools/gui/egg-property-cell-renderer.c @@ -0,0 +1,594 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include "egg-property-cell-renderer.h" + +G_DEFINE_TYPE (EggPropertyCellRenderer, egg_property_cell_renderer, GTK_TYPE_CELL_RENDERER) + +#define EGG_PROPERTY_CELL_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), EGG_TYPE_PROPERTY_CELL_RENDERER, EggPropertyCellRendererPrivate)) + + +struct _EggPropertyCellRendererPrivate +{ + GObject *object; + GtkListStore *list_store; + GtkCellRenderer *renderer; + GtkCellRenderer *text_renderer; + GtkCellRenderer *spin_renderer; + GtkCellRenderer *toggle_renderer; + GtkCellRenderer *combo_renderer; + GHashTable *combo_models; +}; + +enum +{ + PROP_0, + PROP_PROP_NAME, + N_PROPERTIES +}; + +enum +{ + COMBO_COLUMN_VALUE_NAME, + COMBO_COLUMN_VALUE, + N_COMBO_COLUMNS +}; + +static GParamSpec *egg_property_cell_renderer_properties[N_PROPERTIES] = { NULL, }; + +GtkCellRenderer * +egg_property_cell_renderer_new (GObject *object, + GtkListStore *list_store) +{ + EggPropertyCellRenderer *renderer; + + renderer = EGG_PROPERTY_CELL_RENDERER (g_object_new (EGG_TYPE_PROPERTY_CELL_RENDERER, NULL)); + renderer->priv->object = object; + renderer->priv->list_store = list_store; + return GTK_CELL_RENDERER (renderer); +} + +static GParamSpec * +get_pspec_from_object (GObject *object, const gchar *prop_name) +{ + GObjectClass *oclass = G_OBJECT_GET_CLASS (object); + return g_object_class_find_property (oclass, prop_name); +} + +static void +get_string_double_repr (GObject *object, const gchar *prop_name, gchar **text, gdouble *number) +{ + GParamSpec *pspec; + GValue from = { 0 }; + GValue to_string = { 0 }; + GValue to_double = { 0 }; + + pspec = get_pspec_from_object (object, prop_name); + g_value_init (&from, pspec->value_type); + g_value_init (&to_string, G_TYPE_STRING); + g_value_init (&to_double, G_TYPE_DOUBLE); + g_object_get_property (object, prop_name, &from); + + if (g_value_transform (&from, &to_string)) + *text = g_strdup (g_value_get_string (&to_string)); + else + g_warning ("Could not convert from %s gchar*\n", g_type_name (pspec->value_type)); + + if (g_value_transform (&from, &to_double)) + *number = g_value_get_double (&to_double); + else + g_warning ("Could not convert from %s to gdouble\n", g_type_name (pspec->value_type)); +} + +static void +clear_adjustment (GObject *object) +{ + GtkAdjustment *adjustment; + + g_object_get (object, + "adjustment", &adjustment, + NULL); + + if (adjustment) + g_object_unref (adjustment); + + g_object_set (object, + "adjustment", NULL, + NULL); +} + +static void +egg_property_cell_renderer_set_renderer (EggPropertyCellRenderer *renderer, + const gchar *prop_name) +{ + EggPropertyCellRendererPrivate *priv; + GParamSpec *pspec; + gchar *text = NULL; + gdouble number; + + priv = EGG_PROPERTY_CELL_RENDERER_GET_PRIVATE (renderer); + pspec = get_pspec_from_object (priv->object, prop_name); + + /* + * Set this renderers mode, so that any actions can be forwarded to our + * child renderers. + */ + switch (pspec->value_type) { + /* toggle renderers */ + case G_TYPE_BOOLEAN: + priv->renderer = priv->toggle_renderer; + g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL); + break; + + /* spin renderers */ + case G_TYPE_FLOAT: + case G_TYPE_DOUBLE: + priv->renderer = priv->spin_renderer; + g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_EDITABLE, NULL); + g_object_set (priv->renderer, "digits", 5, NULL); + break; + + case G_TYPE_INT: + case G_TYPE_UINT: + case G_TYPE_LONG: + case G_TYPE_ULONG: + case G_TYPE_INT64: + case G_TYPE_UINT64: + priv->renderer = priv->spin_renderer; + g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_EDITABLE, NULL); + g_object_set (priv->renderer, "digits", 0, NULL); + break; + + /* text renderers */ + case G_TYPE_POINTER: + case G_TYPE_STRING: + priv->renderer = priv->text_renderer; + g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_EDITABLE, NULL); + break; + + /* combo renderers */ + default: + if (G_TYPE_IS_ENUM (pspec->value_type)) { + priv->renderer = priv->combo_renderer; + g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_EDITABLE, NULL); + } + break; + } + + /* + * Set the content from the objects property. + */ + switch (pspec->value_type) { + case G_TYPE_BOOLEAN: + { + gboolean val; + + g_object_get (priv->object, prop_name, &val, NULL); + g_object_set (priv->renderer, + "active", val, + "activatable", pspec->flags & G_PARAM_WRITABLE ? TRUE : FALSE, + NULL); + break; + } + + case G_TYPE_INT: + case G_TYPE_UINT: + case G_TYPE_LONG: + case G_TYPE_ULONG: + case G_TYPE_INT64: + case G_TYPE_UINT64: + case G_TYPE_FLOAT: + case G_TYPE_DOUBLE: + get_string_double_repr (priv->object, prop_name, &text, &number); + break; + + case G_TYPE_STRING: + g_object_get (priv->object, prop_name, &text, NULL); + break; + + case G_TYPE_POINTER: + { + gpointer val; + + g_object_get (priv->object, prop_name, &val, NULL); + text = g_strdup_printf ("0x%x", GPOINTER_TO_INT (val)); + } + break; + + default: + if (G_TYPE_IS_ENUM (pspec->value_type)) { + GParamSpecEnum *pspec_enum; + GEnumClass *enum_class; + GtkTreeModel *combo_model; + GtkTreeIter iter; + gint value; + + g_object_get (priv->object, prop_name, &value, NULL); + + pspec_enum = G_PARAM_SPEC_ENUM (pspec); + enum_class = pspec_enum->enum_class; + combo_model = g_hash_table_lookup (priv->combo_models, prop_name); + + if (combo_model == NULL) { + combo_model = GTK_TREE_MODEL (gtk_list_store_new (N_COMBO_COLUMNS, G_TYPE_STRING, G_TYPE_INT)); + g_hash_table_insert (priv->combo_models, g_strdup (prop_name), combo_model); + + for (guint i = 0; i < enum_class->n_values; i++) { + gtk_list_store_append (GTK_LIST_STORE (combo_model), &iter); + gtk_list_store_set (GTK_LIST_STORE (combo_model), &iter, + COMBO_COLUMN_VALUE_NAME, enum_class->values[i].value_name, + COMBO_COLUMN_VALUE, enum_class->values[i].value, + -1); + } + } + + + for (guint i = 0; i < enum_class->n_values; i++) { + if (enum_class->values[i].value == value) + text = g_strdup (enum_class->values[i].value_name); + } + + g_object_set (priv->renderer, + "model", combo_model, + "text-column", 0, + NULL); + } + break; + } + + if (pspec->flags & G_PARAM_WRITABLE) { + if (GTK_IS_CELL_RENDERER_TOGGLE (priv->renderer)) + g_object_set (priv->renderer, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL); + else + g_object_set (priv->renderer, "foreground", "#000000", NULL); + + if (GTK_IS_CELL_RENDERER_TEXT (priv->renderer)) { + g_object_set (priv->renderer, + "editable", TRUE, + "mode", GTK_CELL_RENDERER_MODE_EDITABLE, + NULL); + } + + if (GTK_IS_CELL_RENDERER_SPIN (priv->renderer)) { + GtkObject *adjustment = NULL; + +#define gtk_typed_adjustment_new(type, pspec, val, step_inc, page_inc) \ + gtk_adjustment_new (val, ((type *) pspec)->minimum, ((type *) pspec)->maximum, step_inc, page_inc, 0) + + switch (pspec->value_type) { + case G_TYPE_INT: + adjustment = gtk_typed_adjustment_new (GParamSpecInt, pspec, number, 1, 10); + break; + case G_TYPE_UINT: + adjustment = gtk_typed_adjustment_new (GParamSpecUInt, pspec, number, 1, 10); + break; + case G_TYPE_LONG: + adjustment = gtk_typed_adjustment_new (GParamSpecLong, pspec, number, 1, 10); + break; + case G_TYPE_ULONG: + adjustment = gtk_typed_adjustment_new (GParamSpecULong, pspec, number, 1, 10); + break; + case G_TYPE_INT64: + adjustment = gtk_typed_adjustment_new (GParamSpecInt64, pspec, number, 1, 10); + break; + case G_TYPE_UINT64: + adjustment = gtk_typed_adjustment_new (GParamSpecUInt64, pspec, number, 1, 10); + break; + case G_TYPE_FLOAT: + adjustment = gtk_typed_adjustment_new (GParamSpecFloat, pspec, number, 0.05, 10); + break; + case G_TYPE_DOUBLE: + adjustment = gtk_typed_adjustment_new (GParamSpecDouble, pspec, number, 0.05, 10); + break; + } + + clear_adjustment (G_OBJECT (priv->renderer)); + g_object_set (priv->renderer, "adjustment", adjustment, NULL); + } + } + else { + g_object_set (priv->renderer, "mode", GTK_CELL_RENDERER_MODE_INERT, NULL); + + if (!GTK_IS_CELL_RENDERER_TOGGLE (priv->renderer)) + g_object_set (priv->renderer, "foreground", "#aaaaaa", NULL); + } + + if (text != NULL) { + g_object_set (priv->renderer, "text", text, NULL); + g_free (text); + } +} + +static gchar * +get_prop_name_from_tree_model (GtkTreeModel *model, const gchar *path) +{ + GtkTreeIter iter; + gchar *prop_name = NULL; + + /* TODO: don't assume column 0 to contain the prop name */ + if (gtk_tree_model_get_iter_from_string (model, &iter, path)) + gtk_tree_model_get (model, &iter, 0, &prop_name, -1); + + return prop_name; +} + +static void +egg_property_cell_renderer_toggle_cb (GtkCellRendererToggle *renderer, + gchar *path, + gpointer user_data) +{ + EggPropertyCellRendererPrivate *priv; + gchar *prop_name; + + priv = (EggPropertyCellRendererPrivate *) user_data; + prop_name = get_prop_name_from_tree_model (GTK_TREE_MODEL (priv->list_store), path); + + if (prop_name != NULL) { + gboolean activated; + + g_object_get (priv->object, prop_name, &activated, NULL); + g_object_set (priv->object, prop_name, !activated, NULL); + g_free (prop_name); + } +} + +static void +egg_property_cell_renderer_text_edited_cb (GtkCellRendererText *renderer, + gchar *path, + gchar *new_text, + gpointer user_data) +{ + EggPropertyCellRendererPrivate *priv; + gchar *prop_name; + + priv = (EggPropertyCellRendererPrivate *) user_data; + prop_name = get_prop_name_from_tree_model (GTK_TREE_MODEL (priv->list_store), path); + + if (prop_name != NULL) { + g_object_set (priv->object, prop_name, new_text, NULL); + g_free (prop_name); + } +} + +static void +egg_property_cell_renderer_spin_edited_cb (GtkCellRendererText *renderer, + gchar *path, + gchar *new_text, + gpointer user_data) +{ + EggPropertyCellRendererPrivate *priv; + gchar *prop_name; + + priv = (EggPropertyCellRendererPrivate *) user_data; + prop_name = get_prop_name_from_tree_model (GTK_TREE_MODEL (priv->list_store), path); + + if (prop_name != NULL) { + GParamSpec *pspec; + GValue from = { 0 }; + GValue to = { 0 }; + + pspec = get_pspec_from_object (priv->object, prop_name); + + g_value_init (&from, G_TYPE_DOUBLE); + g_value_init (&to, pspec->value_type); + g_value_set_double (&from, strtod (new_text, NULL)); + + if (g_value_transform (&from, &to)) + g_object_set_property (priv->object, prop_name, &to); + else + g_warning ("Could not transform %s to %s\n", + g_value_get_string (&from), g_type_name (pspec->value_type)); + + g_free (prop_name); + } +} + +static void +egg_property_cell_renderer_changed_cb (GtkCellRendererCombo *combo, + gchar *path, + GtkTreeIter *new_iter, + gpointer user_data) +{ + EggPropertyCellRendererPrivate *priv; + gchar *prop_name; + + priv = (EggPropertyCellRendererPrivate *) user_data; + prop_name = get_prop_name_from_tree_model (GTK_TREE_MODEL (priv->list_store), path); + + if (prop_name != NULL) { + GtkTreeModel *combo_model; + gchar *value_name; + gint value; + + combo_model = g_hash_table_lookup (priv->combo_models, prop_name); + + gtk_tree_model_get (combo_model, new_iter, + COMBO_COLUMN_VALUE_NAME, &value_name, + COMBO_COLUMN_VALUE, &value, + -1); + + g_object_set (priv->object, prop_name, value, NULL); + g_free (value_name); + g_free (prop_name); + } +} + +static void +egg_property_cell_renderer_get_size (GtkCellRenderer *cell, + GtkWidget *widget, + GdkRectangle *cell_area, + gint *x_offset, + gint *y_offset, + gint *width, + gint *height) +{ + + EggPropertyCellRendererPrivate *priv = EGG_PROPERTY_CELL_RENDERER_GET_PRIVATE (cell); + gtk_cell_renderer_get_size (priv->renderer, widget, cell_area, x_offset, y_offset, width, height); +} + +static void +egg_property_cell_renderer_render (GtkCellRenderer *cell, + GdkDrawable *window, + GtkWidget *widget, + GdkRectangle *background_area, + GdkRectangle *cell_area, + GdkRectangle *expose_area, + GtkCellRendererState flags) +{ + EggPropertyCellRendererPrivate *priv = EGG_PROPERTY_CELL_RENDERER_GET_PRIVATE (cell); + gtk_cell_renderer_render (priv->renderer, window, widget, background_area, cell_area, expose_area, flags); +} + +static gboolean +egg_property_cell_renderer_activate (GtkCellRenderer *cell, + GdkEvent *event, + GtkWidget *widget, + const gchar *path, + GdkRectangle *background_area, + GdkRectangle *cell_area, + GtkCellRendererState flags) +{ + EggPropertyCellRendererPrivate *priv = EGG_PROPERTY_CELL_RENDERER_GET_PRIVATE (cell); + return gtk_cell_renderer_activate (priv->renderer, event, widget, path, background_area, cell_area, flags); +} + +static GtkCellEditable * +egg_property_cell_renderer_start_editing (GtkCellRenderer *cell, + GdkEvent *event, + GtkWidget *widget, + const gchar *path, + GdkRectangle *background_area, + GdkRectangle *cell_area, + GtkCellRendererState flags) +{ + EggPropertyCellRendererPrivate *priv = EGG_PROPERTY_CELL_RENDERER_GET_PRIVATE (cell); + return gtk_cell_renderer_start_editing (priv->renderer, event, widget, path, background_area, cell_area, flags); +} + +static void +egg_property_cell_renderer_dispose (GObject *object) +{ + EggPropertyCellRenderer *renderer = EGG_PROPERTY_CELL_RENDERER (object); + g_hash_table_destroy (renderer->priv->combo_models); +} + +static void +egg_property_cell_renderer_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + g_return_if_fail (EGG_IS_PROPERTY_CELL_RENDERER (object)); + EggPropertyCellRenderer *renderer = EGG_PROPERTY_CELL_RENDERER (object); + + switch (property_id) { + case PROP_PROP_NAME: + egg_property_cell_renderer_set_renderer (renderer, g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + return; + } +} + +static void +egg_property_cell_renderer_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + g_return_if_fail (EGG_IS_PROPERTY_CELL_RENDERER (object)); + + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + return; + } +} + +static void +egg_property_cell_renderer_class_init (EggPropertyCellRendererClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkCellRendererClass *cellrenderer_class = GTK_CELL_RENDERER_CLASS (klass); + + gobject_class->set_property = egg_property_cell_renderer_set_property; + gobject_class->get_property = egg_property_cell_renderer_get_property; + gobject_class->dispose = egg_property_cell_renderer_dispose; + + cellrenderer_class->render = egg_property_cell_renderer_render; + cellrenderer_class->get_size = egg_property_cell_renderer_get_size; + cellrenderer_class->activate = egg_property_cell_renderer_activate; + cellrenderer_class->start_editing = egg_property_cell_renderer_start_editing; + + egg_property_cell_renderer_properties[PROP_PROP_NAME] = + g_param_spec_string("prop-name", + "Property name", "Property name", "", + G_PARAM_READWRITE); + + g_object_class_install_property(gobject_class, PROP_PROP_NAME, egg_property_cell_renderer_properties[PROP_PROP_NAME]); + + g_type_class_add_private (klass, sizeof (EggPropertyCellRendererPrivate)); +} + +static void +egg_property_cell_renderer_init (EggPropertyCellRenderer *renderer) +{ + EggPropertyCellRendererPrivate *priv; + + renderer->priv = priv = EGG_PROPERTY_CELL_RENDERER_GET_PRIVATE (renderer); + + priv->text_renderer = gtk_cell_renderer_text_new (); + priv->spin_renderer = gtk_cell_renderer_spin_new (); + priv->toggle_renderer = gtk_cell_renderer_toggle_new (); + priv->combo_renderer = gtk_cell_renderer_combo_new (); + priv->renderer = priv->text_renderer; + priv->combo_models = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + + g_object_set (priv->text_renderer, + "editable", TRUE, + NULL); + + g_object_set (priv->spin_renderer, + "editable", TRUE, + NULL); + + g_object_set (priv->toggle_renderer, + "xalign", 0.0f, + "activatable", TRUE, + "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, + NULL); + + g_object_set (priv->combo_renderer, + "has-entry", FALSE, + NULL); + + g_signal_connect (priv->spin_renderer, "edited", + G_CALLBACK (egg_property_cell_renderer_spin_edited_cb), priv); + + g_signal_connect (priv->text_renderer, "edited", + G_CALLBACK (egg_property_cell_renderer_text_edited_cb), NULL); + + g_signal_connect (priv->toggle_renderer, "toggled", + G_CALLBACK (egg_property_cell_renderer_toggle_cb), priv); + + g_signal_connect (priv->combo_renderer, "changed", + G_CALLBACK (egg_property_cell_renderer_changed_cb), priv); +} diff --git a/tools/gui/egg-property-cell-renderer.h b/tools/gui/egg-property-cell-renderer.h new file mode 100644 index 0000000..d4dbe02 --- /dev/null +++ b/tools/gui/egg-property-cell-renderer.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#ifndef EGG_PROPERTY_CELL_RENDERER_H +#define EGG_PROPERTY_CELL_RENDERER_H + +#include + +G_BEGIN_DECLS + +#define EGG_TYPE_PROPERTY_CELL_RENDERER (egg_property_cell_renderer_get_type()) +#define EGG_PROPERTY_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), EGG_TYPE_PROPERTY_CELL_RENDERER, EggPropertyCellRenderer)) +#define EGG_IS_PROPERTY_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), EGG_TYPE_PROPERTY_CELL_RENDERER)) +#define EGG_PROPERTY_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EGG_TYPE_PROPERTY_CELL_RENDERER, EggPropertyCellRendererClass)) +#define EGG_IS_PROPERTY_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EGG_TYPE_PROPERTY_CELL_RENDERER)) +#define EGG_PROPERTY_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EGG_TYPE_PROPERTY_CELL_RENDERER, EggPropertyCellRendererClass)) + +typedef struct _EggPropertyCellRenderer EggPropertyCellRenderer; +typedef struct _EggPropertyCellRendererClass EggPropertyCellRendererClass; +typedef struct _EggPropertyCellRendererPrivate EggPropertyCellRendererPrivate; + +struct _EggPropertyCellRenderer +{ + GtkCellRenderer parent_instance; + + /*< private >*/ + EggPropertyCellRendererPrivate *priv; +}; + +struct _EggPropertyCellRendererClass +{ + GtkCellRendererClass parent_class; +}; + +GType egg_property_cell_renderer_get_type (void); +GtkCellRenderer* egg_property_cell_renderer_new (GObject *object, + GtkListStore *list_store); + +G_END_DECLS + +#endif diff --git a/tools/gui/egg-property-tree-view.c b/tools/gui/egg-property-tree-view.c new file mode 100644 index 0000000..52d1e10 --- /dev/null +++ b/tools/gui/egg-property-tree-view.c @@ -0,0 +1,113 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + + +#include "egg-property-tree-view.h" +#include "egg-property-cell-renderer.h" + +G_DEFINE_TYPE (EggPropertyTreeView, egg_property_tree_view, GTK_TYPE_TREE_VIEW) + +#define EGG_PROPERTY_TREE_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), EGG_TYPE_PROPERTY_TREE_VIEW, EggPropertyTreeViewPrivate)) + +struct _EggPropertyTreeViewPrivate +{ + GtkListStore *list_store; +}; + +enum +{ + COLUMN_PROP_NAME, + COLUMN_PROP_ROW, + COLUMN_PROP_ADJUSTMENT, + N_COLUMNS +}; + +static void +egg_property_tree_view_populate_model_with_properties (GtkListStore *model, GObject *object) +{ + GParamSpec **pspecs; + GObjectClass *oclass; + guint n_properties; + GtkTreeIter iter; + + oclass = G_OBJECT_GET_CLASS (object); + pspecs = g_object_class_list_properties (oclass, &n_properties); + + for (guint i = 0; i < n_properties; i++) { + if (pspecs[i]->flags & G_PARAM_READABLE) { + GtkObject *adjustment; + + adjustment = gtk_adjustment_new (5, 0, 1000, 1, 10, 0); + + gtk_list_store_append (model, &iter); + gtk_list_store_set (model, &iter, + COLUMN_PROP_NAME, pspecs[i]->name, + COLUMN_PROP_ROW, FALSE, + COLUMN_PROP_ADJUSTMENT, adjustment, + -1); + } + } + + g_free (pspecs); +} + +GtkWidget * +egg_property_tree_view_new (GObject *object) +{ + EggPropertyTreeView *property_tree_view; + GtkTreeView *tree_view; + GtkTreeViewColumn *prop_column, *value_column; + GtkCellRenderer *prop_renderer, *value_renderer; + GtkListStore *list_store; + + property_tree_view = EGG_PROPERTY_TREE_VIEW (g_object_new (EGG_TYPE_PROPERTY_TREE_VIEW, NULL)); + list_store = property_tree_view->priv->list_store; + tree_view = GTK_TREE_VIEW (property_tree_view); + + egg_property_tree_view_populate_model_with_properties (list_store, object); + gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store)); + + prop_renderer = gtk_cell_renderer_text_new (); + prop_column = gtk_tree_view_column_new_with_attributes ("Property", prop_renderer, + "text", COLUMN_PROP_NAME, + NULL); + + value_renderer = egg_property_cell_renderer_new (object, list_store); + value_column = gtk_tree_view_column_new_with_attributes ("Value", value_renderer, + "prop-name", COLUMN_PROP_NAME, + NULL); + + gtk_tree_view_append_column (tree_view, prop_column); + gtk_tree_view_append_column (tree_view, value_column); + + return GTK_WIDGET (tree_view); +} + +static void +egg_property_tree_view_class_init (EggPropertyTreeViewClass *klass) +{ + g_type_class_add_private (klass, sizeof (EggPropertyTreeViewPrivate)); +} + +static void +egg_property_tree_view_init (EggPropertyTreeView *tree_view) +{ + EggPropertyTreeViewPrivate *priv = EGG_PROPERTY_TREE_VIEW_GET_PRIVATE (tree_view); + + tree_view->priv = priv = EGG_PROPERTY_TREE_VIEW_GET_PRIVATE (tree_view); + priv->list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_BOOLEAN, GTK_TYPE_ADJUSTMENT); +} diff --git a/tools/gui/egg-property-tree-view.h b/tools/gui/egg-property-tree-view.h new file mode 100644 index 0000000..e8fd0fe --- /dev/null +++ b/tools/gui/egg-property-tree-view.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#ifndef EGG_PROPERTY_TREE_VIEW_H +#define EGG_PROPERTY_TREE_VIEW_H + +#include + +G_BEGIN_DECLS + +#define EGG_TYPE_PROPERTY_TREE_VIEW (egg_property_tree_view_get_type()) +#define EGG_PROPERTY_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), EGG_TYPE_PROPERTY_TREE_VIEW, EggPropertyTreeView)) +#define EGG_IS_PROPERTY_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), EGG_TYPE_PROPERTY_TREE_VIEW)) +#define EGG_PROPERTY_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EGG_TYPE_PROPERTY_TREE_VIEW, EggPropertyTreeViewClass)) +#define EGG_IS_PROPERTY_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EGG_TYPE_PROPERTY_TREE_VIEW)) +#define EGG_PROPERTY_TREE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EGG_TYPE_PROPERTY_TREE_VIEW, EggPropertyTreeViewClass)) + +typedef struct _EggPropertyTreeView EggPropertyTreeView; +typedef struct _EggPropertyTreeViewClass EggPropertyTreeViewClass; +typedef struct _EggPropertyTreeViewPrivate EggPropertyTreeViewPrivate; + +struct _EggPropertyTreeView +{ + GtkTreeView parent_instance; + + /*< private >*/ + EggPropertyTreeViewPrivate *priv; +}; + +struct _EggPropertyTreeViewClass +{ + GtkTreeViewClass parent_class; +}; + +GType egg_property_tree_view_get_type (void) G_GNUC_CONST; +GtkWidget* egg_property_tree_view_new (GObject *object); + +G_END_DECLS + +#endif diff --git a/tools/perf-overhead.c b/tools/perf-overhead.c new file mode 100644 index 0000000..f8bdcbd --- /dev/null +++ b/tools/perf-overhead.c @@ -0,0 +1,181 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include +#include +#include +#include +#include "uca-plugin-manager.h" +#include "uca-camera.h" + +#define handle_error(errno) {if ((errno) != UCA_NO_ERROR) printf("error at <%s:%i>\n", \ + __FILE__, __LINE__);} + +typedef struct { + guint counter; + gsize size; + gpointer destination; +} thread_data; + +static UcaCamera *camera = NULL; + +static void +sigint_handler (int signal) +{ + printf ("Closing down libuca\n"); + uca_camera_stop_recording (camera, NULL); + g_object_unref (camera); + exit (signal); +} + +static void +print_usage (void) +{ + GList *types; + UcaPluginManager *manager; + + manager = uca_plugin_manager_new (); + g_print ("Usage: benchmark [ "); + types = uca_plugin_manager_get_available_cameras (manager); + + if (types == NULL) { + g_print ("] -- no camera plugin found\n"); + return; + } + + for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { + gchar *name = (gchar *) it->data; + if (g_list_next (it) == NULL) + g_print ("%s ]\n", name); + else + g_print ("%s, ", name); + } +} + +static void +test_synchronous_operation (UcaCamera *camera) +{ + GError *error = NULL; + guint width, height, bits; + g_object_get (G_OBJECT (camera), + "sensor-width", &width, + "sensor-height", &height, + "sensor-bitdepth", &bits, + NULL); + + const int pixel_size = bits == 8 ? 1 : 2; + const gsize size = width * height * pixel_size; + const guint n_trials = 10000; + gpointer buffer = g_malloc0(size); + + uca_camera_start_recording (camera, &error); + GTimer *timer = g_timer_new (); + + for (guint n = 0; n < n_trials; n++) + uca_camera_grab (camera, &buffer, &error); + + gdouble total_time = g_timer_elapsed (timer, NULL); + g_timer_stop (timer); + + g_print ("Synchronous data transfer\n"); + g_print (" Bandwidth: %3.2f MB/s\n", size * n_trials / 1024. / 1024. / total_time); + g_print (" Throughput: %3.2f frames/s\n", n_trials / total_time); + + uca_camera_stop_recording (camera, &error); + g_free (buffer); + g_timer_destroy (timer); +} + +static void +grab_func (gpointer data, gpointer user_data) +{ + static GStaticMutex mutex = G_STATIC_MUTEX_INIT; + + thread_data *d = (thread_data *) user_data; + g_memmove (d->destination, data, d->size); + g_static_mutex_lock (&mutex); + d->counter++; + g_static_mutex_unlock (&mutex); +} + +static void +test_asynchronous_operation (UcaCamera *camera) +{ + GError *error = NULL; + guint width, height, bits; + + g_object_get (G_OBJECT (camera), + "sensor-width", &width, + "sensor-height", &height, + "sensor-bitdepth", &bits, + NULL); + + const guint pixel_size = bits == 8 ? 1 : 2; + + thread_data d = { + .counter = 0, + .size = width * height * pixel_size, + .destination = g_malloc0(width * height * pixel_size) + }; + + g_object_set (G_OBJECT (camera), + "transfer-asynchronously", TRUE, + NULL); + + uca_camera_set_grab_func (camera, &grab_func, &d); + uca_camera_start_recording (camera, &error); + g_usleep (G_USEC_PER_SEC); + uca_camera_stop_recording (camera, &error); + + g_print ("Asynchronous data transfer\n"); + g_print (" Bandwidth: %3.2f MB/s\n", d.size * d.counter / 1024. / 1024.); + g_print (" Throughput: %i frames/s\n", d.counter); + + g_free (d.destination); +} + +int +main (int argc, char *argv[]) +{ + UcaPluginManager *manager; + GError *error = NULL; + (void) signal (SIGINT, sigint_handler); + + g_type_init (); + if (argc < 2) { + print_usage (); + return 1; + } + + manager = uca_plugin_manager_new (); + camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + + if (camera == NULL) { + g_print ("Error during initialization: %s\n", error->message); + return 1; + } + + test_synchronous_operation (camera); + g_print ("\n"); + test_asynchronous_operation (camera); + + g_object_unref (camera); + g_object_unref (manager); + + return error != NULL ? 1 : 0; +} -- cgit v1.2.3 From f92e2316665c75ed44f1c662cf7aa62fcbf6d419 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Tue, 25 Sep 2012 18:18:53 +0200 Subject: Add CMakeLists.txt for control GUI --- tools/gui/CMakeLists.txt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tools/gui/CMakeLists.txt (limited to 'tools') diff --git a/tools/gui/CMakeLists.txt b/tools/gui/CMakeLists.txt new file mode 100644 index 0000000..39afe98 --- /dev/null +++ b/tools/gui/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 2.8) + +add_definitions("--std=c99 -Wall") + +# --- Find packages and libraries --------------------------------------------- +find_package(PkgConfig) + +pkg_check_modules(GTK2 gtk+-2.0>=2.22) +pkg_check_modules(GTHREAD2 gthread-2.0) +pkg_check_modules(GLIB2 glib-2.0>=2.24 REQUIRED) +pkg_check_modules(GOBJECT2 gobject-2.0>=2.24 REQUIRED) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/control.glade ${CMAKE_CURRENT_BINARY_DIR}) + +# --- Build targets ----------------------------------------------------------- +include_directories( + ${GLIB2_INCLUDE_DIRS} + ${GOBJECT2_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR}/../../src/ + ${CMAKE_CURRENT_SOURCE_DIR}/../../src + ) + +if (GTK2_FOUND) + include_directories(${GTK2_INCLUDE_DIRS}) + + add_executable(control + control.c + egg-property-cell-renderer.c + egg-property-tree-view.c) + + target_link_libraries(control uca + ${GTK2_LIBRARIES} ${GTHREAD2_LIBRARIES}) + + install(TARGETS control + RUNTIME DESTINATION bin) + + install(FILES control.glade + DESTINATION share/libuca) +endif() -- cgit v1.2.3 From 4e78a33ab00c8437d341a4cb83919e2a67e54493 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 8 Oct 2012 10:04:18 +0200 Subject: Generate documentation for the base camera object --- tools/gen-doc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/gen-doc.c b/tools/gen-doc.c index d9b6b41..86d6ff9 100644 --- a/tools/gen-doc.c +++ b/tools/gen-doc.c @@ -124,25 +124,29 @@ int main(int argc, char *argv[]) { UcaPluginManager *manager; UcaCamera *camera; + gchar *name; GError *error = NULL; g_type_init(); + manager = uca_plugin_manager_new (); if (argc < 2) { - print_usage(); - return 1; + name = g_strdup ("Basic camera"); + camera = g_object_new (UCA_TYPE_CAMERA, NULL); + } + else { + name = argv[1]; + camera = uca_plugin_manager_new_camera (manager, name, &error); } - - manager = uca_plugin_manager_new (); - camera = uca_plugin_manager_new_camera (manager, argv[1], &error); if (camera == NULL) { g_print("Error during initialization: %s\n", error->message); + print_usage(); return 1; } - g_print (html_header, argv[1]); - g_print ("

Property documentation of %s

", argv[1]); + g_print (html_header, name); + g_print ("

Property documentation of %s

", name); print_properties (camera); g_print ("%s\n", html_footer); -- cgit v1.2.3 From b3dbedeec78a55802565a3824ab52188e8b9bd4d Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 8 Oct 2012 14:38:16 +0200 Subject: Generate introspection files Unfortunately, the gir tools recognize anything with $PREFIX_new_$SUFFIX as some kind of constructor. This means that we have to rename uca_plugin_manager_new_camera() to uca_plugin_manager_get_camera(). --- tools/benchmark.c | 2 +- tools/gen-doc.c | 2 +- tools/grab-async.c | 2 +- tools/grab.c | 2 +- tools/gui/control.c | 2 +- tools/perf-overhead.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/benchmark.c b/tools/benchmark.c index ef99fd1..bff8b50 100644 --- a/tools/benchmark.c +++ b/tools/benchmark.c @@ -250,7 +250,7 @@ main (int argc, char *argv[]) g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, log_channel); manager = uca_plugin_manager_new (); - camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + camera = uca_plugin_manager_get_camera (manager, argv[1], &error); if (camera == NULL) { g_error ("Initialization: %s", error->message); diff --git a/tools/gen-doc.c b/tools/gen-doc.c index 86d6ff9..f555a5f 100644 --- a/tools/gen-doc.c +++ b/tools/gen-doc.c @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) } else { name = argv[1]; - camera = uca_plugin_manager_new_camera (manager, name, &error); + camera = uca_plugin_manager_get_camera (manager, name, &error); } if (camera == NULL) { diff --git a/tools/grab-async.c b/tools/grab-async.c index 6132829..2c4bf04 100644 --- a/tools/grab-async.c +++ b/tools/grab-async.c @@ -94,7 +94,7 @@ main(int argc, char *argv[]) } manager = uca_plugin_manager_new (); - camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + camera = uca_plugin_manager_get_camera (manager, argv[1], &error); if (camera == NULL) { g_print("Error during initialization: %s\n", error->message); diff --git a/tools/grab.c b/tools/grab.c index 1f5c917..1518997 100644 --- a/tools/grab.c +++ b/tools/grab.c @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) } manager = uca_plugin_manager_new (); - camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + camera = uca_plugin_manager_get_camera (manager, argv[1], &error); if (camera == NULL) { g_print("Error during initialization: %s\n", error->message); diff --git a/tools/gui/control.c b/tools/gui/control.c index 75b3cde..178c809 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -207,7 +207,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) static ThreadData td; GError *error = NULL; - UcaCamera *camera = uca_plugin_manager_new_camera (plugin_manager, camera_name, &error); + UcaCamera *camera = uca_plugin_manager_get_camera (plugin_manager, camera_name, &error); if ((camera == NULL) || (error != NULL)) { g_error ("%s\n", error->message); diff --git a/tools/perf-overhead.c b/tools/perf-overhead.c index f8bdcbd..6735e6f 100644 --- a/tools/perf-overhead.c +++ b/tools/perf-overhead.c @@ -163,7 +163,7 @@ main (int argc, char *argv[]) } manager = uca_plugin_manager_new (); - camera = uca_plugin_manager_new_camera (manager, argv[1], &error); + camera = uca_plugin_manager_get_camera (manager, argv[1], &error); if (camera == NULL) { g_print ("Error during initialization: %s\n", error->message); -- cgit v1.2.3 From 0badcd14dc0ba8b3b6894be035237b846e3fb0e6 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Tue, 9 Oct 2012 16:52:17 +0200 Subject: Remove unneccessary variable --- tools/gui/control.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 178c809..89e932a 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -37,7 +37,6 @@ typedef struct { guchar *buffer, *pixels; GdkPixbuf *pixbuf; GtkWidget *image; - GtkTreeModel *property_model; UcaCamera *camera; GtkStatusbar *statusbar; @@ -242,7 +241,6 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.statusbar_context_id = gtk_statusbar_get_context_id (td.statusbar, "Recording Information"); td.store = FALSE; td.camera = camera; - td.property_model = GTK_TREE_MODEL (gtk_builder_get_object (builder, "camera-properties")); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); g_signal_connect (gtk_builder_get_object (builder, "toolbutton_run"), -- cgit v1.2.3 From 9d84d920da67f857ef31a2a2b475b191ec3c6c55 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Tue, 9 Oct 2012 16:52:36 +0200 Subject: Use scrolled window for camera choice --- tools/gui/control.glade | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.glade b/tools/gui/control.glade index d7ba2fc..ad5a91f 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -235,18 +235,28 @@ True 2 - + True True - camera-types + automatic + automatic - - Choose camera + + True + True + camera-types + False + 0 - - - 0 - + + Choose camera + + + + 0 + + + -- cgit v1.2.3 From 08a794b59a02a36028da90f31e165e7f44ef28e5 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 10 Oct 2012 09:15:21 +0200 Subject: Add histogram view skeleton --- tools/gui/CMakeLists.txt | 3 +- tools/gui/egg-histogram-view.c | 100 +++++++++++++++++++++++++++++++++++++++++ tools/gui/egg-histogram-view.h | 54 ++++++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 tools/gui/egg-histogram-view.c create mode 100644 tools/gui/egg-histogram-view.h (limited to 'tools') diff --git a/tools/gui/CMakeLists.txt b/tools/gui/CMakeLists.txt index 39afe98..b30f3ea 100644 --- a/tools/gui/CMakeLists.txt +++ b/tools/gui/CMakeLists.txt @@ -26,7 +26,8 @@ if (GTK2_FOUND) add_executable(control control.c egg-property-cell-renderer.c - egg-property-tree-view.c) + egg-property-tree-view.c + egg-histogram-view.c) target_link_libraries(control uca ${GTK2_LIBRARIES} ${GTHREAD2_LIBRARIES}) diff --git a/tools/gui/egg-histogram-view.c b/tools/gui/egg-histogram-view.c new file mode 100644 index 0000000..809a2d9 --- /dev/null +++ b/tools/gui/egg-histogram-view.c @@ -0,0 +1,100 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#include +#include "egg-histogram-view.h" + +G_DEFINE_TYPE (EggHistogramView, egg_histogram_view, GTK_TYPE_CELL_RENDERER) + +#define EGG_HISTOGRAM_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), EGG_TYPE_HISTOGRAM_VIEW, EggHistogramViewPrivate)) + + +struct _EggHistogramViewPrivate +{ + guint foo; +}; + +enum +{ + PROP_0, + N_PROPERTIES +}; + +static GParamSpec *egg_histogram_view_properties[N_PROPERTIES] = { NULL, }; + + +GtkWidget * +egg_histogram_view_new (void) +{ + EggHistogramView *view; + + view = EGG_HISTOGRAM_VIEW (g_object_new (EGG_TYPE_HISTOGRAM_VIEW, NULL)); + return GTK_WIDGET (view); +} + +static void +egg_histogram_view_dispose (GObject *object) +{ +} + +static void +egg_histogram_view_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + g_return_if_fail (EGG_IS_HISTOGRAM_VIEW (object)); + + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + return; + } +} + +static void +egg_histogram_view_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + g_return_if_fail (EGG_IS_HISTOGRAM_VIEW (object)); + + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + return; + } +} + +static void +egg_histogram_view_class_init (EggHistogramViewClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = egg_histogram_view_set_property; + gobject_class->get_property = egg_histogram_view_get_property; + gobject_class->dispose = egg_histogram_view_dispose; + + g_type_class_add_private (klass, sizeof (EggHistogramViewPrivate)); +} + +static void +egg_histogram_view_init (EggHistogramView *renderer) +{ + renderer->priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (renderer); +} diff --git a/tools/gui/egg-histogram-view.h b/tools/gui/egg-histogram-view.h new file mode 100644 index 0000000..23581dc --- /dev/null +++ b/tools/gui/egg-histogram-view.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2011, 2012 Matthias Vogelgesang + (Karlsruhe Institute of Technology) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 51 + Franklin St, Fifth Floor, Boston, MA 02110, USA */ + +#ifndef EGG_HISTOGRAM_VIEW_H +#define EGG_HISTOGRAM_VIEW_H + +#include + +G_BEGIN_DECLS + +#define EGG_TYPE_HISTOGRAM_VIEW (egg_histogram_view_get_type()) +#define EGG_HISTOGRAM_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), EGG_TYPE_HISTOGRAM_VIEW, EggHistogramView)) +#define EGG_IS_HISTOGRAM_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), EGG_TYPE_HISTOGRAM_VIEW)) +#define EGG_HISTOGRAM_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EGG_TYPE_HISTOGRAM_VIEW, EggHistogramViewClass)) +#define EGG_IS_HISTOGRAM_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EGG_TYPE_HISTOGRAM_VIEW)) +#define EGG_HISTOGRAM_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EGG_TYPE_HISTOGRAM_VIEW, EggHistogramViewClass)) + +typedef struct _EggHistogramView EggHistogramView; +typedef struct _EggHistogramViewClass EggHistogramViewClass; +typedef struct _EggHistogramViewPrivate EggHistogramViewPrivate; + +struct _EggHistogramView +{ + GtkDrawingArea parent_instance; + + /*< private >*/ + EggHistogramViewPrivate *priv; +}; + +struct _EggHistogramViewClass +{ + GtkDrawingAreaClass parent_class; +}; + +GType egg_histogram_view_get_type (void); +GtkWidget * egg_histogram_view_new (void); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 46a6d028c5591b0775ef5862ff5c9e95fd68e7fd Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 10 Oct 2012 10:20:08 +0200 Subject: (De-) activate tool buttons according to state --- tools/gui/control.c | 99 +++++++++++++++++++++++++++---------------------- tools/gui/control.glade | 20 +++------- 2 files changed, 59 insertions(+), 60 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 89e932a..f7d3618 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -31,21 +31,22 @@ typedef struct { - gboolean running; - gboolean store; - - guchar *buffer, *pixels; - GdkPixbuf *pixbuf; - GtkWidget *image; - UcaCamera *camera; - - GtkStatusbar *statusbar; - guint statusbar_context_id; - - int timestamp; - int width; - int height; - int pixel_size; + UcaCamera *camera; + GdkPixbuf *pixbuf; + GtkWidget *image; + GtkWidget *start_button; + GtkWidget *stop_button; + GtkWidget *record_button; + + guchar *buffer; + guchar *pixels; + gboolean running; + gboolean store; + + int timestamp; + int width; + int height; + int pixel_size; } ThreadData; enum { @@ -145,16 +146,22 @@ on_destroy (GtkWidget *widget, gpointer data) } static void -on_toolbutton_run_clicked (GtkWidget *widget, gpointer args) +set_tool_button_state (ThreadData *data) { - ThreadData *data = (ThreadData *) args; - - if (data->running) - return; + gtk_widget_set_sensitive (data->start_button, !data->running); + gtk_widget_set_sensitive (data->stop_button, data->running); + gtk_widget_set_sensitive (data->record_button, !data->running); +} +static void +on_start_button_clicked (GtkWidget *widget, gpointer args) +{ + ThreadData *data = (ThreadData *) args; GError *error = NULL; + data->running = TRUE; + set_tool_button_state (data); uca_camera_start_recording (data->camera, &error); if (error != NULL) { @@ -169,12 +176,15 @@ on_toolbutton_run_clicked (GtkWidget *widget, gpointer args) } static void -on_toolbutton_stop_clicked (GtkWidget *widget, gpointer args) +on_stop_button_clicked (GtkWidget *widget, gpointer args) { ThreadData *data = (ThreadData *) args; + GError *error = NULL; + data->running = FALSE; data->store = FALSE; - GError *error = NULL; + + set_tool_button_state (data); uca_camera_stop_recording (data->camera, &error); if (error != NULL) @@ -182,22 +192,20 @@ on_toolbutton_stop_clicked (GtkWidget *widget, gpointer args) } static void -on_toolbutton_record_clicked (GtkWidget *widget, gpointer args) +on_record_button_clicked (GtkWidget *widget, gpointer args) { ThreadData *data = (ThreadData *) args; - data->timestamp = (int) time (0); - data->store = TRUE; GError *error = NULL; - gtk_statusbar_push (data->statusbar, data->statusbar_context_id, "Recording..."); + data->timestamp = (int) time (0); + data->store = TRUE; + data->running = TRUE; - if (data->running != TRUE) { - data->running = TRUE; - uca_camera_start_recording (data->camera, &error); + set_tool_button_state (data); + uca_camera_start_recording (data->camera, &error); - if (!g_thread_create (grab_thread, data, FALSE, &error)) - g_printerr ("Failed to create thread: %s\n", error->message); - } + if (!g_thread_create (grab_thread, data, FALSE, &error)) + g_printerr ("Failed to create thread: %s\n", error->message); } static void @@ -215,10 +223,10 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) guint bits_per_sample; g_object_get (camera, - "roi-width", &td.width, - "roi-height", &td.height, - "sensor-bitdepth", &bits_per_sample, - NULL); + "roi-width", &td.width, + "roi-height", &td.height, + "sensor-bitdepth", &bits_per_sample, + NULL); GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); GtkWidget *image = GTK_WIDGET (gtk_builder_get_object (builder, "image")); @@ -237,18 +245,19 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.buffer = (guchar *) g_malloc (td.pixel_size * td.width * td.height); td.pixels = gdk_pixbuf_get_pixels (pixbuf); td.running = FALSE; - td.statusbar = GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")); - td.statusbar_context_id = gtk_statusbar_get_context_id (td.statusbar, "Recording Information"); td.store = FALSE; td.camera = camera; g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); - g_signal_connect (gtk_builder_get_object (builder, "toolbutton_run"), - "clicked", G_CALLBACK (on_toolbutton_run_clicked), &td); - g_signal_connect (gtk_builder_get_object (builder, "toolbutton_stop"), - "clicked", G_CALLBACK (on_toolbutton_stop_clicked), &td); - g_signal_connect (gtk_builder_get_object (builder, "toolbutton_record"), - "clicked", G_CALLBACK (on_toolbutton_record_clicked), &td); + + 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")); + set_tool_button_state (&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); + g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); gtk_widget_show (image); gtk_widget_show (window); @@ -295,7 +304,7 @@ create_choice_window (GtkBuilder *builder) GtkWidget *choice_window = GTK_WIDGET (gtk_builder_get_object (builder, "choice-window")); GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview-cameras")); GtkListStore *list_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "camera-types")); - GtkButton *proceed_button = GTK_BUTTON (gtk_builder_get_object (builder, "button-proceed")); + GtkButton *proceed_button = GTK_BUTTON (gtk_builder_get_object (builder, "proceed-button")); GtkTreeIter iter; for (GList *it = g_list_first (camera_types); it != NULL; it = g_list_next (it)) { diff --git a/tools/gui/control.glade b/tools/gui/control.glade index ad5a91f..ee888e8 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -117,7 +117,7 @@ True - + True Run True @@ -129,7 +129,7 @@ - + True Record True @@ -141,7 +141,7 @@ - + True Stop True @@ -208,16 +208,6 @@ 2 - - - True - 2 - - - False - 3 - - @@ -271,7 +261,7 @@ 6 end - + gtk-quit True True @@ -286,7 +276,7 @@ - + gtk-ok True True -- cgit v1.2.3 From 95a22bf2f02ad11c2602df5ac5ffd04fee93588c Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 10 Oct 2012 17:44:34 +0200 Subject: Implement experimental histogram view --- tools/gui/control.c | 47 ++++--- tools/gui/control.glade | 75 ++++++++-- tools/gui/egg-histogram-view.c | 301 +++++++++++++++++++++++++++++++++++++++-- tools/gui/egg-histogram-view.h | 5 + 4 files changed, 392 insertions(+), 36 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index f7d3618..b36d188 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -28,6 +28,7 @@ #include "uca-camera.h" #include "uca-plugin-manager.h" #include "egg-property-tree-view.h" +#include "egg-histogram-view.h" typedef struct { @@ -37,6 +38,8 @@ typedef struct { GtkWidget *start_button; GtkWidget *stop_button; GtkWidget *record_button; + GtkWidget *histogram_view; + GtkToggleButton *histogram_button; guchar *buffer; guchar *pixels; @@ -49,15 +52,9 @@ typedef struct { int pixel_size; } ThreadData; -enum { - COLUMN_NAME = 0, - COLUMN_VALUE, - COLUMN_EDITABLE, - NUM_COLUMNS -}; - static UcaPluginManager *plugin_manager; + static void convert_8bit_to_rgb (guchar *output, guchar *input, int width, int height) { @@ -106,7 +103,7 @@ grab_thread (void *args) uca_camera_grab (data->camera, (gpointer) &data->buffer, NULL); if (data->store) { - snprintf (filename, FILENAME_MAX, "frame-%i-%08i.raw", data->timestamp, counter++); + snprintf (filename, FILENAME_MAX, "frame-%i-%08i.raw", data->timestamp, counter); FILE *fp = fopen (filename, "wb"); fwrite (data->buffer, data->width*data->height, data->pixel_size, fp); fclose (fp); @@ -121,11 +118,18 @@ grab_thread (void *args) } gdk_threads_enter (); + gdk_flush (); gtk_image_clear (GTK_IMAGE (data->image)); gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); gtk_widget_queue_draw_area (data->image, 0, 0, data->width, data->height); + + if (gtk_toggle_button_get_active (data->histogram_button)) + gtk_widget_queue_draw (data->histogram_view); + gdk_threads_leave (); + + counter++; } return NULL; } @@ -211,6 +215,12 @@ on_record_button_clicked (GtkWidget *widget, gpointer args) static void create_main_window (GtkBuilder *builder, const gchar* camera_name) { + GtkWidget *window; + GtkWidget *image; + GtkWidget *property_tree_view; + GdkPixbuf *pixbuf; + GtkBox *histogram_box; + GtkContainer *scrolled_property_window; static ThreadData td; GError *error = NULL; @@ -228,15 +238,12 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) "sensor-bitdepth", &bits_per_sample, NULL); - GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); - GtkWidget *image = GTK_WIDGET (gtk_builder_get_object (builder, "image")); - GtkWidget *property_tree_view = egg_property_tree_view_new (G_OBJECT (camera)); - GtkContainer *scrolled_property_window = GTK_CONTAINER (gtk_builder_get_object (builder, "scrolledwindow2")); - + property_tree_view = egg_property_tree_view_new (G_OBJECT (camera)); + scrolled_property_window = GTK_CONTAINER (gtk_builder_get_object (builder, "scrolledwindow2")); gtk_container_add (scrolled_property_window, property_tree_view); - gtk_widget_show_all (GTK_WIDGET (scrolled_property_window)); - GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, td.width, td.height); + image = GTK_WIDGET (gtk_builder_get_object (builder, "image")); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, td.width, td.height); gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); td.pixel_size = bits_per_sample > 8 ? 2 : 1; @@ -247,7 +254,14 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.running = FALSE; td.store = FALSE; td.camera = camera; + td.histogram_view = egg_histogram_view_new (); + td.histogram_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "histogram-checkbutton")); + + histogram_box = GTK_BOX (gtk_builder_get_object (builder, "histogram-box")); + gtk_box_pack_start (histogram_box, td.histogram_view, TRUE, TRUE, 6); + egg_histogram_view_set_data (EGG_HISTOGRAM_VIEW (td.histogram_view), td.buffer, td.width * td.height, bits_per_sample, 256); + window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); td.start_button = GTK_WIDGET (gtk_builder_get_object (builder, "start-button")); @@ -259,8 +273,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) g_signal_connect (td.stop_button, "clicked", G_CALLBACK (on_stop_button_clicked), &td); g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); - gtk_widget_show (image); - gtk_widget_show (window); + gtk_widget_show_all (window); } static void diff --git a/tools/gui/control.glade b/tools/gui/control.glade index ee888e8..6d6d791 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -164,28 +164,83 @@ True 6 - - 300 + True True - automatic - automatic - + + 640 + 480 True - queue + True + automatic + automatic - + True - gtk-missing-image + queue + + + 640 + 480 + True + gtk-missing-image + + + + True + True + + + + + True + True + + + True + + + + + + Enable Live Update + True + True + False + 6 + True + True + + + end + 1 + + + + + + + True + Histogram + + + False + + + + + True + True + - True - False + False + True diff --git a/tools/gui/egg-histogram-view.c b/tools/gui/egg-histogram-view.c index 809a2d9..d3cb18b 100644 --- a/tools/gui/egg-histogram-view.c +++ b/tools/gui/egg-histogram-view.c @@ -15,17 +15,33 @@ with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA */ -#include +#include #include "egg-histogram-view.h" -G_DEFINE_TYPE (EggHistogramView, egg_histogram_view, GTK_TYPE_CELL_RENDERER) +G_DEFINE_TYPE (EggHistogramView, egg_histogram_view, GTK_TYPE_DRAWING_AREA) #define EGG_HISTOGRAM_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), EGG_TYPE_HISTOGRAM_VIEW, EggHistogramViewPrivate)) +#define MIN_WIDTH 128 +#define MIN_HEIGHT 128 +#define BORDER 2 struct _EggHistogramViewPrivate { - guint foo; + GdkCursorType cursor_type; + gboolean grabbing; + + /* This could be moved into a real histogram class */ + guint n_bins; + gint *bins; + gint min_value; + gint max_value; + gint min_border; + gint max_border; + + gpointer data; + gint n_elements; + gint n_bits; }; enum @@ -46,9 +62,178 @@ egg_histogram_view_new (void) return GTK_WIDGET (view); } +void +egg_histogram_view_set_data (EggHistogramView *view, + gpointer data, + guint n_elements, + guint n_bits, + guint n_bins) +{ + EggHistogramViewPrivate *priv; + + priv = view->priv; + + if (priv->bins != NULL) + g_free (priv->bins); + + priv->data = data; + priv->bins = g_malloc0 (n_bins * sizeof (guint)); + priv->n_bins = n_bins; + priv->n_bits = n_bits; + priv->n_elements = n_elements; + + priv->min_value = 0; + priv->max_value = (gint) pow(2, n_bits) - 1; + + priv->min_border = 20; + priv->max_border = priv->max_value - 20; +} + +static void +compute_histogram (EggHistogramViewPrivate *priv) +{ + for (guint i = 0; i < priv->n_bins; i++) + priv->bins[i] = 0; + + if (priv->n_bits == 8) { + guint8 *data = (guint8 *) priv->data; + + for (guint i = 0; i < priv->n_elements; i++) { + guint8 v = data[i]; + guint index = (guint) round (((gdouble) v) / priv->max_value * (priv->n_bins - 1)); + priv->bins[index]++; + } + } + else if (priv->n_bits == 16) { + guint16 *data = (guint16 *) priv->data; + + for (guint i = 0; i < priv->n_elements; i++) { + guint16 v = data[i]; + guint index = (guint) floor (((gdouble ) v) / priv->max_value * (priv->n_bins - 1)); + priv->bins[index]++; + } + } + else + g_warning ("%i number of bits unsupported", priv->n_bits); +} + +static void +set_cursor_type (EggHistogramView *view, GdkCursorType cursor_type) +{ + if (cursor_type != view->priv->cursor_type) { + GdkCursor *cursor = gdk_cursor_new (cursor_type); + + gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET(view)), cursor); + gdk_cursor_unref (cursor); + view->priv->cursor_type = cursor_type; + } +} + +static void +egg_histogram_view_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + requisition->width = MIN_WIDTH; + requisition->height = MIN_HEIGHT; +} + +static gboolean +egg_histogram_view_expose (GtkWidget *widget, + GdkEventExpose *event) +{ + EggHistogramViewPrivate *priv; + GtkAllocation allocation; + GtkStyle *style; + cairo_t *cr; + gint width, height; + gint max_value = 0; + + priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (widget); + cr = gdk_cairo_create (gtk_widget_get_window (widget)); + + gdk_cairo_region (cr, event->region); + cairo_clip (cr); + + style = gtk_widget_get_style (widget); + gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]); + cairo_paint (cr); + + /* Draw the background */ + gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]); + cairo_paint (cr); + + gtk_widget_get_allocation (widget, &allocation); + width = allocation.width - 2 * BORDER; + height = allocation.height - 2 * BORDER; + + gdk_cairo_set_source_color (cr, &style->dark[GTK_STATE_NORMAL]); + cairo_set_line_width (cr, 1.0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_translate (cr, 0.5, 0.5); + cairo_rectangle (cr, BORDER, BORDER, width - 1, height - 1); + cairo_stroke (cr); + + if (priv->bins == NULL) + goto cleanup; + + compute_histogram (priv); + + /* Draw border areas */ + gdk_cairo_set_source_color (cr, &style->dark[GTK_STATE_NORMAL]); + + if (priv->min_border > 0) { + cairo_rectangle (cr, BORDER, BORDER, priv->min_border + 0.5, height - 1); + cairo_fill (cr); + } + + /* Draw spikes */ + for (guint i = 0; i < priv->n_bins; i++) { + if (priv->bins[i] > max_value) + max_value = priv->bins[i]; + } + + if (max_value == 0) + goto cleanup; + + gdk_cairo_set_source_color (cr, &style->black); + + if (width > priv->n_bins) { + gdouble skip = ((gdouble) width) / priv->n_bins; + gdouble x = 1; + + for (guint i = 0; i < priv->n_bins; i++, x += skip) { + if (priv->bins[i] == 0) + continue; + + gint y = (gint) ((height - 2) * priv->bins[i]) / max_value; + cairo_move_to (cr, round (x + BORDER), height + BORDER - 1); + cairo_line_to (cr, round (x + BORDER), height + BORDER - 1 - y); + cairo_stroke (cr); + } + } + +cleanup: + cairo_destroy (cr); + return FALSE; +} + +static void +egg_histogram_view_finalize (GObject *object) +{ + EggHistogramViewPrivate *priv; + + priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (object); + + if (priv->bins) + g_free (priv->bins); + + G_OBJECT_CLASS (egg_histogram_view_parent_class)->finalize (object); +} + static void egg_histogram_view_dispose (GObject *object) { + G_OBJECT_CLASS (egg_histogram_view_parent_class)->dispose (object); } static void @@ -81,20 +266,118 @@ egg_histogram_view_get_property (GObject *object, } } +static gint +get_mouse_distance (EggHistogramViewPrivate *priv, + gint x) +{ + return (priv->min_border + BORDER) - x; +} + +static gboolean +egg_histogram_view_motion_notify (GtkWidget *widget, + GdkEventMotion *event) +{ + EggHistogramView *view; + EggHistogramViewPrivate *priv; + + view = EGG_HISTOGRAM_VIEW (widget); + priv = view->priv; + + if (priv->grabbing) { + priv->min_border = event->x + BORDER; + gtk_widget_queue_draw (widget); + } + else { + gint distance = get_mouse_distance (priv, event->x); + + if (ABS(distance) < 6) + set_cursor_type (view, GDK_FLEUR); + else + set_cursor_type (view, GDK_ARROW); + } + + return TRUE; +} + +static gboolean +egg_histogram_view_button_release (GtkWidget *widget, + GdkEventButton *event) +{ + EggHistogramView *view; + EggHistogramViewPrivate *priv; + GtkAllocation allocation; + gint width; + + gtk_widget_get_allocation (widget, &allocation); + width = allocation.width - 2 * BORDER; + + view = EGG_HISTOGRAM_VIEW (widget); + priv = view->priv; + + set_cursor_type (view, GDK_ARROW); + priv->grabbing = FALSE; + + return TRUE; +} + +static gboolean +egg_histogram_view_button_press (GtkWidget *widget, + GdkEventButton *event) +{ + EggHistogramView *view; + EggHistogramViewPrivate *priv; + gint distance; + + view = EGG_HISTOGRAM_VIEW (widget); + priv = view->priv; + distance = get_mouse_distance (priv, event->x); + + if (ABS (distance) < 6) { + priv->grabbing = TRUE; + set_cursor_type (view, GDK_FLEUR); + } + + return TRUE; +} + static void egg_histogram_view_class_init (EggHistogramViewClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - gobject_class->set_property = egg_histogram_view_set_property; - gobject_class->get_property = egg_histogram_view_get_property; - gobject_class->dispose = egg_histogram_view_dispose; + object_class->set_property = egg_histogram_view_set_property; + object_class->get_property = egg_histogram_view_get_property; + object_class->dispose = egg_histogram_view_dispose; + object_class->finalize = egg_histogram_view_finalize; + + widget_class->size_request = egg_histogram_view_size_request; + widget_class->expose_event = egg_histogram_view_expose; + widget_class->button_press_event = egg_histogram_view_button_press; + widget_class->button_release_event = egg_histogram_view_button_release; + widget_class->motion_notify_event = egg_histogram_view_motion_notify; g_type_class_add_private (klass, sizeof (EggHistogramViewPrivate)); } static void -egg_histogram_view_init (EggHistogramView *renderer) +egg_histogram_view_init (EggHistogramView *view) { - renderer->priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (renderer); + EggHistogramViewPrivate *priv; + + view->priv = priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (view); + + priv->bins = NULL; + priv->data = NULL; + priv->n_bins = 0; + priv->n_elements = 0; + + priv->cursor_type = GDK_ARROW; + priv->grabbing = FALSE; + + gtk_widget_add_events (GTK_WIDGET (view), + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_BUTTON1_MOTION_MASK | + GDK_POINTER_MOTION_MASK); } diff --git a/tools/gui/egg-histogram-view.h b/tools/gui/egg-histogram-view.h index 23581dc..a1df0ba 100644 --- a/tools/gui/egg-histogram-view.h +++ b/tools/gui/egg-histogram-view.h @@ -48,6 +48,11 @@ struct _EggHistogramViewClass GType egg_histogram_view_get_type (void); GtkWidget * egg_histogram_view_new (void); +void egg_histogram_view_set_data (EggHistogramView *view, + gpointer data, + guint n_elements, + guint n_bits, + guint n_bins); G_END_DECLS -- cgit v1.2.3 From 195ccad179d96766165b1dc846dbe066fffc43ac Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 10 Oct 2012 17:47:00 +0200 Subject: Disable unused variables --- tools/gui/egg-histogram-view.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/gui/egg-histogram-view.c b/tools/gui/egg-histogram-view.c index d3cb18b..7abc2be 100644 --- a/tools/gui/egg-histogram-view.c +++ b/tools/gui/egg-histogram-view.c @@ -305,11 +305,11 @@ egg_histogram_view_button_release (GtkWidget *widget, { EggHistogramView *view; EggHistogramViewPrivate *priv; - GtkAllocation allocation; - gint width; + /* GtkAllocation allocation; */ + /* gint width; */ - gtk_widget_get_allocation (widget, &allocation); - width = allocation.width - 2 * BORDER; + /* gtk_widget_get_allocation (widget, &allocation); */ + /* width = allocation.width - 2 * BORDER; */ view = EGG_HISTOGRAM_VIEW (widget); priv = view->priv; -- cgit v1.2.3 From 6200956f93eabb0fe040902fda3716b676b2921a Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 11 Oct 2012 08:45:56 +0200 Subject: Link explicitly against libm --- tools/gui/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/gui/CMakeLists.txt b/tools/gui/CMakeLists.txt index b30f3ea..ff5e9f6 100644 --- a/tools/gui/CMakeLists.txt +++ b/tools/gui/CMakeLists.txt @@ -30,7 +30,9 @@ if (GTK2_FOUND) egg-histogram-view.c) target_link_libraries(control uca - ${GTK2_LIBRARIES} ${GTHREAD2_LIBRARIES}) + ${GTK2_LIBRARIES} + ${GTHREAD2_LIBRARIES} + m) install(TARGETS control RUNTIME DESTINATION bin) -- cgit v1.2.3 From 0c0c93912094bb668a31703b2640f72a0f1b5df8 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 11 Oct 2012 09:07:50 +0200 Subject: Don't set the maximum size of the preview image --- tools/gui/control.glade | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.glade b/tools/gui/control.glade index 6d6d791..7ef712d 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -181,8 +181,6 @@ queue - 640 - 480 True gtk-missing-image -- cgit v1.2.3 From 13b2833ea9c16750efb923a981ea04d37aaa6789 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 11 Oct 2012 16:38:26 +0200 Subject: Implement adjustable histogram --- tools/gui/control.c | 70 ++++++------ tools/gui/control.glade | 112 +++++++++++++++++--- tools/gui/egg-histogram-view.c | 234 +++++++++++++++++++++++++++++++---------- tools/gui/egg-histogram-view.h | 4 + 4 files changed, 315 insertions(+), 105 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index b36d188..214e4da 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -19,10 +19,7 @@ #include #include #include -#include -#include -#include -#include +#include #include "config.h" #include "uca-camera.h" @@ -56,39 +53,28 @@ static UcaPluginManager *plugin_manager; static void -convert_8bit_to_rgb (guchar *output, guchar *input, int width, int height) +convert_8bit_to_rgb (guchar *output, guchar *input, gint width, gint height, gdouble min, gdouble max) { + gdouble factor = 255.0 / (max - min); + for (int i = 0, j = 0; i < width*height; i++) { - output[j++] = input[i]; - output[j++] = input[i]; - output[j++] = input[i]; + guchar val = (guchar) ((input[i] - min) * factor); + output[j++] = val; + output[j++] = val; + output[j++] = val; } } static void -convert_16bit_to_rgb (guchar *output, guchar *input, int width, int height) +convert_16bit_to_rgb (guchar *output, guchar *input, gint width, gint height, gdouble min, gdouble max) { - guint16 *in = (guint16 *) input; - guint16 min = G_MAXUINT16, max = 0; - gfloat spread = 0.0f; - - for (int i = 0; i < width * height; i++) { - guint16 v = in[i]; - if (v < min) - min = v; - if (v > max) - max = v; - } - - spread = (gfloat) max - min; + gdouble factor = 255.0 / (max - min); - if (spread > 0.0f) { - for (int i = 0, j = 0; i < width*height; i++) { - guchar val = (guint8) (((in[i] - min) / spread) * 255.0f); - output[j++] = val; - output[j++] = val; - output[j++] = val; - } + for (int i = 0, j = 0; i < width*height; i++) { + guchar val = (guint8) ((input[i] - min) * factor); + output[j++] = val; + output[j++] = val; + output[j++] = val; } } @@ -100,6 +86,9 @@ grab_thread (void *args) gint counter = 0; while (data->running) { + gdouble min_value; + gdouble max_value; + uca_camera_grab (data->camera, (gpointer) &data->buffer, NULL); if (data->store) { @@ -111,11 +100,12 @@ grab_thread (void *args) /* FIXME: We should actually check if this is really a new frame and * just do nothing if it is an already displayed one. */ + egg_histogram_get_visible_range (EGG_HISTOGRAM_VIEW (data->histogram_view), &min_value, &max_value); + 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_8bit_to_rgb (data->pixels, data->buffer, data->width, data->height, min_value, max_value); + else if (data->pixel_size == 2) + convert_16bit_to_rgb (data->pixels, data->buffer, data->width, data->height, min_value, max_value); gdk_threads_enter (); @@ -221,6 +211,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) GdkPixbuf *pixbuf; GtkBox *histogram_box; GtkContainer *scrolled_property_window; + GtkAdjustment *max_bin_adjustment; static ThreadData td; GError *error = NULL; @@ -259,7 +250,8 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) histogram_box = GTK_BOX (gtk_builder_get_object (builder, "histogram-box")); gtk_box_pack_start (histogram_box, td.histogram_view, TRUE, TRUE, 6); - egg_histogram_view_set_data (EGG_HISTOGRAM_VIEW (td.histogram_view), td.buffer, td.width * td.height, bits_per_sample, 256); + egg_histogram_view_set_data (EGG_HISTOGRAM_VIEW (td.histogram_view), + td.buffer, td.width * td.height, bits_per_sample, 256); window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); @@ -269,6 +261,16 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.record_button = GTK_WIDGET (gtk_builder_get_object (builder, "record-button")); set_tool_button_state (&td); + g_object_bind_property (gtk_builder_get_object (builder, "min_bin_value_adjustment"), "value", + td.histogram_view, "minimum-bin-value", + G_BINDING_DEFAULT); + + max_bin_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "max_bin_value_adjustment")); + gtk_adjustment_set_value (max_bin_adjustment, pow (2, bits_per_sample) - 1); + g_object_bind_property (max_bin_adjustment, "value", + td.histogram_view, "maximum-bin-value", + G_BINDING_DEFAULT); + 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); g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); diff --git a/tools/gui/control.glade b/tools/gui/control.glade index 7ef712d..ebe2cc8 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -204,17 +204,97 @@ - - Enable Live Update + True - True - False 6 - True - True + 3 + 2 + 6 + 6 + + + True + 1 + Minimum Value: + + + GTK_FILL + + 6 + 6 + + + + + 100 + True + True + + min_bin_value_adjustment + + + 1 + 2 + GTK_EXPAND + + + + + + True + 1 + Maximum Value: + + + 1 + 2 + GTK_FILL + + 6 + 6 + + + + + 100 + True + True + + max_bin_value_adjustment + + + 1 + 2 + 1 + 2 + GTK_EXPAND + + + + + + Live Update + True + True + False + 6 + True + True + + + 2 + 3 + + + + + + + - end + False + False 1 @@ -264,13 +344,6 @@ - - 65535 - 1 - 65535 - 1 - 10 - 6 @@ -352,4 +425,15 @@ + + 65535 + 1 + 10 + + + 256 + 65535 + 1 + 10 + diff --git a/tools/gui/egg-histogram-view.c b/tools/gui/egg-histogram-view.c index 7abc2be..91e61e8 100644 --- a/tools/gui/egg-histogram-view.c +++ b/tools/gui/egg-histogram-view.c @@ -34,11 +34,14 @@ struct _EggHistogramViewPrivate /* This could be moved into a real histogram class */ guint n_bins; gint *bins; - gint min_value; - gint max_value; - gint min_border; + gint *grabbed; + gint min_border; /* threshold set in screen units */ gint max_border; + gdouble min_value; /* lowest value of the first bin */ + gdouble max_value; /* highest value of the last bin */ + gdouble range; + gpointer data; gint n_elements; gint n_bits; @@ -47,6 +50,8 @@ struct _EggHistogramViewPrivate enum { PROP_0, + PROP_MINIMUM_BIN_VALUE, + PROP_MAXIMUM_BIN_VALUE, N_PROPERTIES }; @@ -71,6 +76,7 @@ egg_histogram_view_set_data (EggHistogramView *view, { EggHistogramViewPrivate *priv; + g_return_if_fail (EGG_IS_HISTOGRAM_VIEW (view)); priv = view->priv; if (priv->bins != NULL) @@ -82,16 +88,46 @@ egg_histogram_view_set_data (EggHistogramView *view, priv->n_bits = n_bits; priv->n_elements = n_elements; - priv->min_value = 0; + priv->min_value = 0.0; priv->max_value = (gint) pow(2, n_bits) - 1; - priv->min_border = 20; - priv->max_border = priv->max_value - 20; + priv->min_border = 0; + priv->max_border = 256; + priv->range = priv->max_value - priv->min_value; +} + +void +egg_histogram_get_visible_range (EggHistogramView *view, gdouble *min, gdouble *max) +{ + EggHistogramViewPrivate *priv; + GtkAllocation allocation; + gdouble width; + + g_return_if_fail (EGG_IS_HISTOGRAM_VIEW (view)); + + gtk_widget_get_allocation (GTK_WIDGET (view), &allocation); + width = (gdouble) allocation.width - 2 * BORDER; + priv = view->priv; + + *min = (priv->min_border - 2) / width * priv->range; + *max = (priv->max_border - 2) / width * priv->range; +} + +static void +set_max_border (EggHistogramView *view) +{ + GtkAllocation allocation; + + g_return_if_fail (EGG_IS_HISTOGRAM_VIEW (view)); + gtk_widget_get_allocation (GTK_WIDGET (view), &allocation); + view->priv->max_border = allocation.width - 2 * BORDER; } static void compute_histogram (EggHistogramViewPrivate *priv) { + guint n_bins = priv->n_bins - 1; + for (guint i = 0; i < priv->n_bins; i++) priv->bins[i] = 0; @@ -100,8 +136,11 @@ compute_histogram (EggHistogramViewPrivate *priv) for (guint i = 0; i < priv->n_elements; i++) { guint8 v = data[i]; - guint index = (guint) round (((gdouble) v) / priv->max_value * (priv->n_bins - 1)); - priv->bins[index]++; + + if (v >= priv->min_value && v <= priv->max_value) { + guint index = (guint) round (((gdouble) v) / priv->max_value * n_bins); + priv->bins[index]++; + } } } else if (priv->n_bits == 16) { @@ -109,8 +148,11 @@ compute_histogram (EggHistogramViewPrivate *priv) for (guint i = 0; i < priv->n_elements; i++) { guint16 v = data[i]; - guint index = (guint) floor (((gdouble ) v) / priv->max_value * (priv->n_bins - 1)); - priv->bins[index]++; + + if (v >= priv->min_value && v <= priv->max_value) { + guint index = (guint) floor (((gdouble ) v) / priv->max_value * n_bins); + priv->bins[index]++; + } } } else @@ -137,6 +179,36 @@ egg_histogram_view_size_request (GtkWidget *widget, requisition->height = MIN_HEIGHT; } +static void +draw_bins (EggHistogramViewPrivate *priv, + cairo_t *cr, + gint width, + gint height) +{ + gdouble skip = ((gdouble) width) / priv->n_bins; + gdouble x = BORDER; + gdouble ys = height + BORDER - 1; + gint max_value = 0; + + for (guint i = 0; i < priv->n_bins; i++) { + if (priv->bins[i] > max_value) + max_value = priv->bins[i]; + } + + if (max_value == 0) + return; + + for (guint i = 0; i < priv->n_bins && x < (width - BORDER); i++, x += skip) { + if (priv->bins[i] == 0) + continue; + + gint y = (gint) ((height - 2) * priv->bins[i]) / max_value; + cairo_move_to (cr, round (x), ys); + cairo_line_to (cr, round (x), ys - y); + cairo_stroke (cr); + } +} + static gboolean egg_histogram_view_expose (GtkWidget *widget, GdkEventExpose *event) @@ -146,7 +218,6 @@ egg_histogram_view_expose (GtkWidget *widget, GtkStyle *style; cairo_t *cr; gint width, height; - gint max_value = 0; priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (widget); cr = gdk_cairo_create (gtk_widget_get_window (widget)); @@ -181,36 +252,15 @@ egg_histogram_view_expose (GtkWidget *widget, /* Draw border areas */ gdk_cairo_set_source_color (cr, &style->dark[GTK_STATE_NORMAL]); - if (priv->min_border > 0) { - cairo_rectangle (cr, BORDER, BORDER, priv->min_border + 0.5, height - 1); - cairo_fill (cr); - } - - /* Draw spikes */ - for (guint i = 0; i < priv->n_bins; i++) { - if (priv->bins[i] > max_value) - max_value = priv->bins[i]; - } + cairo_rectangle (cr, BORDER, BORDER, priv->min_border + 0.5, height - 1); + cairo_fill (cr); - if (max_value == 0) - goto cleanup; + cairo_rectangle (cr, priv->max_border + 0.5, BORDER, width - priv->min_border - 0.5, height - 1); + cairo_fill (cr); + /* Draw spikes */ gdk_cairo_set_source_color (cr, &style->black); - - if (width > priv->n_bins) { - gdouble skip = ((gdouble) width) / priv->n_bins; - gdouble x = 1; - - for (guint i = 0; i < priv->n_bins; i++, x += skip) { - if (priv->bins[i] == 0) - continue; - - gint y = (gint) ((height - 2) * priv->bins[i]) / max_value; - cairo_move_to (cr, round (x + BORDER), height + BORDER - 1); - cairo_line_to (cr, round (x + BORDER), height + BORDER - 1 - y); - cairo_stroke (cr); - } - } + draw_bins (priv, cr, width, height); cleanup: cairo_destroy (cr); @@ -242,9 +292,42 @@ egg_histogram_view_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { + EggHistogramViewPrivate *priv; + g_return_if_fail (EGG_IS_HISTOGRAM_VIEW (object)); + priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (object); switch (property_id) { + case PROP_MINIMUM_BIN_VALUE: + { + gdouble v = g_value_get_double (value); + + if (v > priv->max_value) + g_warning ("Minimum value `%f' larger than maximum value `%f'", + v, priv->max_value); + else { + priv->min_value = v; + priv->range = priv->max_value - v; + priv->min_border = 0; + } + } + break; + + case PROP_MAXIMUM_BIN_VALUE: + { + gdouble v = g_value_get_double (value); + + if (v < priv->min_value) + g_warning ("Maximum value `%f' larger than minimum value `%f'", + v, priv->min_value); + else { + priv->max_value = v; + priv->range = v - priv->min_value; + set_max_border (EGG_HISTOGRAM_VIEW (object)); + } + } + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); return; @@ -257,20 +340,48 @@ egg_histogram_view_get_property (GObject *object, GValue *value, GParamSpec *pspec) { + EggHistogramViewPrivate *priv; + g_return_if_fail (EGG_IS_HISTOGRAM_VIEW (object)); + priv = EGG_HISTOGRAM_VIEW_GET_PRIVATE (object); switch (property_id) { + case PROP_MINIMUM_BIN_VALUE: + g_value_set_double (value, priv->min_value); + break; + + case PROP_MAXIMUM_BIN_VALUE: + g_value_set_double (value, priv->max_value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); return; } } -static gint -get_mouse_distance (EggHistogramViewPrivate *priv, +static gboolean +is_on_border (EggHistogramViewPrivate *priv, + gint x) +{ + gint d1 = (priv->min_border + BORDER) - x; + gint d2 = (priv->max_border + BORDER) - x; + return ABS (d1) < 6 || ABS (d2) < 6; +} + +static gint * +get_grabbed_border (EggHistogramViewPrivate *priv, gint x) { - return (priv->min_border + BORDER) - x; + gint d1 = (priv->min_border + BORDER) - x; + gint d2 = (priv->max_border + BORDER) - x; + + if (ABS (d1) < 6) + return &priv->min_border; + else if (ABS (d2) < 6) + return &priv->max_border; + + return NULL; } static gboolean @@ -284,13 +395,12 @@ egg_histogram_view_motion_notify (GtkWidget *widget, priv = view->priv; if (priv->grabbing) { - priv->min_border = event->x + BORDER; + *priv->grabbed = event->x; + gtk_widget_queue_draw (widget); } else { - gint distance = get_mouse_distance (priv, event->x); - - if (ABS(distance) < 6) + if (is_on_border (priv, event->x)) set_cursor_type (view, GDK_FLEUR); else set_cursor_type (view, GDK_ARROW); @@ -304,18 +414,10 @@ egg_histogram_view_button_release (GtkWidget *widget, GdkEventButton *event) { EggHistogramView *view; - EggHistogramViewPrivate *priv; - /* GtkAllocation allocation; */ - /* gint width; */ - - /* gtk_widget_get_allocation (widget, &allocation); */ - /* width = allocation.width - 2 * BORDER; */ view = EGG_HISTOGRAM_VIEW (widget); - priv = view->priv; - set_cursor_type (view, GDK_ARROW); - priv->grabbing = FALSE; + view->priv->grabbing = FALSE; return TRUE; } @@ -326,14 +428,13 @@ egg_histogram_view_button_press (GtkWidget *widget, { EggHistogramView *view; EggHistogramViewPrivate *priv; - gint distance; view = EGG_HISTOGRAM_VIEW (widget); priv = view->priv; - distance = get_mouse_distance (priv, event->x); - if (ABS (distance) < 6) { + if (is_on_border (priv, event->x)) { priv->grabbing = TRUE; + priv->grabbed = get_grabbed_border (priv, event->x); set_cursor_type (view, GDK_FLEUR); } @@ -357,6 +458,23 @@ egg_histogram_view_class_init (EggHistogramViewClass *klass) widget_class->button_release_event = egg_histogram_view_button_release; widget_class->motion_notify_event = egg_histogram_view_motion_notify; + egg_histogram_view_properties[PROP_MINIMUM_BIN_VALUE] = + g_param_spec_double ("minimum-bin-value", + "Smallest possible bin value", + "Smallest possible bin value, everything below is discarded.", + 0.0, G_MAXDOUBLE, 0.0, + G_PARAM_READWRITE); + + egg_histogram_view_properties[PROP_MAXIMUM_BIN_VALUE] = + g_param_spec_double ("maximum-bin-value", + "Largest possible bin value", + "Largest possible bin value, everything above is discarded.", + 0.0, G_MAXDOUBLE, 256.0, + G_PARAM_READWRITE); + + g_object_class_install_property (object_class, PROP_MINIMUM_BIN_VALUE, egg_histogram_view_properties[PROP_MINIMUM_BIN_VALUE]); + g_object_class_install_property (object_class, PROP_MAXIMUM_BIN_VALUE, egg_histogram_view_properties[PROP_MAXIMUM_BIN_VALUE]); + g_type_class_add_private (klass, sizeof (EggHistogramViewPrivate)); } @@ -371,6 +489,8 @@ egg_histogram_view_init (EggHistogramView *view) priv->data = NULL; priv->n_bins = 0; priv->n_elements = 0; + priv->min_value = priv->min_border = 0; + priv->max_value = priv->max_border = 256; priv->cursor_type = GDK_ARROW; priv->grabbing = FALSE; diff --git a/tools/gui/egg-histogram-view.h b/tools/gui/egg-histogram-view.h index a1df0ba..61a1c8c 100644 --- a/tools/gui/egg-histogram-view.h +++ b/tools/gui/egg-histogram-view.h @@ -53,6 +53,10 @@ void egg_histogram_view_set_data (EggHistogramView *view, guint n_elements, guint n_bits, guint n_bins); +void egg_histogram_get_visible_range + (EggHistogramView *view, + gdouble *min, + gdouble *max); G_END_DECLS -- cgit v1.2.3 From ef7ff789e9c15f4f4b8c65585de7e7fa4f9c9438 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 12 Oct 2012 14:47:07 +0200 Subject: Add ring buffer recording for assessment --- tools/gui/CMakeLists.txt | 1 + tools/gui/control.c | 190 ++++++++++++++++++++++++++++++----------------- tools/gui/control.glade | 33 +++++++- tools/gui/ring-buffer.c | 64 ++++++++++++++++ tools/gui/ring-buffer.h | 28 +++++++ 5 files changed, 243 insertions(+), 73 deletions(-) create mode 100644 tools/gui/ring-buffer.c create mode 100644 tools/gui/ring-buffer.h (limited to 'tools') diff --git a/tools/gui/CMakeLists.txt b/tools/gui/CMakeLists.txt index ff5e9f6..1000ac6 100644 --- a/tools/gui/CMakeLists.txt +++ b/tools/gui/CMakeLists.txt @@ -25,6 +25,7 @@ if (GTK2_FOUND) add_executable(control control.c + ring-buffer.c egg-property-cell-renderer.c egg-property-tree-view.c egg-histogram-view.c) diff --git a/tools/gui/control.c b/tools/gui/control.c index 214e4da..84799cb 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -22,11 +22,17 @@ #include #include "config.h" +#include "ring-buffer.h" #include "uca-camera.h" #include "uca-plugin-manager.h" #include "egg-property-tree-view.h" #include "egg-histogram-view.h" +typedef enum { + IDLE, + RUNNING, + RECORDING +} State; typedef struct { UcaCamera *camera; @@ -35,13 +41,14 @@ typedef struct { GtkWidget *start_button; GtkWidget *stop_button; GtkWidget *record_button; - GtkWidget *histogram_view; + + GtkWidget *histogram_view; GtkToggleButton *histogram_button; + GtkAdjustment *frame_slider; - guchar *buffer; + RingBuffer *buffer; guchar *pixels; - gboolean running; - gboolean store; + State state; int timestamp; int width; @@ -53,70 +60,66 @@ static UcaPluginManager *plugin_manager; static void -convert_8bit_to_rgb (guchar *output, guchar *input, gint width, gint height, gdouble min, gdouble max) +convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) { - gdouble factor = 255.0 / (max - min); - - for (int i = 0, j = 0; i < width*height; i++) { - guchar val = (guchar) ((input[i] - min) * factor); - output[j++] = val; - output[j++] = val; - output[j++] = val; + gdouble min; + gdouble max; + gdouble factor; + guint8 *output; + + egg_histogram_get_visible_range (EGG_HISTOGRAM_VIEW (data->histogram_view), &min, &max); + factor = 255.0 / (max - min); + output = data->pixels; + + if (data->pixel_size == 1) { + guint8 *input = (guint8 *) buffer; + + for (int i = 0, j = 0; i < data->width * data->height; i++) { + guchar val = (guchar) ((input[i] - min) * factor); + output[j++] = val; + output[j++] = val; + output[j++] = val; + } + } + else if (data->pixel_size == 2) { + guint16 *input = (guint16 *) buffer; + + for (int i = 0, j = 0; i < data->width * data->height; i++) { + guchar val = (guint8) ((input[i] - min) * factor); + output[j++] = val; + output[j++] = val; + output[j++] = val; + } } } static void -convert_16bit_to_rgb (guchar *output, guchar *input, gint width, gint height, gdouble min, gdouble max) +update_pixbuf (ThreadData *data) { - gdouble factor = 255.0 / (max - min); + gdk_flush (); + gtk_image_clear (GTK_IMAGE (data->image)); + gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); + gtk_widget_queue_draw_area (data->image, 0, 0, data->width, data->height); - for (int i = 0, j = 0; i < width*height; i++) { - guchar val = (guint8) ((input[i] - min) * factor); - output[j++] = val; - output[j++] = val; - output[j++] = val; - } + if (gtk_toggle_button_get_active (data->histogram_button)) + gtk_widget_queue_draw (data->histogram_view); } -static void * -grab_thread (void *args) +static gpointer +preview_frames (void *args) { ThreadData *data = (ThreadData *) args; - gchar filename[FILENAME_MAX] = {0,}; gint counter = 0; - while (data->running) { - gdouble min_value; - gdouble max_value; + while (data->state == RUNNING) { + gpointer buffer; - uca_camera_grab (data->camera, (gpointer) &data->buffer, NULL); - - if (data->store) { - snprintf (filename, FILENAME_MAX, "frame-%i-%08i.raw", data->timestamp, counter); - FILE *fp = fopen (filename, "wb"); - fwrite (data->buffer, data->width*data->height, data->pixel_size, fp); - fclose (fp); - } - - /* FIXME: We should actually check if this is really a new frame and - * just do nothing if it is an already displayed one. */ - egg_histogram_get_visible_range (EGG_HISTOGRAM_VIEW (data->histogram_view), &min_value, &max_value); - - if (data->pixel_size == 1) - convert_8bit_to_rgb (data->pixels, data->buffer, data->width, data->height, min_value, max_value); - else if (data->pixel_size == 2) - convert_16bit_to_rgb (data->pixels, data->buffer, data->width, data->height, min_value, max_value); + buffer = ring_buffer_get_current_pointer (data->buffer); + uca_camera_grab (data->camera, &buffer, NULL); + convert_grayscale_to_rgb (data, buffer); gdk_threads_enter (); - - gdk_flush (); - gtk_image_clear (GTK_IMAGE (data->image)); - gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); - gtk_widget_queue_draw_area (data->image, 0, 0, data->width, data->height); - - if (gtk_toggle_button_get_active (data->histogram_button)) - gtk_widget_queue_draw (data->histogram_view); - + update_pixbuf (data); gdk_threads_leave (); counter++; @@ -124,6 +127,33 @@ grab_thread (void *args) return NULL; } +static gpointer +record_frames (gpointer args) +{ + ThreadData *data; + gpointer buffer; + guint n_frames = 0; + + data = (ThreadData *) args; + ring_buffer_reset (data->buffer); + + while (data->state == RECORDING) { + buffer = ring_buffer_get_current_pointer (data->buffer); + uca_camera_grab (data->camera, &buffer, NULL); + ring_buffer_proceed (data->buffer); + n_frames++; + } + + n_frames = ring_buffer_get_num_blocks (data->buffer); + + gdk_threads_enter (); + gtk_adjustment_set_upper (data->frame_slider, n_frames - 1); + gtk_adjustment_set_value (data->frame_slider, n_frames - 1); + gdk_threads_leave (); + + return NULL; +} + gboolean on_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) { @@ -134,17 +164,39 @@ void on_destroy (GtkWidget *widget, gpointer data) { ThreadData *td = (ThreadData *) data; - td->running = FALSE; + + td->state = IDLE; g_object_unref (td->camera); + ring_buffer_free (td->buffer); + gtk_main_quit (); } static void set_tool_button_state (ThreadData *data) { - gtk_widget_set_sensitive (data->start_button, !data->running); - gtk_widget_set_sensitive (data->stop_button, data->running); - gtk_widget_set_sensitive (data->record_button, !data->running); + gtk_widget_set_sensitive (data->start_button, + data->state == IDLE); + gtk_widget_set_sensitive (data->stop_button, + data->state == RUNNING || data->state == RECORDING); + gtk_widget_set_sensitive (data->record_button, + data->state == IDLE); +} + +static void +on_frame_slider_changed (GtkAdjustment *adjustment, gpointer user_data) +{ + ThreadData *data = (ThreadData *) user_data; + + if (data->state == IDLE) { + gpointer buffer; + gint index; + + index = (gint) gtk_adjustment_get_value (adjustment); + buffer = ring_buffer_get_pointer (data->buffer, index); + convert_grayscale_to_rgb (data, buffer); + update_pixbuf (data); + } } static void @@ -153,7 +205,7 @@ on_start_button_clicked (GtkWidget *widget, gpointer args) ThreadData *data = (ThreadData *) args; GError *error = NULL; - data->running = TRUE; + data->state = RUNNING; set_tool_button_state (data); uca_camera_start_recording (data->camera, &error); @@ -163,7 +215,7 @@ on_start_button_clicked (GtkWidget *widget, gpointer args) return; } - if (!g_thread_create (grab_thread, data, FALSE, &error)) { + if (!g_thread_create (preview_frames, data, FALSE, &error)) { g_printerr ("Failed to create thread: %s\n", error->message); return; } @@ -175,8 +227,7 @@ on_stop_button_clicked (GtkWidget *widget, gpointer args) ThreadData *data = (ThreadData *) args; GError *error = NULL; - data->running = FALSE; - data->store = FALSE; + data->state = IDLE; set_tool_button_state (data); uca_camera_stop_recording (data->camera, &error); @@ -192,13 +243,12 @@ on_record_button_clicked (GtkWidget *widget, gpointer args) GError *error = NULL; data->timestamp = (int) time (0); - data->store = TRUE; - data->running = TRUE; + data->state = RECORDING; set_tool_button_state (data); uca_camera_start_recording (data->camera, &error); - if (!g_thread_create (grab_thread, data, FALSE, &error)) + if (!g_thread_create (record_frames, data, FALSE, &error)) g_printerr ("Failed to create thread: %s\n", error->message); } @@ -240,18 +290,19 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.pixel_size = bits_per_sample > 8 ? 2 : 1; td.image = image; td.pixbuf = pixbuf; - td.buffer = (guchar *) g_malloc (td.pixel_size * td.width * td.height); + td.buffer = ring_buffer_new (td.pixel_size * td.width * td.height, 256); td.pixels = gdk_pixbuf_get_pixels (pixbuf); - td.running = FALSE; - td.store = FALSE; + td.state = IDLE; td.camera = camera; td.histogram_view = egg_histogram_view_new (); td.histogram_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "histogram-checkbutton")); + td.frame_slider = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "frames-adjustment")); histogram_box = GTK_BOX (gtk_builder_get_object (builder, "histogram-box")); gtk_box_pack_start (histogram_box, td.histogram_view, TRUE, TRUE, 6); egg_histogram_view_set_data (EGG_HISTOGRAM_VIEW (td.histogram_view), - td.buffer, td.width * td.height, bits_per_sample, 256); + ring_buffer_get_current_pointer (td.buffer), + td.width * td.height, bits_per_sample, 256); window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); @@ -261,16 +312,17 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.record_button = GTK_WIDGET (gtk_builder_get_object (builder, "record-button")); set_tool_button_state (&td); - g_object_bind_property (gtk_builder_get_object (builder, "min_bin_value_adjustment"), "value", + g_object_bind_property (gtk_builder_get_object (builder, "min-bin-value-adjustment"), "value", td.histogram_view, "minimum-bin-value", G_BINDING_DEFAULT); - max_bin_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "max_bin_value_adjustment")); + max_bin_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "max-bin-value-adjustment")); gtk_adjustment_set_value (max_bin_adjustment, pow (2, bits_per_sample) - 1); g_object_bind_property (max_bin_adjustment, "value", td.histogram_view, "maximum-bin-value", G_BINDING_DEFAULT); + 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); g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); diff --git a/tools/gui/control.glade b/tools/gui/control.glade index ebe2cc8..c3008ec 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -230,7 +230,7 @@ True True - min_bin_value_adjustment + min-bin-value-adjustment 1 @@ -260,7 +260,7 @@ True True - max_bin_value_adjustment + max-bin-value-adjustment 1 @@ -309,6 +309,27 @@ False + + + True + True + frames-adjustment + 0 + + + 1 + + + + + True + Preview + + + 1 + False + + True @@ -425,15 +446,19 @@ - + 65535 1 10 - + 256 65535 1 10 + + 1 + 10 + diff --git a/tools/gui/ring-buffer.c b/tools/gui/ring-buffer.c new file mode 100644 index 0000000..56c7620 --- /dev/null +++ b/tools/gui/ring-buffer.c @@ -0,0 +1,64 @@ + +#include +#include "ring-buffer.h" + +RingBuffer * +ring_buffer_new (gsize block_size, + gsize n_blocks) +{ + RingBuffer *buffer; + + buffer = g_new0 (RingBuffer, 1); + buffer->block_size = block_size; + buffer->n_blocks_total = n_blocks; + buffer->n_blocks_used = 0; + buffer->start_index = 0; + buffer->data = g_malloc0 (n_blocks * buffer->block_size); + + return buffer; +} + +void +ring_buffer_free (RingBuffer *buffer) +{ + g_free (buffer->data); + g_free (buffer); +} + +void +ring_buffer_reset (RingBuffer *buffer) +{ + buffer->n_blocks_used = 0; + buffer->start_index = 0; +} + +gpointer +ring_buffer_get_current_pointer (RingBuffer *buffer) +{ + return ring_buffer_get_pointer (buffer, 0); +} + +gpointer +ring_buffer_get_pointer (RingBuffer *buffer, + guint index) +{ + g_assert (index < buffer->n_blocks_total); + return buffer->data + ((buffer->start_index + index) % buffer->n_blocks_total) * buffer->block_size; +} + +guint +ring_buffer_get_num_blocks (RingBuffer *buffer) +{ + return buffer->n_blocks_used; +} + +void +ring_buffer_proceed (RingBuffer *buffer) +{ + buffer->start_index++; + + if (buffer->n_blocks_used < buffer->n_blocks_total) + buffer->n_blocks_used++; + else + buffer->start_index = buffer->start_index % buffer->n_blocks_total; +} diff --git a/tools/gui/ring-buffer.h b/tools/gui/ring-buffer.h new file mode 100644 index 0000000..22cbde7 --- /dev/null +++ b/tools/gui/ring-buffer.h @@ -0,0 +1,28 @@ +#ifndef RING_BUFFER_H +#define RING_BUFFER_H + +#include + +G_BEGIN_DECLS + +typedef struct { + guchar *data; + gsize block_size; + guint n_blocks_total; + guint n_blocks_used; + guint start_index; +} RingBuffer; + +RingBuffer * ring_buffer_new (gsize block_size, + gsize n_blocks); +void ring_buffer_free (RingBuffer *buffer); +void ring_buffer_reset (RingBuffer *buffer); +gpointer ring_buffer_get_current_pointer (RingBuffer *buffer); +gpointer ring_buffer_get_pointer (RingBuffer *buffer, + guint index); +guint ring_buffer_get_num_blocks (RingBuffer *buffer); +void ring_buffer_proceed (RingBuffer *buffer); + +G_END_DECLS + +#endif -- cgit v1.2.3 From c48496b50a72575438f87da69080a48e0878a121 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 12 Oct 2012 16:17:53 +0200 Subject: Control memory size via command line --- tools/gui/control.c | 110 ++++++++++++++++++++++++++++++++---------------- tools/gui/control.glade | 2 +- tools/gui/ring-buffer.c | 2 +- 3 files changed, 76 insertions(+), 38 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 84799cb..eab2be7 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -57,7 +57,7 @@ typedef struct { } ThreadData; static UcaPluginManager *plugin_manager; - +static gsize mem_size = 2048; static void convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) @@ -255,69 +255,86 @@ on_record_button_clicked (GtkWidget *widget, gpointer args) static void create_main_window (GtkBuilder *builder, const gchar* camera_name) { + static ThreadData td; + UcaCamera *camera; GtkWidget *window; GtkWidget *image; + GtkWidget *histogram_view; GtkWidget *property_tree_view; GdkPixbuf *pixbuf; GtkBox *histogram_box; - GtkContainer *scrolled_property_window; + GtkContainer *property_window; GtkAdjustment *max_bin_adjustment; - static ThreadData td; + RingBuffer *ring_buffer; + gsize image_size; + guint n_frames; + guint bits_per_sample; + guint pixel_size; + guint width, height; + GError *error = NULL; - GError *error = NULL; - UcaCamera *camera = uca_plugin_manager_get_camera (plugin_manager, camera_name, &error); + camera = uca_plugin_manager_get_camera (plugin_manager, camera_name, &error); if ((camera == NULL) || (error != NULL)) { g_error ("%s\n", error->message); gtk_main_quit (); } - guint bits_per_sample; g_object_get (camera, - "roi-width", &td.width, - "roi-height", &td.height, + "roi-width", &width, + "roi-height", &height, "sensor-bitdepth", &bits_per_sample, NULL); - property_tree_view = egg_property_tree_view_new (G_OBJECT (camera)); - scrolled_property_window = GTK_CONTAINER (gtk_builder_get_object (builder, "scrolledwindow2")); - gtk_container_add (scrolled_property_window, property_tree_view); + histogram_view = egg_histogram_view_new (); + property_tree_view = egg_property_tree_view_new (G_OBJECT (camera)); + property_window = GTK_CONTAINER (gtk_builder_get_object (builder, "property-window")); + image = GTK_WIDGET (gtk_builder_get_object (builder, "image")); + histogram_box = GTK_BOX (gtk_builder_get_object (builder, "histogram-box")); + window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); + max_bin_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "max-bin-value-adjustment")); + + 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.histogram_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "histogram-checkbutton")); + td.frame_slider = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "frames-adjustment")); + + /* Set initial data */ + pixel_size = bits_per_sample > 8 ? 2 : 1; + image_size = pixel_size * width * height; + n_frames = mem_size * 1024 * 1024 / image_size; + ring_buffer = ring_buffer_new (image_size, n_frames); + + set_tool_button_state (&td); + + egg_histogram_view_set_data (EGG_HISTOGRAM_VIEW (histogram_view), + ring_buffer_get_current_pointer (ring_buffer), + width * height, bits_per_sample, 256); - image = GTK_WIDGET (gtk_builder_get_object (builder, "image")); - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, td.width, td.height); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); - td.pixel_size = bits_per_sample > 8 ? 2 : 1; + gtk_adjustment_set_value (max_bin_adjustment, pow (2, bits_per_sample) - 1); + + g_message ("Allocated memory for %d frames", n_frames); + + td.pixel_size = pixel_size; td.image = image; td.pixbuf = pixbuf; - td.buffer = ring_buffer_new (td.pixel_size * td.width * td.height, 256); + td.buffer = ring_buffer; td.pixels = gdk_pixbuf_get_pixels (pixbuf); td.state = IDLE; td.camera = camera; - td.histogram_view = egg_histogram_view_new (); - td.histogram_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "histogram-checkbutton")); - td.frame_slider = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "frames-adjustment")); - - histogram_box = GTK_BOX (gtk_builder_get_object (builder, "histogram-box")); - gtk_box_pack_start (histogram_box, td.histogram_view, TRUE, TRUE, 6); - egg_histogram_view_set_data (EGG_HISTOGRAM_VIEW (td.histogram_view), - ring_buffer_get_current_pointer (td.buffer), - td.width * td.height, bits_per_sample, 256); - - window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); - g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); - - 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")); - set_tool_button_state (&td); + td.width = width; + td.height = height; + td.histogram_view = histogram_view; + /* Hook up signals */ g_object_bind_property (gtk_builder_get_object (builder, "min-bin-value-adjustment"), "value", td.histogram_view, "minimum-bin-value", G_BINDING_DEFAULT); - max_bin_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "max-bin-value-adjustment")); - gtk_adjustment_set_value (max_bin_adjustment, pow (2, bits_per_sample) - 1); g_object_bind_property (max_bin_adjustment, "value", td.histogram_view, "maximum-bin-value", G_BINDING_DEFAULT); @@ -326,6 +343,11 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) 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); g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); + g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); + + /* Layout */ + gtk_container_add (property_window, property_tree_view); + gtk_box_pack_start (histogram_box, td.histogram_view, TRUE, TRUE, 6); gtk_widget_show_all (window); } @@ -398,16 +420,32 @@ create_choice_window (GtkBuilder *builder) int main (int argc, char *argv[]) { + GtkBuilder *builder; + GOptionContext *context; GError *error = NULL; + static GOptionEntry entries[] = + { + { "mem-size", 'm', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &mem_size, "Memory in megabytes to allocate for frame storage", "M" }, + { NULL } + }; + + context = g_option_context_new ("- control libuca cameras"); + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); + if (!g_option_context_parse (context, &argc, &argv, &error)) { + g_print ("Option parsing failed: %s\n", error->message); + return 1; + } + g_thread_init (NULL); gdk_threads_init (); gtk_init (&argc, &argv); - GtkBuilder *builder = gtk_builder_new (); + builder = gtk_builder_new (); if (!gtk_builder_add_from_file (builder, CONTROL_GLADE_PATH, &error)) { - g_print ("Error: %s\n", error->message); + g_print ("Could not load UI file: %s\n", error->message); return 1; } diff --git a/tools/gui/control.glade b/tools/gui/control.glade index c3008ec..90d9511 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -343,7 +343,7 @@ - + True True automatic diff --git a/tools/gui/ring-buffer.c b/tools/gui/ring-buffer.c index 56c7620..5915d2a 100644 --- a/tools/gui/ring-buffer.c +++ b/tools/gui/ring-buffer.c @@ -13,7 +13,7 @@ ring_buffer_new (gsize block_size, buffer->n_blocks_total = n_blocks; buffer->n_blocks_used = 0; buffer->start_index = 0; - buffer->data = g_malloc0 (n_blocks * buffer->block_size); + buffer->data = g_malloc0_n (n_blocks, block_size); return buffer; } -- cgit v1.2.3 From 63a030a0d65f4ab77a2cbc138eaf5782e276e290 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 12 Oct 2012 16:29:21 +0200 Subject: Accept anything else than 8 bit as 16 bits For now, there is no other possible format. --- tools/gui/egg-histogram-view.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/gui/egg-histogram-view.c b/tools/gui/egg-histogram-view.c index 91e61e8..5041ba2 100644 --- a/tools/gui/egg-histogram-view.c +++ b/tools/gui/egg-histogram-view.c @@ -143,7 +143,7 @@ compute_histogram (EggHistogramViewPrivate *priv) } } } - else if (priv->n_bits == 16) { + else { guint16 *data = (guint16 *) priv->data; for (guint i = 0; i < priv->n_elements; i++) { @@ -155,8 +155,6 @@ compute_histogram (EggHistogramViewPrivate *priv) } } } - else - g_warning ("%i number of bits unsupported", priv->n_bits); } static void -- cgit v1.2.3 From be1bfae1ecef5032e667174da4b4ad016d47887b Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 12 Oct 2012 16:31:06 +0200 Subject: Reflect correct state of camera --- tools/gui/control.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index eab2be7..5e8860f 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -205,8 +205,6 @@ on_start_button_clicked (GtkWidget *widget, gpointer args) ThreadData *data = (ThreadData *) args; GError *error = NULL; - data->state = RUNNING; - set_tool_button_state (data); uca_camera_start_recording (data->camera, &error); @@ -219,6 +217,8 @@ on_start_button_clicked (GtkWidget *widget, gpointer args) g_printerr ("Failed to create thread: %s\n", error->message); return; } + + data->state = RUNNING; } static void -- cgit v1.2.3 From 6d4826f326f981a207ed6d64d5c481d0b1bddd00 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 12 Oct 2012 16:47:51 +0200 Subject: Fix button states --- tools/gui/control.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 5e8860f..e01bc7d 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -191,7 +191,7 @@ on_frame_slider_changed (GtkAdjustment *adjustment, gpointer user_data) if (data->state == IDLE) { gpointer buffer; gint index; - + index = (gint) gtk_adjustment_get_value (adjustment); buffer = ring_buffer_get_pointer (data->buffer, index); convert_grayscale_to_rgb (data, buffer); @@ -205,7 +205,6 @@ on_start_button_clicked (GtkWidget *widget, gpointer args) ThreadData *data = (ThreadData *) args; GError *error = NULL; - set_tool_button_state (data); uca_camera_start_recording (data->camera, &error); if (error != NULL) { @@ -213,12 +212,14 @@ on_start_button_clicked (GtkWidget *widget, gpointer args) return; } + data->state = RUNNING; + set_tool_button_state (data); + if (!g_thread_create (preview_frames, data, FALSE, &error)) { g_printerr ("Failed to create thread: %s\n", error->message); - return; + data->state = IDLE; + set_tool_button_state (data); } - - data->state = RUNNING; } static void @@ -242,14 +243,21 @@ on_record_button_clicked (GtkWidget *widget, gpointer args) ThreadData *data = (ThreadData *) args; GError *error = NULL; + uca_camera_start_recording (data->camera, &error); + + if (error != NULL) { + g_printerr ("Failed to start recording: %s\n", error->message); + } + data->timestamp = (int) time (0); data->state = RECORDING; - set_tool_button_state (data); - uca_camera_start_recording (data->camera, &error); - if (!g_thread_create (record_frames, data, FALSE, &error)) + if (!g_thread_create (record_frames, data, FALSE, &error)) { g_printerr ("Failed to create thread: %s\n", error->message); + data->state = IDLE; + set_tool_button_state (data); + } } static void @@ -434,7 +442,7 @@ main (int argc, char *argv[]) g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { - g_print ("Option parsing failed: %s\n", error->message); + g_print ("Option parsing failed: %s\n", error->message); return 1; } -- cgit v1.2.3 From 33a90d8dc20a513722f5fdf66a99cff91be422d5 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 15 Oct 2012 10:33:14 +0200 Subject: Fix replay feature --- tools/gui/control.c | 54 ++++++++++++++++++++++++------------------ tools/gui/egg-histogram-view.c | 29 ++++++++++++++++++++--- tools/gui/egg-histogram-view.h | 3 +++ tools/gui/ring-buffer.c | 12 +++++----- tools/gui/ring-buffer.h | 2 +- 5 files changed, 67 insertions(+), 33 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index e01bc7d..f26cafc 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -79,6 +79,9 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) output[j++] = val; output[j++] = val; output[j++] = val; + /* if (i < 10) { */ + /* g_print ("%i->%i ", input[i], val); */ + /* } */ } } else if (data->pixel_size == 2) { @@ -161,13 +164,11 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) } void -on_destroy (GtkWidget *widget, gpointer data) +on_destroy (GtkWidget *widget, ThreadData *data) { - ThreadData *td = (ThreadData *) data; - - td->state = IDLE; - g_object_unref (td->camera); - ring_buffer_free (td->buffer); + data->state = IDLE; + g_object_unref (data->camera); + ring_buffer_free (data->buffer); gtk_main_quit (); } @@ -184,25 +185,27 @@ set_tool_button_state (ThreadData *data) } static void -on_frame_slider_changed (GtkAdjustment *adjustment, gpointer user_data) +update_current_frame (ThreadData *data) { - ThreadData *data = (ThreadData *) user_data; + gpointer buffer; + gint index; - if (data->state == IDLE) { - gpointer buffer; - gint index; + index = (gint) gtk_adjustment_get_value (data->frame_slider); + buffer = ring_buffer_get_pointer (data->buffer, index); + convert_grayscale_to_rgb (data, buffer); + update_pixbuf (data); +} - index = (gint) gtk_adjustment_get_value (adjustment); - buffer = ring_buffer_get_pointer (data->buffer, index); - convert_grayscale_to_rgb (data, buffer); - update_pixbuf (data); - } +static void +on_frame_slider_changed (GtkAdjustment *adjustment, ThreadData *data) +{ + if (data->state == IDLE) + update_current_frame (data); } static void -on_start_button_clicked (GtkWidget *widget, gpointer args) +on_start_button_clicked (GtkWidget *widget, ThreadData *data) { - ThreadData *data = (ThreadData *) args; GError *error = NULL; uca_camera_start_recording (data->camera, &error); @@ -223,13 +226,11 @@ on_start_button_clicked (GtkWidget *widget, gpointer args) } static void -on_stop_button_clicked (GtkWidget *widget, gpointer args) +on_stop_button_clicked (GtkWidget *widget, ThreadData *data) { - ThreadData *data = (ThreadData *) args; GError *error = NULL; data->state = IDLE; - set_tool_button_state (data); uca_camera_stop_recording (data->camera, &error); @@ -238,9 +239,8 @@ on_stop_button_clicked (GtkWidget *widget, gpointer args) } static void -on_record_button_clicked (GtkWidget *widget, gpointer args) +on_record_button_clicked (GtkWidget *widget, ThreadData *data) { - ThreadData *data = (ThreadData *) args; GError *error = NULL; uca_camera_start_recording (data->camera, &error); @@ -260,6 +260,13 @@ on_record_button_clicked (GtkWidget *widget, gpointer args) } } +static void +on_histogram_changed (EggHistogramView *view, ThreadData *data) +{ + if (data->state == IDLE) + update_current_frame (data); +} + static void create_main_window (GtkBuilder *builder, const gchar* camera_name) { @@ -351,6 +358,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) 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); g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); + g_signal_connect (histogram_view, "changed", G_CALLBACK (on_histogram_changed), &td); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); /* Layout */ diff --git a/tools/gui/egg-histogram-view.c b/tools/gui/egg-histogram-view.c index 5041ba2..812af7a 100644 --- a/tools/gui/egg-histogram-view.c +++ b/tools/gui/egg-histogram-view.c @@ -55,8 +55,16 @@ enum N_PROPERTIES }; +enum +{ + CHANGED, + LAST_SIGNAL +}; + static GParamSpec *egg_histogram_view_properties[N_PROPERTIES] = { NULL, }; +static guint egg_histogram_view_signals[LAST_SIGNAL] = { 0 }; + GtkWidget * egg_histogram_view_new (void) @@ -253,7 +261,7 @@ egg_histogram_view_expose (GtkWidget *widget, cairo_rectangle (cr, BORDER, BORDER, priv->min_border + 0.5, height - 1); cairo_fill (cr); - cairo_rectangle (cr, priv->max_border + 0.5, BORDER, width - priv->min_border - 0.5, height - 1); + cairo_rectangle (cr, priv->max_border + 0.5, BORDER, width - priv->max_border + 0.5, height - 1); cairo_fill (cr); /* Draw spikes */ @@ -393,9 +401,14 @@ egg_histogram_view_motion_notify (GtkWidget *widget, priv = view->priv; if (priv->grabbing) { - *priv->grabbed = event->x; + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); - gtk_widget_queue_draw (widget); + if ((event->x + BORDER > 0) && (event->x + BORDER < allocation.width)) { + *priv->grabbed = event->x; + gtk_widget_queue_draw (widget); + } } else { if (is_on_border (priv, event->x)) @@ -416,6 +429,7 @@ egg_histogram_view_button_release (GtkWidget *widget, view = EGG_HISTOGRAM_VIEW (widget); set_cursor_type (view, GDK_ARROW); view->priv->grabbing = FALSE; + g_signal_emit (widget, egg_histogram_view_signals[CHANGED], 0); return TRUE; } @@ -473,6 +487,15 @@ egg_histogram_view_class_init (EggHistogramViewClass *klass) g_object_class_install_property (object_class, PROP_MINIMUM_BIN_VALUE, egg_histogram_view_properties[PROP_MINIMUM_BIN_VALUE]); g_object_class_install_property (object_class, PROP_MAXIMUM_BIN_VALUE, egg_histogram_view_properties[PROP_MAXIMUM_BIN_VALUE]); + egg_histogram_view_signals[CHANGED] = + g_signal_new ("changed", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (EggHistogramViewClass, changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + g_type_class_add_private (klass, sizeof (EggHistogramViewPrivate)); } diff --git a/tools/gui/egg-histogram-view.h b/tools/gui/egg-histogram-view.h index 61a1c8c..7a62fca 100644 --- a/tools/gui/egg-histogram-view.h +++ b/tools/gui/egg-histogram-view.h @@ -44,6 +44,9 @@ struct _EggHistogramView struct _EggHistogramViewClass { GtkDrawingAreaClass parent_class; + + /* signals */ + void (* changed) (EggHistogramView *view); }; GType egg_histogram_view_get_type (void); diff --git a/tools/gui/ring-buffer.c b/tools/gui/ring-buffer.c index 5915d2a..ec2638c 100644 --- a/tools/gui/ring-buffer.c +++ b/tools/gui/ring-buffer.c @@ -12,7 +12,7 @@ ring_buffer_new (gsize block_size, buffer->block_size = block_size; buffer->n_blocks_total = n_blocks; buffer->n_blocks_used = 0; - buffer->start_index = 0; + buffer->current_index = 0; buffer->data = g_malloc0_n (n_blocks, block_size); return buffer; @@ -29,13 +29,13 @@ void ring_buffer_reset (RingBuffer *buffer) { buffer->n_blocks_used = 0; - buffer->start_index = 0; + buffer->current_index = 0; } gpointer ring_buffer_get_current_pointer (RingBuffer *buffer) { - return ring_buffer_get_pointer (buffer, 0); + return buffer->data + (buffer->current_index % buffer->n_blocks_total) * buffer->block_size; } gpointer @@ -43,7 +43,7 @@ ring_buffer_get_pointer (RingBuffer *buffer, guint index) { g_assert (index < buffer->n_blocks_total); - return buffer->data + ((buffer->start_index + index) % buffer->n_blocks_total) * buffer->block_size; + return buffer->data + ((buffer->current_index - buffer->n_blocks_used + index) % buffer->n_blocks_total) * buffer->block_size; } guint @@ -55,10 +55,10 @@ ring_buffer_get_num_blocks (RingBuffer *buffer) void ring_buffer_proceed (RingBuffer *buffer) { - buffer->start_index++; + buffer->current_index++; if (buffer->n_blocks_used < buffer->n_blocks_total) buffer->n_blocks_used++; else - buffer->start_index = buffer->start_index % buffer->n_blocks_total; + buffer->current_index = buffer->current_index % buffer->n_blocks_total; } diff --git a/tools/gui/ring-buffer.h b/tools/gui/ring-buffer.h index 22cbde7..9966eb7 100644 --- a/tools/gui/ring-buffer.h +++ b/tools/gui/ring-buffer.h @@ -10,7 +10,7 @@ typedef struct { gsize block_size; guint n_blocks_total; guint n_blocks_used; - guint start_index; + guint current_index; } RingBuffer; RingBuffer * ring_buffer_new (gsize block_size, -- cgit v1.2.3 From e1ab5f557171c94c0b86203cd2ecb50bb9a52ab0 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Tue, 16 Oct 2012 11:09:39 +0200 Subject: Add zoom functionality --- tools/gui/control.c | 103 ++++++++++++++++++++++++++++++++++++------------ tools/gui/control.glade | 90 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 163 insertions(+), 30 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index f26cafc..c9fd2f6 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -41,6 +41,7 @@ typedef struct { GtkWidget *start_button; GtkWidget *stop_button; GtkWidget *record_button; + GtkComboBox *zoom_box; GtkWidget *histogram_view; GtkToggleButton *histogram_button; @@ -48,12 +49,13 @@ typedef struct { RingBuffer *buffer; guchar *pixels; + gint display_width, display_height; + gdouble zoom_factor; State state; - int timestamp; - int width; - int height; - int pixel_size; + gint timestamp; + gint width, height; + gint pixel_size; } ThreadData; static UcaPluginManager *plugin_manager; @@ -66,32 +68,42 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) gdouble max; gdouble factor; guint8 *output; + gint i = 0; + gint stride; egg_histogram_get_visible_range (EGG_HISTOGRAM_VIEW (data->histogram_view), &min, &max); factor = 255.0 / (max - min); output = data->pixels; + stride = (gint) 1 / data->zoom_factor; if (data->pixel_size == 1) { guint8 *input = (guint8 *) buffer; - for (int i = 0, j = 0; i < data->width * data->height; i++) { - guchar val = (guchar) ((input[i] - min) * factor); - output[j++] = val; - output[j++] = val; - output[j++] = val; - /* if (i < 10) { */ - /* g_print ("%i->%i ", input[i], val); */ - /* } */ + 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) { + guchar val = (guchar) ((input[offset] - min) * factor); + + output[i++] = val; + output[i++] = val; + output[i++] = val; + } } } else if (data->pixel_size == 2) { guint16 *input = (guint16 *) buffer; - for (int i = 0, j = 0; i < data->width * data->height; i++) { - guchar val = (guint8) ((input[i] - min) * factor); - output[j++] = val; - output[j++] = val; - output[j++] = val; + 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) { + guchar val = (guchar) ((input[offset] - min) * factor); + + output[i++] = val; + output[i++] = val; + output[i++] = val; + } } } } @@ -100,14 +112,24 @@ static void update_pixbuf (ThreadData *data) { gdk_flush (); - gtk_image_clear (GTK_IMAGE (data->image)); gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); - gtk_widget_queue_draw_area (data->image, 0, 0, data->width, data->height); + gtk_widget_queue_draw_area (data->image, 0, 0, data->display_width, data->display_height); if (gtk_toggle_button_get_active (data->histogram_button)) gtk_widget_queue_draw (data->histogram_view); } +static void +update_pixbuf_dimensions (ThreadData *data) +{ + if (data->pixbuf != NULL) + g_object_unref (data->pixbuf); + + data->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, data->display_width, data->display_height); + data->pixels = gdk_pixbuf_get_pixels (data->pixbuf); + gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); +} + static gpointer preview_frames (void *args) { @@ -182,6 +204,8 @@ set_tool_button_state (ThreadData *data) data->state == RUNNING || data->state == RECORDING); gtk_widget_set_sensitive (data->record_button, data->state == IDLE); + gtk_widget_set_sensitive (GTK_WIDGET (data->zoom_box), + data->state == IDLE); } static void @@ -267,6 +291,28 @@ on_histogram_changed (EggHistogramView *view, ThreadData *data) update_current_frame (data); } +static void +on_zoom_changed (GtkComboBox *widget, ThreadData *data) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gdouble factor; + + enum { + DISPLAY_COLUMN, + FACTOR_COLUMN + }; + + model = gtk_combo_box_get_model (widget); + gtk_combo_box_get_active_iter (widget, &iter); + gtk_tree_model_get (model, &iter, FACTOR_COLUMN, &factor, -1); + + data->display_width = (gint) data->width * factor; + data->display_height = (gint) data->height * factor; + data->zoom_factor = factor; + update_pixbuf_dimensions (data); +} + static void create_main_window (GtkBuilder *builder, const gchar* camera_name) { @@ -278,9 +324,9 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) GtkWidget *property_tree_view; GdkPixbuf *pixbuf; GtkBox *histogram_box; - GtkContainer *property_window; - GtkAdjustment *max_bin_adjustment; - RingBuffer *ring_buffer; + GtkContainer *property_window; + GtkAdjustment *max_bin_adjustment; + RingBuffer *ring_buffer; gsize image_size; guint n_frames; guint bits_per_sample; @@ -309,6 +355,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); max_bin_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "max-bin-value-adjustment")); + td.zoom_box = GTK_COMBO_BOX (gtk_builder_get_object (builder, "zoom-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")); @@ -336,15 +383,18 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.pixel_size = pixel_size; td.image = image; - td.pixbuf = pixbuf; + td.pixbuf = NULL; + td.pixels = NULL; td.buffer = ring_buffer; - td.pixels = gdk_pixbuf_get_pixels (pixbuf); td.state = IDLE; td.camera = camera; - td.width = width; - td.height = height; + td.width = td.display_width = width; + td.height = td.display_height = height; + td.zoom_factor = 1.0; td.histogram_view = histogram_view; + update_pixbuf_dimensions (&td); + /* Hook up signals */ g_object_bind_property (gtk_builder_get_object (builder, "min-bin-value-adjustment"), "value", td.histogram_view, "minimum-bin-value", @@ -358,6 +408,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) 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); g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); + g_signal_connect (td.zoom_box, "changed", G_CALLBACK (on_zoom_changed), &td); g_signal_connect (histogram_view, "changed", G_CALLBACK (on_histogram_changed), &td); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); diff --git a/tools/gui/control.glade b/tools/gui/control.glade index 90d9511..37f8150 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -200,6 +200,7 @@ True + 10 @@ -310,11 +311,70 @@ - + True - True - frames-adjustment - 0 + 10 + 2 + 2 + 6 + 6 + + + True + True + frames-adjustment + 0 + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + True + 1 + Frame: + + + 1 + 2 + GTK_FILL + + + + + + True + 1 + Zoom: + + + GTK_FILL + + + + + + True + zoom-values + + + + 0 + + + + + 1 + 2 + GTK_FILL + GTK_FILL + + 1 @@ -365,6 +425,28 @@ + + + + + + + + + + 100 % + 1 + + + 50 % + 0.5 + + + 25 % + 0.25 + + + 6 -- cgit v1.2.3 From a1ab005916ba3aa50923294c5be3da0ded16fbc0 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Oct 2012 10:56:30 +0200 Subject: Add download button and make dimax work --- tools/gui/control.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- tools/gui/control.glade | 12 ++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index c9fd2f6..930c4d0 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -41,6 +41,7 @@ typedef struct { GtkWidget *start_button; GtkWidget *stop_button; GtkWidget *record_button; + GtkWidget *download_button; GtkComboBox *zoom_box; GtkWidget *histogram_view; @@ -52,6 +53,7 @@ typedef struct { gint display_width, display_height; gdouble zoom_factor; State state; + gboolean data_in_camram; gint timestamp; gint width, height; @@ -88,7 +90,7 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) output[i++] = val; output[i++] = val; output[i++] = val; - } + } } } else if (data->pixel_size == 2) { @@ -103,7 +105,7 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) output[i++] = val; output[i++] = val; output[i++] = val; - } + } } } } @@ -204,6 +206,8 @@ set_tool_button_state (ThreadData *data) data->state == RUNNING || data->state == RECORDING); gtk_widget_set_sensitive (data->record_button, data->state == IDLE); + gtk_widget_set_sensitive (data->download_button, + data->data_in_camram); gtk_widget_set_sensitive (GTK_WIDGET (data->zoom_box), data->state == IDLE); } @@ -254,12 +258,14 @@ on_stop_button_clicked (GtkWidget *widget, ThreadData *data) { GError *error = NULL; + g_object_get (data->camera, "has-camram-recording", &data->data_in_camram, NULL); data->state = IDLE; set_tool_button_state (data); uca_camera_stop_recording (data->camera, &error); if (error != NULL) g_printerr ("Failed to stop: %s\n", error->message); + } static void @@ -284,6 +290,38 @@ on_record_button_clicked (GtkWidget *widget, ThreadData *data) } } +static void +on_download_button_clicked (GtkWidget *widget, ThreadData *data) +{ + gpointer buffer; + GError *error = NULL; + + uca_camera_start_readout (data->camera, &error); + + if (error != NULL) { + g_printerr ("Failed to start read out of camera memory: %s\n", error->message); + return; + } + + ring_buffer_reset (data->buffer); + + while (error == NULL) { + buffer = ring_buffer_get_current_pointer (data->buffer); + uca_camera_grab (data->camera, &buffer, &error); + ring_buffer_proceed (data->buffer); + } + + if (error->code != UCA_CAMERA_ERROR_END_OF_STREAM) { + guint n_frames = ring_buffer_get_num_blocks (data->buffer); + + gtk_adjustment_set_upper (data->frame_slider, n_frames - 1); + gtk_adjustment_set_value (data->frame_slider, n_frames - 1); + } + else { + g_printerr ("Error while reading out frames: %s\n", error->message); + } +} + static void on_histogram_changed (EggHistogramView *view, ThreadData *data) { @@ -359,6 +397,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) 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.frame_slider = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "frames-adjustment")); @@ -368,8 +407,6 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) n_frames = mem_size * 1024 * 1024 / image_size; ring_buffer = ring_buffer_new (image_size, n_frames); - set_tool_button_state (&td); - egg_histogram_view_set_data (EGG_HISTOGRAM_VIEW (histogram_view), ring_buffer_get_current_pointer (ring_buffer), width * height, bits_per_sample, 256); @@ -392,8 +429,10 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.height = td.display_height = height; td.zoom_factor = 1.0; td.histogram_view = histogram_view; + td.data_in_camram = FALSE; update_pixbuf_dimensions (&td); + set_tool_button_state (&td); /* Hook up signals */ g_object_bind_property (gtk_builder_get_object (builder, "min-bin-value-adjustment"), "value", @@ -408,6 +447,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) 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); g_signal_connect (td.record_button, "clicked", G_CALLBACK (on_record_button_clicked), &td); + g_signal_connect (td.download_button, "clicked", G_CALLBACK (on_download_button_clicked), &td); g_signal_connect (td.zoom_box, "changed", G_CALLBACK (on_zoom_changed), &td); g_signal_connect (histogram_view, "changed", G_CALLBACK (on_histogram_changed), &td); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); diff --git a/tools/gui/control.glade b/tools/gui/control.glade index 37f8150..2d2aaac 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -152,6 +152,18 @@ True + + + True + Download + True + network-receive + + + False + True + + False -- cgit v1.2.3 From 983005dfbc3b07093145c0b964063e334b928d48 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Oct 2012 12:44:40 +0200 Subject: Fix download of in-camera frames --- tools/gui/control.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 930c4d0..aaeeb75 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -311,15 +311,19 @@ on_download_button_clicked (GtkWidget *widget, ThreadData *data) ring_buffer_proceed (data->buffer); } - if (error->code != UCA_CAMERA_ERROR_END_OF_STREAM) { + if (error->code == UCA_CAMERA_ERROR_END_OF_STREAM) { guint n_frames = ring_buffer_get_num_blocks (data->buffer); gtk_adjustment_set_upper (data->frame_slider, n_frames - 1); gtk_adjustment_set_value (data->frame_slider, n_frames - 1); } - else { + else g_printerr ("Error while reading out frames: %s\n", error->message); - } + + uca_camera_stop_readout (data->camera, &error); + + if (error != NULL) + g_printerr ("Failed to stop reading out of camera memory: %s\n", error->message); } static void -- cgit v1.2.3 From 694d4b4edd93bc8fdba6f578454d6b7b9f95003f Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Oct 2012 13:40:58 +0200 Subject: Free error that will be set during download --- tools/gui/control.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index aaeeb75..a5ef410 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -320,6 +320,7 @@ on_download_button_clicked (GtkWidget *widget, ThreadData *data) else g_printerr ("Error while reading out frames: %s\n", error->message); + g_error_free (error); uca_camera_stop_readout (data->camera, &error); if (error != NULL) -- cgit v1.2.3 From 4db2ac7026ae3bc85807016cb2510fed996a2a20 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Oct 2012 13:44:44 +0200 Subject: Don't make memory argument optional If `-m' is supplied, a number must follow. --- tools/gui/control.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index a5ef410..0d08893 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -538,7 +538,7 @@ main (int argc, char *argv[]) static GOptionEntry entries[] = { - { "mem-size", 'm', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &mem_size, "Memory in megabytes to allocate for frame storage", "M" }, + { "mem-size", 'm', 0, G_OPTION_ARG_INT, &mem_size, "Memory in megabytes to allocate for frame storage", "M" }, { NULL } }; -- cgit v1.2.3 From 2c3028f55ae1985315b8e350c1cdb26c9f7aa1a3 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Oct 2012 13:47:44 +0200 Subject: Set error NULL to avoid printing false message --- tools/gui/control.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 0d08893..07b7937 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -321,6 +321,8 @@ on_download_button_clicked (GtkWidget *widget, ThreadData *data) g_printerr ("Error while reading out frames: %s\n", error->message); g_error_free (error); + error = NULL; + uca_camera_stop_readout (data->camera, &error); if (error != NULL) -- cgit v1.2.3 From bcf80f7ddb66ee213dc493904e1b743e99d90082 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Oct 2012 16:07:13 +0200 Subject: Launch download dialog to ease waiting --- tools/gui/control.c | 34 ++++++++++++++++++++-- tools/gui/control.glade | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 07b7937..0b59837 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -44,6 +44,11 @@ typedef struct { GtkWidget *download_button; GtkComboBox *zoom_box; + GtkDialog *download_dialog; + GtkProgressBar *download_progressbar; + GtkWidget *download_close_button; + GtkAdjustment *download_adjustment; + GtkWidget *histogram_view; GtkToggleButton *histogram_button; GtkAdjustment *frame_slider; @@ -290,17 +295,21 @@ on_record_button_clicked (GtkWidget *widget, ThreadData *data) } } -static void -on_download_button_clicked (GtkWidget *widget, ThreadData *data) +static gpointer +download_frames (ThreadData *data) { gpointer buffer; + guint n_frames; GError *error = NULL; + g_object_get (data->camera, "recorded-frames", &n_frames, NULL); + g_print ("recorded %i frames\n", n_frames); + uca_camera_start_readout (data->camera, &error); if (error != NULL) { g_printerr ("Failed to start read out of camera memory: %s\n", error->message); - return; + return NULL; } ring_buffer_reset (data->buffer); @@ -327,6 +336,22 @@ on_download_button_clicked (GtkWidget *widget, ThreadData *data) if (error != NULL) g_printerr ("Failed to stop reading out of camera memory: %s\n", error->message); + + return NULL; +} + +static void +on_download_button_clicked (GtkWidget *widget, ThreadData *data) +{ + GError *error = NULL; + + if (!g_thread_create ((GThreadFunc) download_frames, data, FALSE, &error)) { + g_printerr ("Failed to create thread: %s\n", error->message); + } + + gtk_window_set_modal (GTK_WINDOW (data->download_dialog), TRUE); + gtk_dialog_run (data->download_dialog); + gtk_window_set_modal (GTK_WINDOW (data->download_dialog), FALSE); } static void @@ -408,6 +433,9 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.histogram_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "histogram-checkbutton")); td.frame_slider = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "frames-adjustment")); + td.download_dialog = GTK_DIALOG (gtk_builder_get_object (builder, "download-dialog")); + td.download_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "download-adjustment")); + /* Set initial data */ pixel_size = bits_per_sample > 8 ? 2 : 1; image_size = pixel_size * width * height; diff --git a/tools/gui/control.glade b/tools/gui/control.glade index 2d2aaac..eec9dde 100644 --- a/tools/gui/control.glade +++ b/tools/gui/control.glade @@ -555,4 +555,81 @@ 1 10 + + 5 + normal + + + True + 2 + + + True + 10 + 6 + + + True + 0 + Downloading Frames … + + + False + False + 0 + + + + + True + download-adjustment + + + False + 1 + + + + + 1 + + + + + True + end + + + gtk-close + True + True + True + True + + + False + False + 0 + + + + + False + False + end + 0 + + + + + + download-close-button + + + + 100 + 1 + 10 + 10 + -- cgit v1.2.3 From a7a48c55df8dc3e34a2ce50b18b70c0cd101766d Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Oct 2012 16:27:45 +0200 Subject: Show download progress --- tools/gui/control.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/gui/control.c b/tools/gui/control.c index 0b59837..877473e 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -36,6 +36,7 @@ typedef enum { typedef struct { UcaCamera *camera; + GtkWidget *main_window; GdkPixbuf *pixbuf; GtkWidget *image; GtkWidget *start_button; @@ -300,10 +301,14 @@ download_frames (ThreadData *data) { gpointer buffer; guint n_frames; + guint current_frame = 1; GError *error = NULL; g_object_get (data->camera, "recorded-frames", &n_frames, NULL); - g_print ("recorded %i frames\n", n_frames); + gdk_threads_enter (); + gtk_widget_set_sensitive (data->download_close_button, FALSE); + gtk_adjustment_set_upper (data->download_adjustment, n_frames); + gdk_threads_leave (); uca_camera_start_readout (data->camera, &error); @@ -318,6 +323,9 @@ download_frames (ThreadData *data) buffer = ring_buffer_get_current_pointer (data->buffer); uca_camera_grab (data->camera, &buffer, &error); ring_buffer_proceed (data->buffer); + gdk_threads_enter (); + gtk_adjustment_set_value (data->download_adjustment, current_frame++); + gdk_threads_leave (); } if (error->code == UCA_CAMERA_ERROR_END_OF_STREAM) { @@ -337,6 +345,10 @@ download_frames (ThreadData *data) if (error != NULL) g_printerr ("Failed to stop reading out of camera memory: %s\n", error->message); + gdk_threads_enter (); + gtk_widget_set_sensitive (data->download_close_button, TRUE); + gdk_threads_leave (); + return NULL; } @@ -349,9 +361,13 @@ on_download_button_clicked (GtkWidget *widget, ThreadData *data) g_printerr ("Failed to create thread: %s\n", error->message); } + gtk_widget_set_sensitive (data->main_window, FALSE); gtk_window_set_modal (GTK_WINDOW (data->download_dialog), TRUE); gtk_dialog_run (data->download_dialog); + gtk_widget_hide (GTK_WIDGET (data->download_dialog)); gtk_window_set_modal (GTK_WINDOW (data->download_dialog), FALSE); + gtk_widget_set_sensitive (data->main_window, TRUE); + gtk_window_set_modal (GTK_WINDOW (data->download_dialog), TRUE); } static void @@ -435,6 +451,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.download_dialog = GTK_DIALOG (gtk_builder_get_object (builder, "download-dialog")); td.download_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "download-adjustment")); + td.download_close_button = GTK_WIDGET (gtk_builder_get_object (builder, "download-close-button")); /* Set initial data */ pixel_size = bits_per_sample > 8 ? 2 : 1; @@ -465,6 +482,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.zoom_factor = 1.0; td.histogram_view = histogram_view; td.data_in_camram = FALSE; + td.main_window = window; update_pixbuf_dimensions (&td); set_tool_button_state (&td); -- cgit v1.2.3