diff options
author | Matthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de> | 2011-03-01 09:34:21 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de> | 2011-03-01 09:34:21 +0100 |
commit | a92101a277aed63224e1bd2077c99826e9e35f1d (patch) | |
tree | e2d38c3dfcfe46b483a13cc35e23f6ed453cf64e | |
parent | 28873ccf3f3f32486049eb40cd639bbab86e09dc (diff) | |
download | uca-a92101a277aed63224e1bd2077c99826e9e35f1d.tar.gz uca-a92101a277aed63224e1bd2077c99826e9e35f1d.tar.bz2 uca-a92101a277aed63224e1bd2077c99826e9e35f1d.tar.xz uca-a92101a277aed63224e1bd2077c99826e9e35f1d.zip |
Complete (simple) frame grabbing
-rw-r--r-- | src/cameras/pco.c | 38 | ||||
-rw-r--r-- | src/grabbers/me4.c | 40 | ||||
-rw-r--r-- | src/uca-cam.h | 2 | ||||
-rw-r--r-- | src/uca-grabber.h | 8 | ||||
-rw-r--r-- | src/uca.h | 19 | ||||
-rw-r--r-- | test/grab.c | 4 |
6 files changed, 75 insertions, 36 deletions
diff --git a/src/cameras/pco.c b/src/cameras/pco.c index f65eb14..cfb5d6b 100644 --- a/src/cameras/pco.c +++ b/src/cameras/pco.c @@ -60,11 +60,13 @@ static uint32_t uca_pco_set_property(struct uca_camera_t *cam, enum uca_property case UCA_PROP_WIDTH: if (grabber->set_property(grabber, FG_WIDTH, (uint32_t *) data) != UCA_NO_ERROR) return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + cam->frame_width = *((uint32_t *) data); break; case UCA_PROP_HEIGHT: if (grabber->set_property(grabber, FG_HEIGHT, (uint32_t *) data) != UCA_NO_ERROR) return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + cam->frame_height = *((uint32_t *) data); break; case UCA_PROP_X_OFFSET: @@ -109,11 +111,7 @@ static uint32_t uca_pco_get_property(struct uca_camera_t *cam, enum uca_property break; case UCA_PROP_WIDTH: - { - int w, h; - if (pco_get_actual_size(pco, &w, &h) == PCO_NOERROR) - set_void(data, uint32_t, w); - } + set_void(data, uint32_t, cam->frame_width); break; case UCA_PROP_WIDTH_MIN: @@ -125,11 +123,7 @@ static uint32_t uca_pco_get_property(struct uca_camera_t *cam, enum uca_property break; case UCA_PROP_HEIGHT: - { - int w, h; - if (pco_get_actual_size(pco, &w, &h) == PCO_NOERROR) - set_void(data, uint32_t, h); - } + set_void(data, uint32_t, cam->frame_height); break; case UCA_PROP_HEIGHT_MIN: @@ -179,19 +173,28 @@ static uint32_t uca_pco_get_property(struct uca_camera_t *cam, enum uca_property uint32_t uca_pco_start_recording(struct uca_camera_t *cam) { struct pco_edge_t *pco = GET_PCO(cam); - pco_arm_camera(pco); - pco_set_rec_state(pco, 1); - cam->grabber->acquire(cam->grabber, -1, true); + if (pco_arm_camera(pco) != PCO_NOERROR) + return UCA_ERR_CAM_ARM; + if (pco_set_rec_state(pco, 1) != PCO_NOERROR) + return UCA_ERR_CAM_RECORD; + return cam->grabber->acquire(cam->grabber, -1); } uint32_t uca_pco_stop_recording(struct uca_camera_t *cam) { - pco_set_rec_state(GET_PCO(cam), 0); + if (pco_set_rec_state(GET_PCO(cam), 0) != PCO_NOERROR) + return UCA_ERR_PROP_GENERAL; } uint32_t uca_pco_grab(struct uca_camera_t *cam, char *buffer, size_t n_bytes) { - cam->grabber->grab(cam->grabber, buffer, n_bytes); + uint16_t *frame; + uint32_t err = cam->grabber->grab(cam->grabber, (void **) &frame, n_bytes); + if (err != UCA_NO_ERROR) + return err; + /* FIXME: choose according to data format */ + pco_reorder_image_5x16((uint16_t *) buffer, frame, cam->frame_width, cam->frame_height); + return UCA_NO_ERROR; } uint32_t uca_pco_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber) @@ -202,7 +205,7 @@ uint32_t uca_pco_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber) return UCA_ERR_INIT_NOT_FOUND; } - if ((pco->serial_ref == NULL) || !pco_active(pco)) { + if ((pco->serial_ref == NULL) || !pco_is_active(pco)) { pco_destroy(pco); return UCA_ERR_INIT_NOT_FOUND; } @@ -210,6 +213,7 @@ uint32_t uca_pco_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber) struct uca_camera_t *uca = (struct uca_camera_t *) malloc(sizeof(struct uca_camera_t)); uca->user = pco; uca->grabber = grabber; + uca->grabber->asynchronous = false; /* Camera found, set function pointers... */ uca->destroy = &uca_pco_destroy; @@ -240,6 +244,8 @@ uint32_t uca_pco_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber) int width, height; pco_get_actual_size(pco, &width, &height); + uca->frame_width = width; + uca->frame_height = height; /* Yes, we really have to take an image twice as large because we set the * CameraLink interface to 8-bit 10 Taps, but are actually using 5x16 bits. */ diff --git a/src/grabbers/me4.c b/src/grabbers/me4.c index 2196172..e907014 100644 --- a/src/grabbers/me4.c +++ b/src/grabbers/me4.c @@ -50,19 +50,40 @@ uint32_t uca_me4_alloc(struct uca_grabber_t *grabber, uint32_t n_buffers) return UCA_ERR_PROP_GENERAL; } -uint32_t uca_me4_acquire(struct uca_grabber_t *grabber, int32_t n_frames, bool async) +uint32_t uca_me4_acquire(struct uca_grabber_t *grabber, int32_t n_frames) { - if (GET_MEM(grabber) != NULL) { - if (Fg_AcquireEx(GET_FG(grabber), 0, n_frames, ACQ_STANDARD, GET_MEM(grabber)) != FG_OK) - return UCA_NO_ERROR; - } - return UCA_ERR_PROP_GENERAL; + if (GET_MEM(grabber) == NULL) + return UCA_ERR_GRABBER_NOMEM; + + int flag = grabber->asynchronous ? ACQ_STANDARD : ACQ_BLOCK; + n_frames = n_frames < 0 ? GRAB_INFINITE : n_frames; + if (Fg_AcquireEx(GET_FG(grabber), 0, n_frames, flag, GET_MEM(grabber)) == FG_OK) + return UCA_NO_ERROR; + + return UCA_ERR_GRABBER_ACQUIRE; +} + +uint32_t uca_me4_stop_acquire(struct uca_grabber_t *grabber) +{ + if (GET_MEM(grabber) != NULL) + if (Fg_stopAcquireEx(GET_FG(grabber), 0, GET_MEM(grabber), STOP_SYNC) != FG_OK) + return UCA_ERR_PROP_GENERAL; + return UCA_NO_ERROR; } -uint32_t uca_me4_grab(struct uca_grabber_t *grabber, char *buffer, size_t n_bytes) +uint32_t uca_me4_grab(struct uca_grabber_t *grabber, void **buffer, size_t n_bytes) { - uint32_t last_frame = Fg_getLastPicNumber(GET_FG(grabber), PORT_A); - memcpy(buffer, Fg_getImagePtrEx(GET_FG(grabber), last_frame, PORT_A, GET_MEM(grabber)), n_bytes); + int32_t last_frame; + if (grabber->asynchronous) + last_frame = Fg_getLastPicNumberEx(GET_FG(grabber), PORT_A, GET_MEM(grabber)); + else + last_frame = Fg_getLastPicNumberBlockingEx(GET_FG(grabber), 1, PORT_A, 10, GET_MEM(grabber)); + + if (last_frame <= 0) + return UCA_ERR_PROP_GENERAL; + + *buffer = Fg_getImagePtrEx(GET_FG(grabber), last_frame, PORT_A, GET_MEM(grabber)); + return UCA_NO_ERROR; } uint32_t uca_me4_init(struct uca_grabber_t **grabber) @@ -83,6 +104,7 @@ uint32_t uca_me4_init(struct uca_grabber_t **grabber) uca->get_property = &uca_me4_get_property; uca->alloc = &uca_me4_alloc; uca->acquire = &uca_me4_acquire; + uca->stop_acquire = &uca_me4_stop_acquire; uca->grab = &uca_me4_grab; *grabber = uca; diff --git a/src/uca-cam.h b/src/uca-cam.h index f9db0b7..db780da 100644 --- a/src/uca-cam.h +++ b/src/uca-cam.h @@ -76,6 +76,8 @@ struct uca_camera_t { struct uca_grabber_t *grabber; enum uca_cam_state state; + uint32_t frame_width; + uint32_t frame_height; void *user; /**< private user data to be used by the camera driver */ }; diff --git a/src/uca-grabber.h b/src/uca-grabber.h index 0e203e1..dd68688 100644 --- a/src/uca-grabber.h +++ b/src/uca-grabber.h @@ -44,9 +44,11 @@ typedef uint32_t (*uca_grabber_alloc) (struct uca_grabber_t *grabber, uint32_t n * \param[in] n_frames Number of frames to acquire, -1 means infinite number * \param[in] async Grab asynchronous if true */ -typedef uint32_t (*uca_grabber_acquire) (struct uca_grabber_t *grabber, int32_t n_frames, bool async); +typedef uint32_t (*uca_grabber_acquire) (struct uca_grabber_t *grabber, int32_t n_frames); -typedef uint32_t (*uca_grabber_grab) (struct uca_grabber_t *grabber, char *buffer, size_t n_bytes); +typedef uint32_t (*uca_grabber_stop_acquire) (struct uca_grabber_t *grabber); + +typedef uint32_t (*uca_grabber_grab) (struct uca_grabber_t *grabber, void **buffer, size_t n_bytes); struct uca_grabber_t { @@ -58,9 +60,11 @@ struct uca_grabber_t { uca_grabber_get_property get_property; uca_grabber_alloc alloc; uca_grabber_acquire acquire; + uca_grabber_stop_acquire stop_acquire; uca_grabber_grab grab; /* Private */ + bool asynchronous; void *user; }; @@ -117,12 +117,19 @@ struct uca_property_t { } type; }; - -#define UCA_NO_ERROR 0 -#define UCA_ERR_INIT_NOT_FOUND 1 /**< camera probing or initialization failed */ -#define UCA_ERR_PROP_INVALID 2 /**< the requested property is not supported by the camera */ -#define UCA_ERR_PROP_GENERAL 3 /**< error occured reading/writing the property */ -#define UCA_ERR_PROP_VALUE_OUT_OF_RANGE 4 /**< error occured writing the property */ +enum uca_errors { + UCA_NO_ERROR = 0, + UCA_ERR_INIT_NOT_FOUND, /**< camera probing or initialization failed */ + UCA_ERR_PROP_INVALID, /**< the requested property is not supported by the camera */ + UCA_ERR_PROP_GENERAL, /**< error occured reading/writing the property */ + UCA_ERR_PROP_VALUE_OUT_OF_RANGE, /**< error occured writing the property */ + + UCA_ERR_CAM_ARM, + UCA_ERR_CAM_RECORD, + + UCA_ERR_GRABBER_ACQUIRE, + UCA_ERR_GRABBER_NOMEM +}; struct uca_t { struct uca_camera_t *cameras; diff --git a/test/grab.c b/test/grab.c index 34453da..aeed8c6 100644 --- a/test/grab.c +++ b/test/grab.c @@ -23,10 +23,8 @@ int main(int argc, char *argv[]) uint32_t width, height; cam->get_property(cam, UCA_PROP_WIDTH, &width); cam->get_property(cam, UCA_PROP_HEIGHT, &height); - printf("Image dimensions: %ix%i\n", width, height); - if (uca_cam_alloc(cam, 20) != UCA_NO_ERROR) - printf("Couldn't allocate buffer memory\n"); + uca_cam_alloc(cam, 20); uint16_t *buffer = (uint16_t *) malloc(width * height * 2); |