Add AES2501 driver
[libfprint.git] / examples / img_capture.c
blobea494c89b05dfb382ee9c20eb3a6fcf838b53fe5
1 /*
2 * Example libfprint image capture program
3 * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <stdio.h>
21 #include <stdlib.h>
23 #include <libfprint/fprint.h>
25 struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
27 struct fp_dscv_dev *ddev = NULL;
28 int i;
30 for (i = 0; ddev = discovered_devs[i]; i++) {
31 struct fp_driver *drv = fp_dscv_dev_get_driver(ddev);
32 printf("Found device claimed by %s driver\n",
33 fp_driver_get_full_name(drv));
34 return ddev;
37 return ddev;
40 int main(void)
42 int r = 1;
43 struct fp_dscv_dev *ddev;
44 struct fp_dscv_dev **discovered_devs;
45 struct fp_dev *dev;
46 struct fp_img *img = NULL;
48 r = fp_init();
49 if (r < 0) {
50 fprintf(stderr, "Failed to initialize libfprint\n");
51 exit(1);
54 discovered_devs = fp_discover_devs();
55 if (!discovered_devs) {
56 fprintf(stderr, "Could not discover devices\n");
57 goto out;
60 ddev = discover_device(discovered_devs);
61 if (!ddev) {
62 fprintf(stderr, "No devices detected.\n");
63 goto out;
66 dev = fp_dev_open(ddev);
67 fp_dscv_devs_free(discovered_devs);
68 if (!dev) {
69 fprintf(stderr, "Could not open device.\n");
70 goto out;
73 if (!fp_dev_supports_imaging(dev)) {
74 fprintf(stderr, "this device does not have imaging capabilities.\n");
75 goto out_close;
78 printf("Opened device. It's now time to scan your finger.\n\n");
80 r = fp_dev_img_capture(dev, 0, &img);
81 if (r) {
82 fprintf(stderr, "image capture failed, code %d\n", r);
83 goto out_close;
86 r = fp_img_save_to_file(img, "finger.pgm");
87 if (r) {
88 fprintf(stderr, "img save failed, code %d\n", r);
89 goto out_close;
92 fp_img_standardize(img);
93 r = fp_img_save_to_file(img, "finger_standardized.pgm");
94 fp_img_free(img);
95 if (r) {
96 fprintf(stderr, "standardized img save failed, code %d\n", r);
97 goto out_close;
100 r = 0;
101 out_close:
102 fp_dev_close(dev);
103 out:
104 fp_exit();
105 return r;