Support images with variable dimensions

For example, AES2501 returns images that vary in height.
This commit is contained in:
Daniel Drake 2007-11-08 13:56:21 +00:00
parent e1a25eeb67
commit b9238e8b8a
2 changed files with 36 additions and 15 deletions

View file

@ -176,6 +176,11 @@ int main(void)
img_width = fp_dev_get_img_width(dev); img_width = fp_dev_get_img_width(dev);
img_height = fp_dev_get_img_height(dev); img_height = fp_dev_get_img_height(dev);
if (img_width <= 0 || img_height <= 0) {
fprintf(stderr, "this device returns images with variable dimensions,"
" this example does not support that.\n");
goto out;
}
framebuffer = malloc(img_width * img_height * 2); framebuffer = malloc(img_width * img_height * 2);
if (!framebuffer) if (!framebuffer)
goto out; goto out;

View file

@ -73,13 +73,14 @@ int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev)
} }
int fpi_imgdev_capture(struct fp_img_dev *imgdev, int unconditional, int fpi_imgdev_capture(struct fp_img_dev *imgdev, int unconditional,
struct fp_img **image) struct fp_img **_img)
{ {
struct fp_driver *drv = imgdev->dev->drv; struct fp_driver *drv = imgdev->dev->drv;
struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv);
struct fp_img *img;
int r; int r;
if (!image) { if (!_img) {
fp_err("no image pointer given"); fp_err("no image pointer given");
return -EINVAL; return -EINVAL;
} }
@ -107,35 +108,50 @@ int fpi_imgdev_capture(struct fp_img_dev *imgdev, int unconditional,
} }
} }
r = imgdrv->capture(imgdev, unconditional, image); r = imgdrv->capture(imgdev, unconditional, &img);
if (r) { if (r) {
fp_err("capture failed with error %d", r); fp_err("capture failed with error %d", r);
return r; return r;
} }
if (img == NULL) {
fp_err("capture succeeded but no image returned?");
return -ENODATA;
}
if (!unconditional && imgdrv->await_finger_off) { if (!unconditional && imgdrv->await_finger_off) {
r = imgdrv->await_finger_off(imgdev); r = imgdrv->await_finger_off(imgdev);
if (r) { if (r) {
fp_err("await_finger_off failed with error %d", r); fp_err("await_finger_off failed with error %d", r);
fp_img_free(img);
return r; return r;
} }
} }
if (r == 0) { if (imgdrv->img_width > 0) {
struct fp_img *img = *image;
if (img == NULL) {
fp_err("capture succeeded but no image returned?");
return -ENODATA;
}
img->width = imgdrv->img_width; img->width = imgdrv->img_width;
img->height = imgdrv->img_height; } else if (img->width <= 0) {
if (!fpi_img_is_sane(img)) { fp_err("no image width assigned");
fp_err("image is not sane!"); goto err;
return -EIO;
}
} }
return r; if (imgdrv->img_height > 0) {
img->height = imgdrv->img_height;
} else if (img->height <= 0) {
fp_err("no image height assigned");
goto err;
}
if (!fpi_img_is_sane(img)) {
fp_err("image is not sane!");
goto err;
}
*_img = img;
return 0;
err:
fp_img_free(img);
return -EIO;
} }
#define MIN_ACCEPTABLE_MINUTIAE 10 #define MIN_ACCEPTABLE_MINUTIAE 10