Fix fp_get_pollfds()
[libfprint.git] / examples / img_capture.c
blob652803178c65f539a9013a02cacda794c263719c
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 = discovered_devs[0];
28 struct fp_driver *drv;
29 if (!ddev)
30 return NULL;
32 drv = fp_dscv_dev_get_driver(ddev);
33 printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
34 return ddev;
37 int main(void)
39 int r = 1;
40 struct fp_dscv_dev *ddev;
41 struct fp_dscv_dev **discovered_devs;
42 struct fp_dev *dev;
43 struct fp_img *img = NULL;
45 r = fp_init();
46 if (r < 0) {
47 fprintf(stderr, "Failed to initialize libfprint\n");
48 exit(1);
50 fp_set_debug(3);
52 discovered_devs = fp_discover_devs();
53 if (!discovered_devs) {
54 fprintf(stderr, "Could not discover devices\n");
55 goto out;
58 ddev = discover_device(discovered_devs);
59 if (!ddev) {
60 fprintf(stderr, "No devices detected.\n");
61 goto out;
64 dev = fp_dev_open(ddev);
65 fp_dscv_devs_free(discovered_devs);
66 if (!dev) {
67 fprintf(stderr, "Could not open device.\n");
68 goto out;
71 if (!fp_dev_supports_imaging(dev)) {
72 fprintf(stderr, "this device does not have imaging capabilities.\n");
73 goto out_close;
76 printf("Opened device. It's now time to scan your finger.\n\n");
78 r = fp_dev_img_capture(dev, 0, &img);
79 if (r) {
80 fprintf(stderr, "image capture failed, code %d\n", r);
81 goto out_close;
84 r = fp_img_save_to_file(img, "finger.pgm");
85 if (r) {
86 fprintf(stderr, "img save failed, code %d\n", r);
87 goto out_close;
90 fp_img_standardize(img);
91 r = fp_img_save_to_file(img, "finger_standardized.pgm");
92 fp_img_free(img);
93 if (r) {
94 fprintf(stderr, "standardized img save failed, code %d\n", r);
95 goto out_close;
98 r = 0;
99 out_close:
100 fp_dev_close(dev);
101 out:
102 fp_exit();
103 return r;