From c7d87b9c4a2b220886aea7a6eb025685c57e950a Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Tue, 16 Jul 2013 12:31:24 +0200 Subject: Save acquired data as binary blob --- bin/gui/control.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ bin/gui/control.glade | 10 +--------- 2 files changed, 47 insertions(+), 9 deletions(-) (limited to 'bin') diff --git a/bin/gui/control.c b/bin/gui/control.c index 76b1345..ea150f3 100644 --- a/bin/gui/control.c +++ b/bin/gui/control.c @@ -332,6 +332,50 @@ on_frame_slider_changed (GtkAdjustment *adjustment, ThreadData *data) update_current_frame (data); } +static gboolean +write_raw_file (const gchar *filename, RingBuffer *buffer) +{ + FILE *fp; + guint n_blocks; + gsize size; + + fp = fopen (filename, "wb"); + + if (fp == NULL) + return FALSE; + + n_blocks = ring_buffer_get_num_blocks (buffer); + size = ring_buffer_get_block_size (buffer); + + for (guint i = 0; i < n_blocks; i++) + fwrite (ring_buffer_get_pointer (buffer, i), size , 1, fp); + + fclose (fp); + return TRUE; +} + +static void +on_save (GtkMenuItem *item, ThreadData *data) +{ + GtkWidget *dialog; + + dialog = gtk_file_chooser_dialog_new ("Save Frames", NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { + gchar *filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + write_raw_file (filename, data->buffer); + g_free (filename); + } + + gtk_widget_destroy (dialog); +} + static void on_start_button_clicked (GtkWidget *widget, ThreadData *data) { @@ -612,6 +656,8 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) gtk_builder_get_object (builder, "exposure-adjustment"), "value", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + g_signal_connect (gtk_builder_get_object (builder, "save-item"), "activate", G_CALLBACK (on_save), &td); + g_signal_connect (td.frame_slider, "value-changed", G_CALLBACK (on_frame_slider_changed), &td); g_signal_connect (td.start_button, "clicked", G_CALLBACK (on_start_button_clicked), &td); g_signal_connect (td.stop_button, "clicked", G_CALLBACK (on_stop_button_clicked), &td); diff --git a/bin/gui/control.glade b/bin/gui/control.glade index 179eb2c..2b87806 100644 --- a/bin/gui/control.glade +++ b/bin/gui/control.glade @@ -54,21 +54,13 @@ - + gtk-save True True True - - - gtk-save-as - True - True - True - - True -- cgit v1.2.3