vips/
region.rs

1use crate::VipsImage;
2use std::os::raw::c_void;
3
4/// VipsRegion struct wrapping libvips VipsRegion
5///
6/// # Example
7/// ```no_run
8/// use vips::*;
9///
10/// fn main() -> Result<()> {
11///     let _instance = VipsInstance::new("app_test", true)?;
12///     let img = VipsImage::from_file("examples/images/kodim01.png")?;
13///     let region = VipsRegion::new(&img);
14///     Ok(())
15/// }
16/// ```
17pub struct VipsRegion {
18    // The underlying C VipsRegion pointer
19    pub c: *mut vips_sys::VipsRegion,
20}
21
22impl VipsRegion {
23    /// Create a new VipsRegion for the given image
24    ///
25    /// # Arguments
26    /// * `image` - The VipsImage to create the region for
27    ///
28    /// # Example
29    /// ```no_run
30    /// use vips::*;
31    ///
32    /// fn main() -> Result<()> {
33    ///     let _instance = VipsInstance::new("app_test", true)?;
34    ///     let img = VipsImage::from_file("examples/images/kodim01.png")?;
35    ///     let region = VipsRegion::new(&img);
36    ///     Ok(())
37    /// }
38    /// ```
39    pub fn new(image: &VipsImage) -> VipsRegion {
40        let c = unsafe { vips_sys::vips_region_new(image.c) };
41        VipsRegion { c }
42    }
43}
44
45impl Drop for VipsRegion {
46    fn drop(&mut self) {
47        unsafe {
48            vips_sys::g_object_unref(self.c as *mut c_void);
49        }
50    }
51}