From cd7590bac56800586c4aadef077d1effe03b00c4 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 9 Mar 2011 11:34:30 +0100 Subject: Use correct number of bytes per pixel when allocating buffers --- test/grab.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test/grab.c') diff --git a/test/grab.c b/test/grab.c index e2973dc..5ae44f1 100644 --- a/test/grab.c +++ b/test/grab.c @@ -15,18 +15,20 @@ int main(int argc, char *argv[]) /* take first camera */ struct uca_camera_t *cam = uca->cameras; - uint32_t val = 5000; + uint32_t val = 1; cam->set_property(cam, UCA_PROP_EXPOSURE, &val); val = 0; cam->set_property(cam, UCA_PROP_DELAY, &val); - uint32_t width, height; + uint32_t width, height, bits; cam->get_property(cam, UCA_PROP_WIDTH, &width); cam->get_property(cam, UCA_PROP_HEIGHT, &height); + cam->get_property(cam, UCA_PROP_BITDEPTH, &bits); - uca_cam_alloc(cam, 20); + uca_cam_alloc(cam, 10); - uint16_t *buffer = (uint16_t *) malloc(width * height * 2); + const int pixel_size = bits == 8 ? 1 : 2; + uint16_t *buffer = (uint16_t *) malloc(width * height * pixel_size); cam->start_recording(cam); cam->grab(cam, (char *) buffer); @@ -34,7 +36,7 @@ int main(int argc, char *argv[]) uca_destroy(uca); FILE *fp = fopen("out.raw", "wb"); - fwrite(buffer, width*height, 2, fp); + fwrite(buffer, width*height, pixel_size, fp); fclose(fp); free(buffer); -- cgit v1.2.3