diff options
author | Matthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de> | 2011-03-21 16:33:40 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de> | 2011-03-21 16:33:40 +0100 |
commit | c8d39cd185b8ba5fa7e178924b6db9e8819fc528 (patch) | |
tree | 02d068d590f167c1bedbbe31a6bc47a6c92508e7 /test/grab-async.c | |
parent | 2e13f2b9911db58cd3c4a7c06175c1cf2b2ceaf1 (diff) | |
download | libuca-c8d39cd185b8ba5fa7e178924b6db9e8819fc528.tar.gz libuca-c8d39cd185b8ba5fa7e178924b6db9e8819fc528.tar.bz2 libuca-c8d39cd185b8ba5fa7e178924b6db9e8819fc528.tar.xz libuca-c8d39cd185b8ba5fa7e178924b6db9e8819fc528.zip |
Fix me4 callback grabbing
Diffstat (limited to 'test/grab-async.c')
-rw-r--r-- | test/grab-async.c | 37 |
1 files changed, 26 insertions, 11 deletions
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; |