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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::os::raw::c_void;
use crate::{
core::{_InputArray, _InputArrayTrait, _InputOutputArray, _InputOutputArrayTrait, _OutputArray, _OutputArrayTrait},
input_output_array,
Result,
sys,
traits::Boxed,
};
pub trait ToInputArray {
fn input_array(&self) -> Result<_InputArray>;
}
input_output_array! { f64, from_f64 }
pub trait ToOutputArray {
fn output_array(&mut self) -> Result<_OutputArray>;
}
pub trait ToInputOutputArray {
fn input_output_array(&mut self) -> Result<_InputOutputArray>;
}
impl<T: _InputArrayTrait> ToInputArray for T {
fn input_array(&self) -> Result<_InputArray> {
extern "C" { fn cv_InputArray_input_array(instance: *const c_void) -> sys::Result<*mut c_void>; }
unsafe { cv_InputArray_input_array(self.as_raw__InputArray()) }
.into_result()
.map(|ptr| unsafe { _InputArray::from_raw(ptr) })
}
}
impl<T: _OutputArrayTrait> ToOutputArray for T {
fn output_array(&mut self) -> Result<_OutputArray> {
extern "C" { fn cv_OutputArray_output_array(instance: *mut c_void) -> sys::Result<*mut c_void>; }
unsafe { cv_OutputArray_output_array(self.as_raw_mut__OutputArray()) }
.into_result()
.map(|ptr| unsafe { _OutputArray::from_raw(ptr) })
}
}
impl<T: _InputOutputArrayTrait> ToInputOutputArray for T {
fn input_output_array(&mut self) -> Result<_InputOutputArray> {
extern "C" { fn cv_InputOutputArray_input_output_array(instance: *mut c_void) -> sys::Result<*mut c_void>; }
unsafe { cv_InputOutputArray_input_output_array(self.as_raw_mut__InputOutputArray()) }
.into_result()
.map(|ptr| unsafe { _InputOutputArray::from_raw(ptr) })
}
}
#[macro_export]
macro_rules! input_output_array {
($type: ty, $const_cons: ident) => {
impl $crate::manual::core::ToInputArray for $type {
#[inline]
fn input_array(&self) -> $crate::Result<$crate::core::_InputArray> {
$crate::core::_InputArray::$const_cons(self)
}
}
$crate::input_array_ref_forward! { $type }
};
($type: ty, $const_cons: ident, $mut_cons: ident) => {
$crate::input_output_array! { $type, $const_cons }
impl $crate::manual::core::ToOutputArray for $type {
#[inline]
fn output_array(&mut self) -> $crate::Result<$crate::core::_OutputArray> {
$crate::core::_OutputArray::$mut_cons(self)
}
}
impl $crate::manual::core::ToInputOutputArray for $type {
#[inline]
fn input_output_array(&mut self) -> $crate::Result<$crate::core::_InputOutputArray> {
$crate::core::_InputOutputArray::$mut_cons(self)
}
}
$crate::output_array_ref_forward! { $type }
};
}
#[macro_export]
macro_rules! input_array_ref_forward {
($type: ty) => {
impl $crate::manual::core::ToInputArray for &$type {
#[inline]
fn input_array(&self) -> $crate::Result<$crate::core::_InputArray> {
(*self).input_array()
}
}
};
}
#[macro_export]
macro_rules! output_array_ref_forward {
($type: ty) => {
impl $crate::manual::core::ToOutputArray for &mut $type {
#[inline]
fn output_array(&mut self) -> $crate::Result<$crate::core::_OutputArray> {
(*self).output_array()
}
}
impl $crate::manual::core::ToInputOutputArray for &mut $type {
#[inline]
fn input_output_array(&mut self) -> $crate::Result<$crate::core::_InputOutputArray> {
(*self).input_output_array()
}
}
};
}
#[macro_export]
macro_rules! input_output_array_ref_forward {
($type: ty) => {
$crate::input_array_ref_forward! { $type }
$crate::output_array_ref_forward! { $type }
}
}