From c8d39cd185b8ba5fa7e178924b6db9e8819fc528 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 21 Mar 2011 16:33:40 +0100 Subject: Fix me4 callback grabbing --- test/grab-async.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/grab-async.c b/test/grab-async.c index 1e0a90b..5f3694e 100644 --- a/test/grab-async.c +++ b/test/grab-async.c @@ -5,9 +5,24 @@ #include "uca.h" #include "uca-cam.h" +struct image_props { + uint32_t width; + uint32_t height; + uint32_t bits; +}; + void grab_callback(uint32_t image_number, void *buffer, void *meta_data, void *user) { - printf("got picture number %i\n", image_number); + struct image_props *props = (struct image_props *) user; + const int pixel_size = props->bits == 8 ? 1 : 2; + char filename[256]; + + sprintf(filename, "out-%04i.raw", image_number); + FILE *fp = fopen(filename, "wb"); + fwrite(buffer, props->width * props->height, pixel_size, fp); + fclose(fp); + + printf("grabbed picture %i at %p (%ix%i @ %i bits)\n", image_number, buffer, props->width, props->height, props->bits); } int main(int argc, char *argv[]) @@ -21,25 +36,25 @@ int main(int argc, char *argv[]) /* take first camera */ struct uca_camera *cam = u->cameras; - uint32_t val = 1; + uint32_t val = 5000; cam->set_property(cam, UCA_PROP_EXPOSURE, &val); val = 0; cam->set_property(cam, UCA_PROP_DELAY, &val); - val = 10; - cam->set_property(cam, UCA_PROP_FRAMERATE, &val); - uint32_t width, height, bits; - cam->get_property(cam, UCA_PROP_WIDTH, &width, 0); - cam->get_property(cam, UCA_PROP_HEIGHT, &height, 0); - cam->get_property(cam, UCA_PROP_BITDEPTH, &bits, 0); + struct image_props props; + cam->get_property(cam, UCA_PROP_WIDTH, &props.width, 0); + cam->get_property(cam, UCA_PROP_HEIGHT, &props.height, 0); + cam->get_property(cam, UCA_PROP_BITDEPTH, &props.bits, 0); uca_cam_alloc(cam, 10); - cam->register_callback(cam, &grab_callback, NULL); + cam->register_callback(cam, &grab_callback, &props); cam->start_recording(cam); - printf("waiting for 5 seconds\n"); - sleep(5); + printf("grabbing for 2 seconds\n"); + sleep(2); cam->stop_recording(cam); + printf("done\n"); + fflush(stdout); uca_destroy(u); return 0; -- cgit v1.2.3