1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// All methods are declared
use glib::{
translate::{FromGlibContainer, FromGlibPtrFull, ToGlibPtr},
wrapper,
};
wrapper! {
#[cfg(not(doctest))]
/// Struct representing an image of a fingerprint. Not all devices support this feature.
/// # Examples:
/// ```rust
/// use libfprint_rs::FpContext;
/// use std::fs::File;
/// use std::io::Write;
///
/// let context = FpContext::new();
/// let devices = context.devices();
/// let device = devices.get(0).unwrap();
///
/// device.open_sync(None).unwrap();
/// let image = device.capture_sync(true, None).unwrap();
/// let data = image.data();
///
/// let mut file = File::create("image.pgm").unwrap();
/// let header = format!("P5\n{} {}\n255\n", image.width(), image.height());
/// file.write_all(header.as_bytes()).unwrap();
/// file.write_all(data.as_slice()).unwrap();
/// ```
pub struct FpImage(Object<libfprint_sys::FpImage, libfprint_sys::FpImageClass>);
match fn {
type_ => || libfprint_sys::fp_image_get_type() as usize,
}
}
impl FpImage {
pub fn new(width: u32, height: u32) -> Self {
unsafe { FpImage::from_glib_full(libfprint_sys::fp_image_new(width as i32, height as i32)) }
}
/// Gets the pixel width of an image.
pub fn width(&self) -> u32 {
unsafe { libfprint_sys::fp_image_get_width(self.to_glib_none().0) as u32 }
}
/// Gets the pixel height of an image.
pub fn height(&self) -> u32 {
unsafe { libfprint_sys::fp_image_get_height(self.to_glib_none().0) as u32 }
}
/// Gets the resolution of the image. Note that this is assumed to be fixed to 500 points per inch (~19.685 p/mm) for most drivers.
pub fn ppmm(&self) -> f64 {
unsafe { libfprint_sys::fp_image_get_ppmm(self.to_glib_none().0) }
}
fn _minutiae(&self) {
unimplemented!()
}
fn _detect_minutiae(&self) {
unimplemented!()
}
fn _detect_minutiae_finish(&self) {
unimplemented!()
}
/// Gets the greyscale data for an image.
pub fn data(&self) -> Vec<u8> {
unsafe {
let mut len = 0;
let data = libfprint_sys::fp_image_get_data(self.to_glib_none().0, &mut len);
Vec::from_glib_none_num(data, len as usize)
}
}
pub fn binarized(&self) -> Vec<u8> {
unsafe {
let mut len = 0;
let data = libfprint_sys::fp_image_get_binarized(self.to_glib_none().0, &mut len);
Vec::from_glib_none_num(data, len as usize)
}
}
}