/* check image properties and resize it if necessary. potentially returns a new * image after freeing the old one. */ static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img) { struct fp_driver *drv = imgdev->dev->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); struct fp_img *img = *_img; if (imgdrv->img_width > 0) { img->width = imgdrv->img_width; } else if (img->width <= 0) { fp_err("no image width assigned"); return -EINVAL; } if (imgdrv->img_height > 0) { img->height = imgdrv->img_height; } else if (img->height <= 0) { fp_err("no image height assigned"); return -EINVAL; } if (!fpi_img_is_sane(img)) { fp_err("image is not sane!"); return -EINVAL; } return 0; }
static int img_dev_open(struct fp_dev *dev, unsigned long driver_data) { struct fp_img_dev *imgdev = g_malloc0(sizeof(*imgdev)); struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(dev->drv); int r = 0; imgdev->dev = dev; dev->priv = imgdev; dev->nr_enroll_stages = 1; /* for consistency in driver code, allow udev access through imgdev */ imgdev->udev = dev->udev; if (imgdrv->open) { r = imgdrv->open(imgdev, driver_data); if (r) goto err; } else { fpi_drvcb_open_complete(dev, 0); } return 0; err: g_free(imgdev); return r; }
static void dev_deactivate(struct fp_img_dev *imgdev) { struct fp_driver *drv = imgdev->dev->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); if (!imgdrv->activate) return; return imgdrv->deactivate(imgdev); }
static int dev_activate(struct fp_img_dev *imgdev, enum fp_imgdev_state state) { struct fp_driver *drv = imgdev->dev->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); if (!imgdrv->activate) return 0; return imgdrv->activate(imgdev, state); }
static void img_dev_close(struct fp_dev *dev) { struct fp_img_dev *imgdev = dev->priv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(dev->drv); if (imgdrv->close) imgdrv->close(imgdev); else fpi_drvcb_close_complete(dev); }
struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev) { struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); int width = imgdrv->img_width; int height = imgdrv->img_height; struct fp_img *img = fpi_img_new(width * height); img->width = width; img->height = height; return img; }
int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev) { struct fp_driver *drv = imgdev->dev->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); int height = imgdrv->img_height; if (height == -1) height = 0; return height; }
int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev) { struct fp_driver *drv = imgdev->dev->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); int width = imgdrv->img_width; if (width == -1) width = 0; return width; }
static void identify_process_img(struct fp_img_dev *imgdev) { struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); int match_score = imgdrv->bz3_threshold; size_t match_offset; int r; if (match_score == 0) match_score = BOZORTH3_DEFAULT_THRESHOLD; r = fpi_img_compare_print_data_to_gallery(imgdev->acquire_data, imgdev->dev->identify_gallery, match_score, &match_offset); imgdev->action_result = r; imgdev->identify_match_offset = match_offset; }
static void verify_process_img(struct fp_img_dev *imgdev) { struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); int match_score = imgdrv->bz3_threshold; int r; if (match_score == 0) match_score = BOZORTH3_DEFAULT_THRESHOLD; r = fpi_img_compare_print_data(imgdev->dev->verify_data, imgdev->acquire_data); if (r >= match_score) r = FP_VERIFY_MATCH; else if (r >= 0) r = FP_VERIFY_NO_MATCH; imgdev->action_result = r; }