summaryrefslogtreecommitdiffstats
path: root/test/control.c
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-17 13:55:53 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-17 13:55:53 +0100
commit65a2016becbb165afa4fdf16742f3586f83d0f30 (patch)
tree6cc4dcd57c5af48d3732b8aa855adbd710376a28 /test/control.c
parent35681d4e1d171117c9d4c2c4fd7d474b5871f81f (diff)
downloaduca-65a2016becbb165afa4fdf16742f3586f83d0f30.tar.gz
uca-65a2016becbb165afa4fdf16742f3586f83d0f30.tar.bz2
uca-65a2016becbb165afa4fdf16742f3586f83d0f30.tar.xz
uca-65a2016becbb165afa4fdf16742f3586f83d0f30.zip
Allow resize of image dimensions
Diffstat (limited to 'test/control.c')
-rw-r--r--test/control.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/test/control.c b/test/control.c
index 449c4ea..c220e21 100644
--- a/test/control.c
+++ b/test/control.c
@@ -1,10 +1,12 @@
#include <glib/gprintf.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
+#include <string.h>
#include "uca.h"
#include "uca-cam.h"
+
typedef struct {
guchar *buffer, *pixels;
gboolean running;
@@ -12,16 +14,18 @@ typedef struct {
GdkPixbuf *pixbuf;
int width;
int height;
- int bits;
+ int pixel_size;
struct uca_camera *cam;
struct uca *u;
-} ThreadData ;
+} ThreadData;
+
typedef struct {
ThreadData *thread_data;
GtkTreeStore *tree_store;
} ValueCellData;
+
enum {
COLUMN_NAME = 0,
COLUMN_VALUE,
@@ -30,6 +34,7 @@ enum {
NUM_COLUMNS
};
+
void convert_8bit_to_rgb(guchar *output, guchar *input, int width, int height)
{
for (int x = 0; x < width; x++) {
@@ -56,6 +61,22 @@ void convert_16bit_to_rgb(guchar *output, guchar *input, int width, int height)
}
}
+void reallocate_buffers(ThreadData *td, int width, int height)
+{
+ const size_t num_bytes = width * height * td->pixel_size;
+
+ g_object_unref(td->pixbuf);
+ g_free(td->buffer);
+
+ td->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height);
+ td->buffer = (guchar *) g_malloc(num_bytes);
+ td->width = width;
+ td->height = height;
+ td->pixels = gdk_pixbuf_get_pixels(td->pixbuf);
+ gtk_image_set_from_pixbuf(GTK_IMAGE(td->image), td->pixbuf);
+ memset(td->buffer, 0, num_bytes);
+}
+
static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
return FALSE;
@@ -76,9 +97,9 @@ void *grab_thread(void *args)
while (data->running) {
cam->grab(cam, (char *) data->buffer);
- if (data->bits == 8)
+ if (data->pixel_size == 1)
convert_8bit_to_rgb(data->pixels, data->buffer, data->width, data->height);
- else if (data->bits == 16)
+ else if (data->pixel_size == 2)
convert_16bit_to_rgb(data->pixels, data->buffer, data->width, data->height);
gdk_threads_enter();
@@ -129,6 +150,9 @@ static void on_valuecell_edited(GtkCellRendererText *renderer, gchar *path, gcha
/* TODO: extensive value checking */
uint32_t val = (uint32_t) g_ascii_strtoull(new_text, NULL, 10);
cam->set_property(cam, prop_id, &val);
+ if ((prop_id == UCA_PROP_WIDTH) || (prop_id == UCA_PROP_HEIGHT))
+ reallocate_buffers(value_data->thread_data, cam->frame_width, cam->frame_height);
+
gtk_tree_store_set(value_data->tree_store, &iter, COLUMN_VALUE, new_text, -1);
}
}
@@ -320,10 +344,10 @@ int main(int argc, char *argv[])
td.pixels = gdk_pixbuf_get_pixels(pixbuf);
td.width = width;
td.height = height;
- td.bits = bits_per_sample;
td.cam = cam;
td.u = u;
td.running = FALSE;
+ td.pixel_size = pixel_size;
g_signal_connect(window, "delete-event",
G_CALLBACK (delete_event), NULL);