1pub fn linear(inp: &VipsImage, a: &mut[f64], b: &mut[f64]) -> Result<VipsImage> {
10 unsafe {
11 if a.len() != b.len() {
12 return Err(Error::LinearError)
13 }
14 let inp_in: *mut bindings::VipsImage = inp.ctx;
15 let a_in: *mut f64 = a.as_mut_ptr();
16 let b_in: *mut f64 = b.as_mut_ptr();
17 let mut out_out: *mut bindings::VipsImage = null_mut();
18
19 let vips_op_response =
20 bindings::vips_linear(inp_in, &mut out_out, a_in, b_in, b.len() as i32, NULL);
21 utils::result(
22 vips_op_response,
23 VipsImage { ctx: out_out },
24 Error::LinearError,
25 )
26 }
27}
28
29pub struct LinearOptions {
31 pub uchar: bool,
34}
35
36impl std::default::Default for LinearOptions {
37 fn default() -> Self {
38 LinearOptions { uchar: false }
39 }
40}
41
42pub fn linear_with_opts(
49 inp: &VipsImage,
50 a: &mut [f64],
51 b: &mut [f64],
52 linear_options: &LinearOptions,
53) -> Result<VipsImage> {
54 unsafe {
55 if a.len() != b.len() {
56 return Err(Error::LinearError)
57 }
58 let inp_in: *mut bindings::VipsImage = inp.ctx;
59 let a_in: *mut f64 = a.as_mut_ptr();
60 let b_in: *mut f64 = b.as_mut_ptr();
61 let mut out_out: *mut bindings::VipsImage = null_mut();
62
63 let uchar_in: i32 = if linear_options.uchar { 1 } else { 0 };
64 let uchar_in_name = utils::new_c_string("uchar")?;
65
66 let vips_op_response = bindings::vips_linear(
67 inp_in,
68 &mut out_out,
69 a_in,
70 b_in,
71 b.len() as i32,
72 uchar_in_name.as_ptr(),
73 uchar_in,
74 NULL,
75 );
76 utils::result(
77 vips_op_response,
78 VipsImage { ctx: out_out },
79 Error::LinearError,
80 )
81 }
82}
83
84pub fn getpoint(inp: &VipsImage, x: i32, y: i32) -> Result<Vec<f64>> {
92 unsafe {
93 let inp_in: *mut bindings::VipsImage = inp.ctx;
94 let mut out_array_size: i32 = 0;
95 let mut out_array: *mut f64 = null_mut();
96
97 let vips_op_response = bindings::vips_getpoint(
98 inp_in,
99 &mut out_array,
100 &mut out_array_size,
101 x,
102 y,
103 NULL,
104 );
105 utils::result(
106 vips_op_response,
107 utils::new_double_array(out_array, out_array_size.try_into().unwrap()),
108 Error::GetpointError,
109 )
110 }
111}
112
113pub fn case(index: &VipsImage, cases: &mut [VipsImage], n: i32) -> Result<VipsImage> {
119 unsafe {
120 let index_in: *mut bindings::VipsImage = index.ctx;
121 let cases_in: *mut *mut bindings::VipsImage =
122 cases.iter().map(|v| v.ctx).collect::<Vec<_>>().as_mut_ptr();
123 let mut out_out: *mut bindings::VipsImage = null_mut();
124
125 let vips_op_response = bindings::vips_case(index_in, cases_in, &mut out_out, n, NULL);
126 utils::result(
127 vips_op_response,
128 VipsImage { ctx: out_out },
129 Error::CaseError,
130 )
131 }
132}