Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libfprint/fp-image-device-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct
FpImage *capture_image;

gint bz3_threshold;
FpiPrintType algorithm;
} FpImageDevicePrivate;


Expand Down
108 changes: 50 additions & 58 deletions libfprint/fp-image-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "fpi-print.h"
#define FP_COMPONENT "image_device"
#include "fpi-log.h"

Expand All @@ -32,23 +33,20 @@
* This is a helper class for the commonly found image based devices.
*/

G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (FpImageDevice, fp_image_device, FP_TYPE_DEVICE)
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (FpImageDevice, fp_image_device,
FP_TYPE_DEVICE)

enum {
PROP_0,
PROP_FPI_STATE,
N_PROPS
};
enum { PROP_0, PROP_FPI_STATE, N_PROPS };

static GParamSpec *properties[N_PROPS];
static GParamSpec * properties[N_PROPS];

enum {
FPI_STATE_CHANGED,

LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };
static guint signals[LAST_SIGNAL] = {0};

/*******************************************************/

Expand All @@ -58,30 +56,30 @@ static guint signals[LAST_SIGNAL] = { 0 };

/* Callbacks/vfuncs */
static void
fp_image_device_open (FpDevice *device)
fp_image_device_open (FpDevice * device)
{
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (device);
FpImageDeviceClass * cls = FP_IMAGE_DEVICE_GET_CLASS (device);

/* Nothing special about opening an image device, just
* forward the request. */
cls->img_open (FP_IMAGE_DEVICE (device));
}

static void
fp_image_device_close (FpDevice *device)
fp_image_device_close (FpDevice * device)
{
FpImageDevice *self = FP_IMAGE_DEVICE (device);
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self);
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpImageDevice * self = FP_IMAGE_DEVICE (device);
FpImageDeviceClass * cls = FP_IMAGE_DEVICE_GET_CLASS (self);
FpImageDevicePrivate * priv = fp_image_device_get_instance_private (self);

g_assert (priv->active == FALSE);
cls->img_close (self);
}

static void
fp_image_device_cancel_action (FpDevice *device)
fp_image_device_cancel_action (FpDevice * device)
{
FpImageDevice *self = FP_IMAGE_DEVICE (device);
FpImageDevice * self = FP_IMAGE_DEVICE (device);
FpiDeviceAction action;

action = fpi_device_get_current_action (device);
Expand All @@ -96,10 +94,10 @@ fp_image_device_cancel_action (FpDevice *device)
}

static void
fp_image_device_start_capture_action (FpDevice *device)
fp_image_device_start_capture_action (FpDevice * device)
{
FpImageDevice *self = FP_IMAGE_DEVICE (device);
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpImageDevice * self = FP_IMAGE_DEVICE (device);
FpImageDevicePrivate * priv = fp_image_device_get_instance_private (self);
FpiDeviceAction action;
FpiPrintType print_type;

Expand All @@ -116,18 +114,17 @@ fp_image_device_start_capture_action (FpDevice *device)

if (!wait_for_finger)
{
fpi_device_action_error (device, fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED));
fpi_device_action_error (
device, fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED));
return;
}
}
else if (action == FPI_DEVICE_ACTION_ENROLL)
{
FpPrint *enroll_print = NULL;
FpPrint * enroll_print = NULL;

fpi_device_get_enroll_data (device, &enroll_print);
g_object_get (enroll_print, "fpi-type", &print_type, NULL);
if (print_type != FPI_PRINT_NBIS)
fpi_print_set_type (enroll_print, FPI_PRINT_NBIS);
fpi_print_set_type (enroll_print, priv->algorithm);
}

priv->enroll_stage = 0;
Expand All @@ -140,40 +137,37 @@ fp_image_device_start_capture_action (FpDevice *device)
fpi_image_device_activate (self);
}


/*********************************************************/

static void
fp_image_device_finalize (GObject *object)
fp_image_device_finalize (GObject * object)
{
FpImageDevice *self = (FpImageDevice *) object;
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpImageDevice * self = (FpImageDevice *) object;
FpImageDevicePrivate * priv = fp_image_device_get_instance_private (self);

g_assert (priv->active == FALSE);

G_OBJECT_CLASS (fp_image_device_parent_class)->finalize (object);
}

static void
fp_image_device_default_activate (FpImageDevice *self)
fp_image_device_default_activate (FpImageDevice * self)
{
fpi_image_device_activate_complete (self, NULL);
}

static void
fp_image_device_default_deactivate (FpImageDevice *self)
fp_image_device_default_deactivate (FpImageDevice * self)
{
fpi_image_device_deactivate_complete (self, NULL);
}

static void
fp_image_device_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
fp_image_device_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
FpImageDevice *self = FP_IMAGE_DEVICE (object);
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpImageDevice * self = FP_IMAGE_DEVICE (object);
FpImageDevicePrivate * priv = fp_image_device_get_instance_private (self);

switch (prop_id)
{
Expand All @@ -187,25 +181,28 @@ fp_image_device_get_property (GObject *object,
}

static void
fp_image_device_constructed (GObject *obj)
fp_image_device_constructed (GObject * obj)
{
FpImageDevice *self = FP_IMAGE_DEVICE (obj);
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self);
FpImageDevice * self = FP_IMAGE_DEVICE (obj);
FpImageDevicePrivate * priv = fp_image_device_get_instance_private (self);
FpImageDeviceClass * cls = FP_IMAGE_DEVICE_GET_CLASS (self);

/* Set default threshold. */
priv->bz3_threshold = BOZORTH3_DEFAULT_THRESHOLD;
if (cls->bz3_threshold > 0)
priv->bz3_threshold = cls->bz3_threshold;
priv->algorithm = FPI_PRINT_NBIS;
if (cls->algorithm > 0)
priv->algorithm = cls->algorithm;

G_OBJECT_CLASS (fp_image_device_parent_class)->constructed (obj);
}

static void
fp_image_device_class_init (FpImageDeviceClass *klass)
fp_image_device_class_init (FpImageDeviceClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
FpDeviceClass *fp_device_class = FP_DEVICE_CLASS (klass);
GObjectClass * object_class = G_OBJECT_CLASS (klass);
FpDeviceClass * fp_device_class = FP_DEVICE_CLASS (klass);

object_class->finalize = fp_image_device_finalize;
object_class->get_property = fp_image_device_get_property;
Expand Down Expand Up @@ -237,13 +234,11 @@ fp_image_device_class_init (FpImageDeviceClass *klass)
*
* Stability: private
*/
properties[PROP_FPI_STATE] =
g_param_spec_enum ("fpi-image-device-state",
"Image Device State",
"Private: The state of the image device",
FPI_TYPE_IMAGE_DEVICE_STATE,
FPI_IMAGE_DEVICE_STATE_INACTIVE,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
properties[PROP_FPI_STATE] = g_param_spec_enum (
"fpi-image-device-state", "Image Device State",
"Private: The state of the image device", FPI_TYPE_IMAGE_DEVICE_STATE,
FPI_IMAGE_DEVICE_STATE_INACTIVE,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);

/**
* FpImageDevice::fpi-image-device-state-changed: (skip)
Expand All @@ -254,18 +249,15 @@ fp_image_device_class_init (FpImageDeviceClass *klass)
*
* Stability: private
*/
signals[FPI_STATE_CHANGED] =
g_signal_new ("fpi-image-device-state-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (FpImageDeviceClass, change_state),
NULL, NULL, NULL,
G_TYPE_NONE, 1, FPI_TYPE_IMAGE_DEVICE_STATE);
signals[FPI_STATE_CHANGED] = g_signal_new (
"fpi-image-device-state-changed", G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (FpImageDeviceClass, change_state),
NULL, NULL, NULL, G_TYPE_NONE, 1, FPI_TYPE_IMAGE_DEVICE_STATE);

g_object_class_install_properties (object_class, N_PROPS, properties);
}

static void
fp_image_device_init (FpImageDevice *self)
fp_image_device_init (FpImageDevice * self)
{
}
103 changes: 95 additions & 8 deletions libfprint/fp-image.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "sigfm/sigfm.hpp"
#define FP_COMPONENT "image"

#include "fpi-image.h"
Expand Down Expand Up @@ -158,15 +159,25 @@ fp_image_init (FpImage *self)

typedef struct
{
GAsyncReadyCallback user_cb;
struct fp_minutiae *minutiae;
gint width, height;
gdouble ppmm;
FpiImageFlags flags;
guchar *image;
guchar *binarized;
GAsyncReadyCallback user_cb;
struct fp_minutiae * minutiae;

gint width, height;
gdouble ppmm;
FpiImageFlags flags;
guchar *image;
guchar *binarized;
} DetectMinutiaeData;

typedef struct
{
SigfmImgInfo * sigfm_info;
guchar * image;
gint width;
gint height;
GAsyncReadyCallback user_cb;
} ExtractSigfmData;

static void
fp_image_detect_minutiae_free (DetectMinutiaeData *data)
{
Expand All @@ -176,6 +187,35 @@ fp_image_detect_minutiae_free (DetectMinutiaeData *data)
g_free (data);
}

static void
fp_image_sigfm_extract_free (ExtractSigfmData * data)
{
g_clear_pointer (&data->image, g_free);
g_clear_pointer (&data->sigfm_info, sigfm_free_info);
g_free (data);
}

static void
fp_image_sigfm_extract_cb (GObject * source_object, GAsyncResult * res,
gpointer user_data)
{
GTask * task = G_TASK (res);
FpImage * image;
ExtractSigfmData * data = g_task_get_task_data (task);

if (!g_task_had_error (task))
{
image = FP_IMAGE (source_object);

g_clear_pointer (&image->data, g_free);
image->data = g_steal_pointer (&data->image);
image->sigfm_info = g_steal_pointer (&data->sigfm_info);
}

if (data->user_cb)
data->user_cb (source_object, res, user_data);
}

static void
fp_image_detect_minutiae_cb (GObject *source_object,
GAsyncResult *res,
Expand All @@ -201,7 +241,6 @@ fp_image_detect_minutiae_cb (GObject *source_object,
g_clear_pointer (&image->minutiae, g_ptr_array_unref);
image->minutiae = g_ptr_array_new_full (data->minutiae->num,
(GDestroyNotify) free_minutia);

for (i = 0; i < data->minutiae->num; i++)
g_ptr_array_add (image->minutiae,
g_steal_pointer (&data->minutiae->list[i]));
Expand Down Expand Up @@ -263,6 +302,29 @@ invert_colors (guint8 *data, gint width, gint height)
data[i] = 0xff - data[i];
}

static void
fp_image_sigfm_extract_thread_func (GTask * task, void * src_obj,
void * task_data,
GCancellable * cancellable)
{
ExtractSigfmData * data = task_data;
GTimer * timer = g_timer_new ();

data->sigfm_info = sigfm_extract (data->image, data->width, data->height);
g_timer_stop (timer);
fp_dbg ("sigfm extract completed in %f secs", g_timer_elapsed (timer, NULL));
g_timer_destroy (timer);
if (sigfm_keypoints_count (data->sigfm_info) == 0)
{
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED,
"No keypoints found");
g_object_unref (task);
return;
}
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}

static void
fp_image_detect_minutiae_thread_func (GTask *task,
gpointer source_object,
Expand Down Expand Up @@ -428,6 +490,31 @@ fp_image_get_minutiae (FpImage *self)
return self->minutiae;
}

SigfmImgInfo *
fp_image_get_sigfm_info (FpImage * self)
{
return self->sigfm_info;
}

void
fp_image_extract_sigfm_info (FpImage * self, GCancellable * cancellable,
GAsyncReadyCallback callback, gpointer user_data)
{
GTask * task;
ExtractSigfmData * data = g_new0 (ExtractSigfmData, 1);

task = g_task_new (self, cancellable, fp_image_sigfm_extract_cb, user_data);

data->image = g_malloc (self->width * self->height);
memcpy (data->image, self->data, self->width * self->height);
data->width = self->width;
data->height = self->height;
data->user_cb = callback;

g_task_set_task_data (task, data,
(GDestroyNotify) fp_image_sigfm_extract_free);
g_task_run_in_thread (task, fp_image_sigfm_extract_thread_func);
}
/**
* fp_image_detect_minutiae:
* @self: A #FpImage
Expand Down
Loading