libfprint_rs/
image.rs

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