summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2012-03-06 16:57:36 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2012-03-06 16:57:36 +0100
commiteae2ae49770bcbcdbac3997676c71820dd53fdcc (patch)
treef39b61f6ea2bd30620879595b0fa7c51093bc084 /src
parent09d05f26269799e643c171849f22d24c30836d00 (diff)
downloaduca-eae2ae49770bcbcdbac3997676c71820dd53fdcc.tar.gz
uca-eae2ae49770bcbcdbac3997676c71820dd53fdcc.tar.bz2
uca-eae2ae49770bcbcdbac3997676c71820dd53fdcc.tar.xz
uca-eae2ae49770bcbcdbac3997676c71820dd53fdcc.zip
Implement single frame grabbing
Diffstat (limited to 'src')
-rw-r--r--src/cameras/uca-mock-camera.c4
-rw-r--r--src/cameras/uca-pco-camera.c109
-rw-r--r--src/cameras/uca-pco-camera.h3
-rw-r--r--src/uca-camera.c55
-rw-r--r--src/uca-camera.h4
5 files changed, 152 insertions, 23 deletions
diff --git a/src/cameras/uca-mock-camera.c b/src/cameras/uca-mock-camera.c
index 9e74a01..0040e25 100644
--- a/src/cameras/uca-mock-camera.c
+++ b/src/cameras/uca-mock-camera.c
@@ -142,11 +142,11 @@ static void uca_mock_camera_stop_recording(UcaCamera *camera, GError **error)
}
}
-static void uca_mock_camera_grab(UcaCamera *camera, gpointer data, GError **error)
+static void uca_mock_camera_grab(UcaCamera *camera, gpointer *data, GError **error)
{
g_return_if_fail(UCA_IS_MOCK_CAMERA(camera));
UcaMockCameraPrivate *priv = UCA_MOCK_CAMERA_GET_PRIVATE(camera);
- g_memmove(data, priv->dummy_data, priv->width * priv->height);
+ g_memmove(*data, priv->dummy_data, priv->width * priv->height);
}
static void uca_mock_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
diff --git a/src/cameras/uca-pco-camera.c b/src/cameras/uca-pco-camera.c
index 3e1791a..83cdb68 100644
--- a/src/cameras/uca-pco-camera.c
+++ b/src/cameras/uca-pco-camera.c
@@ -16,6 +16,7 @@
Franklin St, Fifth Floor, Boston, MA 02110, USA */
#include <stdlib.h>
+#include <string.h>
#include <libpco/libpco.h>
#include <libpco/sc2_defs.h>
#include <fgrab_struct.h>
@@ -32,6 +33,22 @@
g_object_unref(camobj); \
return NULL; \
} }
+
+#define FG_SET_ERROR(err, fg, err_type) \
+ if (err != FG_OK) { \
+ g_set_error(error, UCA_PCO_CAMERA_ERROR, \
+ err_type, \
+ "%s", Fg_getLastErrorDescription(fg)); \
+ return; \
+ }
+
+#define HANDLE_PCO_ERROR(err) \
+ if ((err) != PCO_NOERROR) { \
+ g_set_error(error, UCA_PCO_CAMERA_ERROR, \
+ UCA_PCO_CAMERA_ERROR_LIBPCO_GENERAL,\
+ "libpco error %i", err); \
+ return; \
+ }
#define UCA_PCO_CAMERA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UCA_TYPE_PCO_CAMERA, UcaPcoCameraPrivate))
@@ -44,6 +61,7 @@ G_DEFINE_TYPE(UcaPcoCamera, uca_pco_camera, UCA_TYPE_CAMERA)
* @UCA_PCO_CAMERA_ERROR_UNSUPPORTED: Camera type is not supported
* @UCA_PCO_CAMERA_ERROR_FG_INIT: Framegrabber initialization failed
* @UCA_PCO_CAMERA_ERROR_FG_GENERAL: General framegrabber error
+ * @UCA_PCO_CAMERA_ERROR_FG_ACQUISITION: Framegrabber acquisition error
*/
GQuark uca_pco_camera_error_quark()
{
@@ -96,6 +114,24 @@ typedef struct {
gboolean has_camram;
} pco_cl_map_entry;
+struct _UcaPcoCameraPrivate {
+ pco_handle pco;
+ pco_cl_map_entry *camera_description;
+
+ Fg_Struct *fg;
+ guint fg_port;
+ dma_mem *fg_mem;
+
+ guint frame_width;
+ guint frame_height;
+ gsize num_bytes;
+
+ guint16 width;
+ guint16 height;
+ GValueArray *horizontal_binnings;
+ GValueArray *vertical_binnings;
+};
+
static pco_cl_map_entry pco_cl_map[] = {
{ CAMERATYPE_PCO_EDGE, "libFullAreaGray8.so", FG_CL_8BIT_FULL_10, FG_GRAY, 30.0f, FALSE },
{ CAMERATYPE_PCO4000, "libDualAreaGray16.so", FG_CL_SINGLETAP_16_BIT, FG_GRAY16, 5.0f, TRUE },
@@ -116,20 +152,6 @@ static pco_cl_map_entry *get_pco_cl_map_entry(int camera_type)
return NULL;
}
-struct _UcaPcoCameraPrivate {
- pco_handle pco;
- pco_cl_map_entry *camera_description;
-
- Fg_Struct *fg;
- guint fg_port;
- dma_mem *fg_mem;
-
- guint16 width;
- guint16 height;
- GValueArray *horizontal_binnings;
- GValueArray *vertical_binnings;
-};
-
static guint fill_binnings(UcaPcoCameraPrivate *priv)
{
uint16_t *horizontal = NULL;
@@ -250,18 +272,71 @@ UcaPcoCamera *uca_pco_camera_new(GError **error)
static void uca_pco_camera_start_recording(UcaCamera *camera, GError **error)
{
g_return_if_fail(UCA_IS_PCO_CAMERA(camera));
- pco_start_recording(UCA_PCO_CAMERA_GET_PRIVATE(camera)->pco);
+ guint err = PCO_NOERROR;
+
+ UcaPcoCameraPrivate *priv = UCA_PCO_CAMERA_GET_PRIVATE(camera);
+
+ /*
+ * Get the actual size of the frame that we are going to grab based on the
+ * currently selected region of interest. This size is fixed until recording
+ * has stopped.
+ */
+ guint16 roi[4] = {0};
+ err = pco_get_roi(priv->pco, roi);
+ priv->frame_width = roi[2] - roi[0];
+ priv->frame_height = roi[3] - roi[1];
+ priv->num_bytes = 2;
+
+ Fg_setParameter(priv->fg, FG_WIDTH, &priv->frame_width, priv->fg_port);
+ Fg_setParameter(priv->fg, FG_HEIGHT, &priv->frame_height, priv->fg_port);
+
+ if (priv->camera_description->camera_type == CAMERATYPE_PCO_DIMAX_STD)
+ pco_clear_active_segment(priv->pco);
+
+ err = pco_arm_camera(priv->pco);
+ HANDLE_PCO_ERROR(err);
+
+ err = pco_start_recording(priv->pco);
+ HANDLE_PCO_ERROR(err);
+
+ err = Fg_AcquireEx(priv->fg, 0, GRAB_INFINITE, ACQ_STANDARD, priv->fg_mem);
+ FG_SET_ERROR(err, priv->fg, UCA_PCO_CAMERA_ERROR_FG_ACQUISITION);
}
static void uca_pco_camera_stop_recording(UcaCamera *camera, GError **error)
{
g_return_if_fail(UCA_IS_PCO_CAMERA(camera));
- pco_stop_recording(UCA_PCO_CAMERA_GET_PRIVATE(camera)->pco);
+ UcaPcoCameraPrivate *priv = UCA_PCO_CAMERA_GET_PRIVATE(camera);
+ pco_stop_recording(priv->pco);
+ guint err = Fg_stopAcquireEx(priv->fg, 0, priv->fg_mem, STOP_SYNC);
+
+ FG_SET_ERROR(err, priv->fg, UCA_PCO_CAMERA_ERROR_FG_ACQUISITION);
}
-static void uca_pco_camera_grab(UcaCamera *camera, gpointer data, GError **error)
+static void uca_pco_camera_grab(UcaCamera *camera, gpointer *data, GError **error)
{
g_return_if_fail(UCA_IS_PCO_CAMERA(camera));
+ static frameindex_t last_frame = 0;
+ UcaPcoCameraPrivate *priv = UCA_PCO_CAMERA_GET_PRIVATE(camera);
+
+ pco_request_image(priv->pco);
+
+ last_frame = Fg_getLastPicNumberBlockingEx(priv->fg, last_frame+1, priv->fg_port, 5, priv->fg_mem);
+
+ if (last_frame <= 0) {
+ guint err = FG_OK + 1;
+ FG_SET_ERROR(err, priv->fg, UCA_PCO_CAMERA_ERROR_FG_GENERAL);
+ }
+
+ guint16 *frame = Fg_getImagePtrEx(priv->fg, last_frame, PORT_A, priv->fg_mem);
+
+ if (*data == NULL)
+ *data = g_malloc0(priv->frame_width * priv->frame_height * priv->num_bytes);
+
+ if (priv->camera_description->camera_type == CAMERATYPE_PCO_EDGE)
+ pco_get_reorder_func(priv->pco)((guint16 *) *data, frame, priv->frame_width, priv->frame_height);
+ else
+ memcpy((gchar *) *data, (gchar *) frame, priv->frame_width * priv->frame_height * priv->num_bytes);
}
static void uca_pco_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
diff --git a/src/cameras/uca-pco-camera.h b/src/cameras/uca-pco-camera.h
index 25009c0..c0b7bf4 100644
--- a/src/cameras/uca-pco-camera.h
+++ b/src/cameras/uca-pco-camera.h
@@ -34,7 +34,8 @@ typedef enum {
UCA_PCO_CAMERA_ERROR_LIBPCO_GENERAL,
UCA_PCO_CAMERA_ERROR_UNSUPPORTED,
UCA_PCO_CAMERA_ERROR_FG_INIT,
- UCA_PCO_CAMERA_ERROR_FG_GENERAL
+ UCA_PCO_CAMERA_ERROR_FG_GENERAL,
+ UCA_PCO_CAMERA_ERROR_FG_ACQUISITION
} UcaPcoCameraError;
typedef struct _UcaPcoCamera UcaPcoCamera;
diff --git a/src/uca-camera.c b/src/uca-camera.c
index 97215bb..2d2963b 100644
--- a/src/uca-camera.c
+++ b/src/uca-camera.c
@@ -67,6 +67,10 @@ enum {
PROP_SENSOR_VERTICAL_BINNING,
PROP_SENSOR_VERTICAL_BINNINGS,
PROP_SENSOR_MAX_FRAME_RATE,
+ PROP_ROI_X,
+ PROP_ROI_Y,
+ PROP_ROI_WIDTH,
+ PROP_ROI_HEIGHT,
PROP_HAS_STREAMING,
PROP_HAS_CAMRAM_RECORDING,
PROP_TRANSFER_ASYNCHRONOUSLY,
@@ -87,6 +91,11 @@ static void uca_camera_set_property(GObject *object, guint property_id, const GV
{
UcaCameraPrivate *priv = UCA_CAMERA_GET_PRIVATE(object);
+ if (priv->is_recording) {
+ g_warning("You cannot change properties during data acquisition");
+ return;
+ }
+
switch (property_id) {
case PROP_TRANSFER_ASYNCHRONOUSLY:
priv->transfer_async = g_value_get_boolean(value);
@@ -182,6 +191,34 @@ static void uca_camera_class_init(UcaCameraClass *klass)
1, G_MAXUINT, 1,
G_PARAM_READABLE), G_PARAM_READABLE);
+ camera_properties[PROP_ROI_X] =
+ g_param_spec_uint("roi-x",
+ "Horizontal coordinate",
+ "Horizontal coordinate",
+ 1, G_MAXUINT, 1,
+ G_PARAM_READABLE);
+
+ camera_properties[PROP_ROI_Y] =
+ g_param_spec_uint("roi-y",
+ "Vertical coordinate",
+ "Vertical coordinate",
+ 1, G_MAXUINT, 1,
+ G_PARAM_READABLE);
+
+ camera_properties[PROP_ROI_WIDTH] =
+ g_param_spec_uint("roi-width",
+ "Width",
+ "Width of the region of interest",
+ 1, G_MAXUINT, 1,
+ G_PARAM_READABLE);
+
+ camera_properties[PROP_ROI_HEIGHT] =
+ g_param_spec_uint("roi-height",
+ "Height",
+ "Height of the region of interest",
+ 1, G_MAXUINT, 1,
+ G_PARAM_READABLE);
+
camera_properties[PROP_SENSOR_MAX_FRAME_RATE] =
g_param_spec_float("max-frame-rate",
"Maximum frame rate",
@@ -377,6 +414,7 @@ void uca_camera_stop_recording(UcaCamera *camera, GError **error)
/**
* uca_camera_set_grab_func:
+ * @camera: A #UcaCamera object
* func: A #UcaCameraGrabFunc callback function
*
* Set the grab function that is called whenever a frame is readily transfered.
@@ -387,7 +425,21 @@ void uca_camera_set_grab_func(UcaCamera *camera, UcaCameraGrabFunc func, gpointe
camera->user_data = user_data;
}
-void uca_camera_grab(UcaCamera *camera, gpointer data, GError **error)
+/**
+ * uca_camera_grab:
+ * @camera: A #UcaCamera object
+ * @data: Pointer to pointer to the data. Must not be %NULL.
+ * @error: Location to store a #UcaCameraError error or %NULL
+ *
+ * Grab a frame a single frame and store the result in @data. If the pointer
+ * pointing to the data is %NULL, memory will be allocated otherwise it will be
+ * used to store the frame. If memory is allocated by uca_camera_grab() it must
+ * be freed by the caller.
+ *
+ * You must have called uca_camera_start_recording() before, otherwise you will
+ * get a #UCA_CAMERA_ERROR_NOT_RECORDING error.
+ */
+void uca_camera_grab(UcaCamera *camera, gpointer *data, GError **error)
{
g_return_if_fail(UCA_IS_CAMERA(camera));
@@ -395,6 +447,7 @@ void uca_camera_grab(UcaCamera *camera, gpointer data, GError **error)
g_return_if_fail(klass != NULL);
g_return_if_fail(klass->grab != NULL);
+ g_return_if_fail(data != NULL);
if (!camera->priv->is_recording) {
g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING,
diff --git a/src/uca-camera.h b/src/uca-camera.h
index a540d16..c10173b 100644
--- a/src/uca-camera.h
+++ b/src/uca-camera.h
@@ -71,7 +71,7 @@ struct _UcaCameraClass {
void (*start_recording) (UcaCamera *camera, GError **error);
void (*stop_recording) (UcaCamera *camera, GError **error);
- void (*grab) (UcaCamera *camera, gpointer data, GError **error);
+ void (*grab) (UcaCamera *camera, gpointer *data, GError **error);
void (*recording_started) (UcaCamera *camera);
void (*recording_stopped) (UcaCamera *camera);
@@ -82,7 +82,7 @@ UcaCamera *uca_camera_new(const gchar *type, GError **error);
void uca_camera_start_recording(UcaCamera *camera, GError **error);
void uca_camera_stop_recording(UcaCamera *camera, GError **error);
-void uca_camera_grab(UcaCamera *camera, gpointer data, GError **error);
+void uca_camera_grab(UcaCamera *camera, gpointer *data, GError **error);
void uca_camera_set_grab_func(UcaCamera *camera, UcaCameraGrabFunc func, gpointer user_data);
GType uca_camera_get_type(void);