summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-09 11:34:30 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-09 11:34:30 +0100
commitcd7590bac56800586c4aadef077d1effe03b00c4 (patch)
tree38863a4996a42301cb68becb88f137d2c28ccac3
parentcc74561cfaff3a4c8719b6972d4ec5c21be535ea (diff)
downloadlibuca-cd7590bac56800586c4aadef077d1effe03b00c4.tar.gz
libuca-cd7590bac56800586c4aadef077d1effe03b00c4.tar.bz2
libuca-cd7590bac56800586c4aadef077d1effe03b00c4.tar.xz
libuca-cd7590bac56800586c4aadef077d1effe03b00c4.zip
Use correct number of bytes per pixel when allocating buffers
-rw-r--r--src/grabbers/me4.c4
-rw-r--r--src/uca-cam.c5
-rw-r--r--src/uca-grabber.h2
-rw-r--r--test/control.c4
-rw-r--r--test/grab.c12
5 files changed, 16 insertions, 11 deletions
diff --git a/src/grabbers/me4.c b/src/grabbers/me4.c
index a833c07..647c5be 100644
--- a/src/grabbers/me4.c
+++ b/src/grabbers/me4.c
@@ -34,7 +34,7 @@ uint32_t uca_me4_get_property(struct uca_grabber_t *grabber, enum uca_property_i
return Fg_getParameter(GET_FG(grabber), property, data, PORT_A) == FG_OK ? UCA_NO_ERROR : UCA_ERR_PROP_GENERAL;
}
-uint32_t uca_me4_alloc(struct uca_grabber_t *grabber, uint32_t n_buffers)
+uint32_t uca_me4_alloc(struct uca_grabber_t *grabber, uint32_t pixel_size, uint32_t n_buffers)
{
if (GET_MEM(grabber) != NULL)
/* FIXME: invent better error code */
@@ -45,7 +45,7 @@ uint32_t uca_me4_alloc(struct uca_grabber_t *grabber, uint32_t n_buffers)
uca_me4_get_property(grabber, FG_HEIGHT, &height);
/* FIXME: get size of pixel */
- dma_mem *mem = Fg_AllocMemEx(GET_FG(grabber), n_buffers*width*height*sizeof(uint16_t), n_buffers);
+ dma_mem *mem = Fg_AllocMemEx(GET_FG(grabber), n_buffers*width*height*pixel_size, n_buffers);
if (mem != NULL) {
((struct uca_me4_grabber_t *) grabber->user)->mem = mem;
return UCA_NO_ERROR;
diff --git a/src/uca-cam.c b/src/uca-cam.c
index b77d62b..31ad416 100644
--- a/src/uca-cam.c
+++ b/src/uca-cam.c
@@ -6,7 +6,10 @@
uint32_t uca_cam_alloc(struct uca_camera_t *cam, uint32_t n_buffers)
{
- cam->grabber->alloc(cam->grabber, n_buffers);
+ uint32_t bitdepth;
+ cam->get_property(cam, UCA_PROP_BITDEPTH, &bitdepth);
+ const int pixel_size = bitdepth == 8 ? 1 : 2;
+ cam->grabber->alloc(cam->grabber, pixel_size, n_buffers);
}
enum uca_cam_state uca_cam_get_state(struct uca_camera_t *cam)
diff --git a/src/uca-grabber.h b/src/uca-grabber.h
index 4485b07..6ae7e8e 100644
--- a/src/uca-grabber.h
+++ b/src/uca-grabber.h
@@ -37,7 +37,7 @@ typedef uint32_t (*uca_grabber_get_property) (struct uca_grabber_t *grabber, enu
* \brief Allocate buffers with current width, height and bitdepth
* \note Subsequent changes of width and height might corrupt memory
*/
-typedef uint32_t (*uca_grabber_alloc) (struct uca_grabber_t *grabber, uint32_t n_buffers);
+typedef uint32_t (*uca_grabber_alloc) (struct uca_grabber_t *grabber, uint32_t pixel_size, uint32_t n_buffers);
/**
* \brief Begin acquiring frames
diff --git a/test/control.c b/test/control.c
index 010d6bc..1eb7e0f 100644
--- a/test/control.c
+++ b/test/control.c
@@ -309,12 +309,12 @@ int main(int argc, char *argv[])
gtk_tree_view_column_set_cell_data_func(value_column, GTK_CELL_RENDERER(value_renderer), value_cell_data_func, NULL, NULL);
/* start grabbing and thread */
- int mem_size = bits_per_sample == 8 ? 1 : 2;
+ int pixel_size = bits_per_sample == 8 ? 1 : 2;
struct ThreadData td;
uca_cam_alloc(cam, 20);
td.image = image;
td.pixbuf = pixbuf;
- td.buffer = (guchar *) g_malloc(mem_size * width * height);
+ td.buffer = (guchar *) g_malloc(pixel_size * width * height);
td.pixels = gdk_pixbuf_get_pixels(pixbuf);
td.width = width;
td.height = height;
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);