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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use region::VipsRegion;
use ffi;
use std::error::Error;
use std::ffi::CString;
use common::current_error;
use std::os::raw::c_void;
pub struct VipsInterpolate {
pub c: *mut ffi::VipsInterpolate,
is_static: bool,
}
impl<'a> Drop for VipsInterpolate {
fn drop(&mut self) {
if !self.is_static {
unsafe {
ffi::g_object_unref(self.c as *mut c_void);
}
}
}
}
impl VipsInterpolate {
pub fn new(nickname: &str) -> Result<VipsInterpolate, Box<Error>> {
let nickname = CString::new(nickname)?;
let c = unsafe { ffi::vips_interpolate_new(nickname.as_ptr()) };
if c.is_null() {
Err(current_error().into())
} else {
Ok(VipsInterpolate { c, is_static:false })
}
}
pub fn nearest_static() -> VipsInterpolate {
let c = unsafe { ffi::vips_interpolate_nearest_static() };
VipsInterpolate {c, is_static:true}
}
pub fn bilinear_static() -> VipsInterpolate {
let c = unsafe { ffi::vips_interpolate_bilinear_static() };
VipsInterpolate {c, is_static:true}
}
pub fn method(&self) -> VipsInterpolateMethod {
let c = unsafe {
ffi::vips_interpolate_get_method(
self.c
)
};
VipsInterpolateMethod { c }
}
pub fn window_size(&self) -> i32 {
unsafe {
ffi::vips_interpolate_get_window_size(
self.c
)
}
}
pub fn window_offset(&self) -> i32 {
unsafe {
ffi::vips_interpolate_get_window_offset(
self.c
)
}
}
}
pub struct VipsInterpolateMethod {
c: ffi::VipsInterpolateMethod
}
impl VipsInterpolateMethod {
pub fn call(&self, interpolate:&VipsInterpolate, in_: &VipsRegion, out: &mut[u8], x:f64, y:f64){
unsafe { self.c.unwrap()(
interpolate.c,
out.as_ptr() as *mut c_void,
in_.c,
x,
y
) }
}
}