diff options
author | Mihael Koep <koep@schneide.com> | 2012-10-25 17:47:14 +0200 |
---|---|---|
committer | Mihael Koep <koep@schneide.com> | 2012-10-25 17:47:14 +0200 |
commit | 620871c0c8e742af5f55ae9a2d6fe2066aa35193 (patch) | |
tree | 74e6c4568338d81c8074eb39139cdd5acc721fdc | |
parent | 9c6732c05f35bb06f92593b46990473aa7a0f799 (diff) | |
parent | f68bda1ebebcf589fdab832abfecf997b7f223a6 (diff) | |
download | uca-620871c0c8e742af5f55ae9a2d6fe2066aa35193.tar.gz uca-620871c0c8e742af5f55ae9a2d6fe2066aa35193.tar.bz2 uca-620871c0c8e742af5f55ae9a2d6fe2066aa35193.tar.xz uca-620871c0c8e742af5f55ae9a2d6fe2066aa35193.zip |
Merge remote branch 'origin/master' into dexela
-rw-r--r-- | plugins/ufo/uca-ufo-camera.c | 7 | ||||
-rw-r--r-- | src/uca-camera.c | 19 | ||||
-rw-r--r-- | tools/gui/control.c | 42 |
3 files changed, 53 insertions, 15 deletions
diff --git a/plugins/ufo/uca-ufo-camera.c b/plugins/ufo/uca-ufo-camera.c index 2b289a5..c4e05b0 100644 --- a/plugins/ufo/uca-ufo-camera.c +++ b/plugins/ufo/uca-ufo-camera.c @@ -28,7 +28,8 @@ if (err != 0) { \ g_set_error(error, UCA_UFO_CAMERA_ERROR, \ err_type, \ - "pcilib: %s", strerror(err)); \ + "%s:%i pcilib: %s (errcode = %d)", \ + __FILE__, __LINE__, strerror(err), err);\ return; \ } @@ -280,7 +281,7 @@ static void uca_ufo_camera_grab(UcaCamera *camera, gpointer *data, GError **erro UcaUfoCameraPrivate *priv = UCA_UFO_CAMERA_GET_PRIVATE(camera); pcilib_event_id_t event_id; pcilib_event_info_t event_info; - size_t err; + int err; const gsize size = SENSOR_WIDTH * SENSOR_HEIGHT * sizeof(guint16); @@ -295,7 +296,7 @@ static void uca_ufo_camera_grab(UcaCamera *camera, gpointer *data, GError **erro if (*data == NULL) *data = g_malloc0(SENSOR_WIDTH * SENSOR_HEIGHT * sizeof(guint16)); - gpointer src = pcilib_get_data(priv->handle, event_id, PCILIB_EVENT_DATA, &err); + gpointer src = pcilib_get_data(priv->handle, event_id, PCILIB_EVENT_DATA, (size_t *) &err); if (src == NULL) PCILIB_SET_ERROR(err, UCA_UFO_CAMERA_ERROR_NO_DATA); diff --git a/src/uca-camera.c b/src/uca-camera.c index 53b2d7a..8905a95 100644 --- a/src/uca-camera.c +++ b/src/uca-camera.c @@ -110,6 +110,7 @@ const gchar *uca_camera_props[N_BASE_PROPERTIES] = { }; static GParamSpec *camera_properties[N_BASE_PROPERTIES] = { NULL, }; +static GStaticMutex access_lock = G_STATIC_MUTEX_INIT; struct _UcaCameraPrivate { gboolean is_recording; @@ -457,7 +458,9 @@ uca_camera_start_recording (UcaCamera *camera, GError **error) goto start_recording_unlock; } + g_static_mutex_lock (&access_lock); (*klass->start_recording)(camera, &tmp_error); + g_static_mutex_unlock (&access_lock); if (tmp_error == NULL) { camera->priv->is_readout = FALSE; @@ -501,7 +504,9 @@ uca_camera_stop_recording (UcaCamera *camera, GError **error) else { GError *tmp_error = NULL; + g_static_mutex_lock (&access_lock); (*klass->stop_recording)(camera, &tmp_error); + g_static_mutex_unlock (&access_lock); if (tmp_error == NULL) { camera->priv->is_readout = FALSE; @@ -548,7 +553,9 @@ uca_camera_start_readout (UcaCamera *camera, GError **error) else { GError *tmp_error = NULL; + g_static_mutex_lock (&access_lock); (*klass->start_readout) (camera, &tmp_error); + g_static_mutex_unlock (&access_lock); if (tmp_error == NULL) { camera->priv->is_readout = TRUE; @@ -593,7 +600,9 @@ uca_camera_stop_readout (UcaCamera *camera, GError **error) else { GError *tmp_error = NULL; + g_static_mutex_lock (&access_lock); (*klass->stop_readout) (camera, &tmp_error); + g_static_mutex_unlock (&access_lock); if (tmp_error == NULL) { camera->priv->is_readout = FALSE; @@ -648,8 +657,11 @@ uca_camera_trigger (UcaCamera *camera, GError **error) if (!camera->priv->is_recording) g_set_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING, "Camera is not recording"); - else + else { + g_static_mutex_lock (&access_lock); (*klass->trigger) (camera, error); + g_static_mutex_unlock (&access_lock); + } g_static_mutex_unlock (&mutex); } @@ -690,8 +702,11 @@ uca_camera_grab (UcaCamera *camera, gpointer *data, GError **error) if (!camera->priv->is_recording && !camera->priv->is_readout) g_set_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING, "Camera is neither recording nor in readout mode"); - else + else { + g_static_mutex_lock (&access_lock); (*klass->grab) (camera, data, error); + g_static_mutex_unlock (&access_lock); + } g_static_mutex_unlock (&mutex); } diff --git a/tools/gui/control.c b/tools/gui/control.c index 877473e..f74e0f1 100644 --- a/tools/gui/control.c +++ b/tools/gui/control.c @@ -91,7 +91,8 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) gint offset = y * stride * data->width; for (gint x = 0; x < data->display_width; x++, offset += stride) { - guchar val = (guchar) ((input[offset] - min) * factor); + gdouble dval = (input[offset] - min) * factor; + guchar val = (guchar) CLAMP(dval, 0.0, 255.0); output[i++] = val; output[i++] = val; @@ -106,7 +107,8 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) gint offset = y * stride * data->width; for (gint x = 0; x < data->display_width; x++, offset += stride) { - guchar val = (guchar) ((input[offset] - min) * factor); + gdouble dval = (input[offset] - min) * factor; + guchar val = (guchar) CLAMP(dval, 0.0, 255.0); output[i++] = val; output[i++] = val; @@ -138,24 +140,38 @@ update_pixbuf_dimensions (ThreadData *data) gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); } +static void +print_and_free_error (GError **error) +{ + g_printerr ("%s\n", (*error)->message); + g_error_free (*error); + *error = NULL; +} + static gpointer preview_frames (void *args) { ThreadData *data = (ThreadData *) args; gint counter = 0; + GError *error = NULL;; while (data->state == RUNNING) { gpointer buffer; buffer = ring_buffer_get_current_pointer (data->buffer); - uca_camera_grab (data->camera, &buffer, NULL); - convert_grayscale_to_rgb (data, buffer); + uca_camera_grab (data->camera, &buffer, &error); - gdk_threads_enter (); - update_pixbuf (data); - gdk_threads_leave (); + if (error == NULL) { + convert_grayscale_to_rgb (data, buffer); + + gdk_threads_enter (); + update_pixbuf (data); + gdk_threads_leave (); - counter++; + counter++; + } + else + print_and_free_error (&error); } return NULL; } @@ -166,6 +182,7 @@ record_frames (gpointer args) ThreadData *data; gpointer buffer; guint n_frames = 0; + GError *error = NULL; data = (ThreadData *) args; ring_buffer_reset (data->buffer); @@ -173,8 +190,13 @@ record_frames (gpointer args) while (data->state == RECORDING) { buffer = ring_buffer_get_current_pointer (data->buffer); uca_camera_grab (data->camera, &buffer, NULL); - ring_buffer_proceed (data->buffer); - n_frames++; + + if (error == NULL) { + ring_buffer_proceed (data->buffer); + n_frames++; + } + else + print_and_free_error (&error); } n_frames = ring_buffer_get_num_blocks (data->buffer); |