Skip to content

Commit 4666568

Browse files
committed
Improve Input/Output array handling and Mat constructors with data
1 parent f630cc5 commit 4666568

File tree

20 files changed

+641
-240
lines changed

20 files changed

+641
-240
lines changed

binding-generator/src/func.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
445445
if let Some(return_hint) = settings::RETURN_OVERRIDE.get(&self.func_id()) {
446446
out.set_type_hint(return_hint.clone());
447447
// if we're returning a BoxedRef then assign its mutability to the mutability of the borrowed argument
448-
if let Some((borrow_arg_name, _)) = return_hint.as_boxed_as_ref() {
448+
if let Some((_, borrow_arg_name, _)) = return_hint.as_boxed_as_ref() {
449449
let borrow_arg_constness = if borrow_arg_name == ARG_OVERRIDE_SELF {
450450
self.constness()
451451
} else {
@@ -712,7 +712,7 @@ impl<'me> NameDebug<'me> for &'me Func<'_, '_> {
712712
.iter()
713713
.map(|a| format!("{:?}", a.type_ref().render_lane()))
714714
.join(", ");
715-
format!("// {name}({render_lanes}) {func_id:?} {location}", func_id = self.func_id())
715+
format!("// {name}({render_lanes}) {func_id} {location}", func_id = self.func_id())
716716
} else {
717717
"".to_string()
718718
}

binding-generator/src/settings/argument_override.rs

Lines changed: 132 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashMap;
22

33
use once_cell::sync::Lazy;
44

5+
use crate::type_ref::Constness::{Const, Mut};
56
use crate::type_ref::TypeRefTypeHint;
67
use crate::writer::rust_native::type_ref::Lifetime;
78
use crate::FuncId;
@@ -144,6 +145,10 @@ pub static ARGUMENT_OVERRIDE: Lazy<HashMap<FuncId, HashMap<&str, TypeRefTypeHint
144145
FuncId::new_const("cv::MatConstIterator::pos", ["_idx"]),
145146
HashMap::from([("_idx", TypeRefTypeHint::PrimitivePtrAsRaw)]),
146147
),
148+
(
149+
FuncId::new_mut("cv::MatSize::MatSize", ["_p"]),
150+
HashMap::from([("_p", TypeRefTypeHint::PrimitivePtrAsRaw)]),
151+
),
147152
])
148153
});
149154

@@ -154,194 +159,274 @@ pub static RETURN_OVERRIDE: Lazy<HashMap<FuncId, TypeRefTypeHint>> = Lazy::new(|
154159
// Mat
155160
(
156161
FuncId::new_mut("cv::Mat::Mat", ["m"]),
157-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Elided),
162+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Elided),
158163
),
159164
(
160165
FuncId::new_mut("cv::Mat::Mat", ["m", "roi"]),
161-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Elided),
166+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Elided),
162167
),
163168
(
164169
FuncId::new_mut("cv::Mat::Mat", ["m", "ranges"]),
165-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Custom("boxed")),
170+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Custom("boxed")),
166171
),
167172
(
168173
FuncId::new_mut("cv::Mat::Mat", ["m", "rowRange", "colRange"]),
169-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Custom("boxed")),
174+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Custom("boxed")),
170175
),
171176
(
172177
FuncId::new_const("cv::Mat::reshape", ["cn", "rows"]),
173-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
178+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
174179
),
175180
(
176181
FuncId::new_const("cv::Mat::reshape", ["cn", "newndims", "newsz"]),
177-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
182+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
178183
),
179184
(
180185
FuncId::new_const("cv::Mat::reshape", ["cn", "newshape"]),
181-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
186+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
182187
),
183188
(
184189
FuncId::new_const("cv::Mat::row", ["y"]),
185-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
190+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
186191
),
187192
(
188193
FuncId::new_const("cv::Mat::col", ["x"]),
189-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
194+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
190195
),
191196
(
192197
FuncId::new_const("cv::Mat::rowRange", ["startrow", "endrow"]),
193-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
198+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
194199
),
195200
(
196201
FuncId::new_const("cv::Mat::rowRange", ["r"]),
197-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
202+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
198203
),
199204
(
200205
FuncId::new_const("cv::Mat::colRange", ["startcol", "endcol"]),
201-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
206+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
202207
),
203208
(
204209
FuncId::new_const("cv::Mat::colRange", ["r"]),
205-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
210+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
206211
),
207212
(
208213
FuncId::new_const("cv::Mat::diag", ["d"]),
209-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
214+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
210215
),
211216
(
212217
FuncId::new_const("cv::Mat::operator()", ["roi"]),
213-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
218+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
214219
),
215220
(
216221
FuncId::new_const("cv::Mat::operator()", ["rowRange", "colRange"]),
217-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
222+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
218223
),
219224
(
220225
FuncId::new_const("cv::Mat::operator()", ["ranges"]),
221-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
226+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
222227
),
223228
// GpuMatND
224229
(
225230
FuncId::new_const("cv::cuda::GpuMatND::createGpuMatHeader", ["idx", "rowRange", "colRange"]),
226-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
231+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
227232
),
228233
(
229234
FuncId::new_const("cv::cuda::GpuMatND::createGpuMatHeader", []),
230-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
235+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
231236
),
232237
(
233238
FuncId::new_const("cv::cuda::GpuMatND::operator()", ["idx", "rowRange", "colRange"]),
234-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
239+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
235240
),
236241
(
237242
FuncId::new_const("cv::cuda::GpuMatND::operator()", ["ranges"]),
238-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
243+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
239244
),
240245
// GpuMat
241246
(
242247
FuncId::new_mut("cv::cuda::GpuMat::GpuMat", ["m", "rowRange", "colRange"]),
243-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Elided),
248+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Elided),
244249
),
245250
(
246251
FuncId::new_mut("cv::cuda::GpuMat::GpuMat", ["m", "roi"]),
247-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Elided),
252+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Elided),
248253
),
249254
(
250255
FuncId::new_const("cv::cuda::GpuMat::row", ["y"]),
251-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
256+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
252257
),
253258
(
254259
FuncId::new_const("cv::cuda::GpuMat::col", ["x"]),
255-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
260+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
256261
),
257262
(
258263
FuncId::new_const("cv::cuda::GpuMat::rowRange", ["startrow", "endrow"]),
259-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
264+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
260265
),
261266
(
262267
FuncId::new_const("cv::cuda::GpuMat::rowRange", ["r"]),
263-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
268+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
264269
),
265270
(
266271
FuncId::new_const("cv::cuda::GpuMat::colRange", ["startcol", "endcol"]),
267-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
272+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
268273
),
269274
(
270275
FuncId::new_const("cv::cuda::GpuMat::colRange", ["r"]),
271-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
276+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
272277
),
273278
(
274279
FuncId::new_const("cv::cuda::GpuMat::reshape", ["cn", "rows"]),
275-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
280+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
276281
),
277282
(
278283
FuncId::new_const("cv::cuda::GpuMat::operator()", ["rowRange", "colRange"]),
279-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
284+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
280285
),
281286
(
282287
FuncId::new_const("cv::cuda::GpuMat::operator()", ["roi"]),
283-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
288+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
284289
),
285290
// UMat
286291
(
287292
FuncId::new_mut("cv::UMat::UMat", ["m", "rowRange", "colRange"]),
288-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Custom("boxed")),
293+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Custom("boxed")),
289294
),
290295
(
291296
FuncId::new_mut("cv::UMat::UMat", ["m", "roi"]),
292-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Elided),
297+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Elided),
293298
),
294299
(
295300
FuncId::new_mut("cv::UMat::UMat", ["m", "ranges"]),
296-
TypeRefTypeHint::BoxedAsRef("m", Lifetime::Custom("boxed")),
301+
TypeRefTypeHint::BoxedAsRef(Mut, "m", Lifetime::Custom("boxed")),
297302
),
298303
(
299304
FuncId::new_const("cv::UMat::row", ["y"]),
300-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
305+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
301306
),
302307
(
303308
FuncId::new_const("cv::UMat::col", ["x"]),
304-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
309+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
305310
),
306311
(
307312
FuncId::new_const("cv::UMat::rowRange", ["startrow", "endrow"]),
308-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
313+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
309314
),
310315
(
311316
FuncId::new_const("cv::UMat::rowRange", ["r"]),
312-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
317+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
313318
),
314319
(
315320
FuncId::new_const("cv::UMat::colRange", ["startcol", "endcol"]),
316-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
321+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
317322
),
318323
(
319324
FuncId::new_const("cv::UMat::colRange", ["r"]),
320-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
325+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
321326
),
322327
(
323328
FuncId::new_const("cv::UMat::diag", ["d"]),
324-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
329+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
325330
),
326331
(
327332
FuncId::new_const("cv::UMat::reshape", ["cn", "rows"]),
328-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
333+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
329334
),
330335
(
331336
FuncId::new_const("cv::UMat::reshape", ["cn", "newndims", "newsz"]),
332-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
337+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
333338
),
334339
(
335340
FuncId::new_const("cv::UMat::operator()", ["rowRange", "colRange"]),
336-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
341+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
337342
),
338343
(
339344
FuncId::new_const("cv::UMat::operator()", ["roi"]),
340-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
345+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
341346
),
342347
(
343348
FuncId::new_const("cv::UMat::operator()", ["ranges"]),
344-
TypeRefTypeHint::BoxedAsRef(ARG_OVERRIDE_SELF, Lifetime::Elided),
349+
TypeRefTypeHint::BoxedAsRef(Mut, ARG_OVERRIDE_SELF, Lifetime::Elided),
350+
),
351+
(
352+
FuncId::new_mut("cv::_InputArray::_InputArray", ["m"]),
353+
TypeRefTypeHint::BoxedAsRef(Const, "m", Lifetime::Elided),
354+
),
355+
(
356+
FuncId::new_mut("cv::_InputArray::_InputArray", ["expr"]),
357+
TypeRefTypeHint::BoxedAsRef(Const, "expr", Lifetime::Elided),
358+
),
359+
(
360+
FuncId::new_mut("cv::_InputArray::_InputArray", ["vec"]),
361+
TypeRefTypeHint::BoxedAsRef(Const, "vec", Lifetime::Elided),
362+
),
363+
(
364+
FuncId::new_mut("cv::_InputArray::_InputArray", ["val"]),
365+
TypeRefTypeHint::BoxedAsRef(Const, "val", Lifetime::Elided),
366+
),
367+
(
368+
FuncId::new_mut("cv::_InputArray::_InputArray", ["d_mat"]),
369+
TypeRefTypeHint::BoxedAsRef(Const, "d_mat", Lifetime::Elided),
370+
),
371+
(
372+
FuncId::new_mut("cv::_InputArray::_InputArray", ["d_mat_array"]),
373+
TypeRefTypeHint::BoxedAsRef(Const, "d_mat_array", Lifetime::Elided),
374+
),
375+
(
376+
FuncId::new_mut("cv::_InputArray::_InputArray", ["buf"]),
377+
TypeRefTypeHint::BoxedAsRef(Const, "buf", Lifetime::Elided),
378+
),
379+
(
380+
FuncId::new_mut("cv::_InputArray::_InputArray", ["cuda_mem"]),
381+
TypeRefTypeHint::BoxedAsRef(Const, "cuda_mem", Lifetime::Elided),
382+
),
383+
(
384+
FuncId::new_mut("cv::_InputArray::_InputArray", ["um"]),
385+
TypeRefTypeHint::BoxedAsRef(Const, "um", Lifetime::Elided),
386+
),
387+
(
388+
FuncId::new_mut("cv::_InputArray::_InputArray", ["umv"]),
389+
TypeRefTypeHint::BoxedAsRef(Const, "umv", Lifetime::Elided),
390+
),
391+
(
392+
FuncId::new_mut("cv::_OutputArray::_OutputArray", ["m"]),
393+
TypeRefTypeHint::BoxedAsRef(Const, "m", Lifetime::Elided),
394+
),
395+
(
396+
FuncId::new_mut("cv::_OutputArray::_OutputArray", ["vec"]),
397+
TypeRefTypeHint::BoxedAsRef(Const, "vec", Lifetime::Elided),
398+
),
399+
(
400+
FuncId::new_mut("cv::_OutputArray::_OutputArray", ["d_mat"]),
401+
TypeRefTypeHint::BoxedAsRef(Const, "d_mat", Lifetime::Elided),
402+
),
403+
(
404+
FuncId::new_mut("cv::_OutputArray::_OutputArray", ["buf"]),
405+
TypeRefTypeHint::BoxedAsRef(Const, "buf", Lifetime::Elided),
406+
),
407+
(
408+
FuncId::new_mut("cv::_OutputArray::_OutputArray", ["cuda_mem"]),
409+
TypeRefTypeHint::BoxedAsRef(Const, "cuda_mem", Lifetime::Elided),
410+
),
411+
(
412+
FuncId::new_mut("cv::_InputOutputArray::_InputOutputArray", ["m"]),
413+
TypeRefTypeHint::BoxedAsRef(Const, "m", Lifetime::Elided),
414+
),
415+
(
416+
FuncId::new_mut("cv::_InputOutputArray::_InputOutputArray", ["vec"]),
417+
TypeRefTypeHint::BoxedAsRef(Const, "vec", Lifetime::Elided),
418+
),
419+
(
420+
FuncId::new_mut("cv::_InputOutputArray::_InputOutputArray", ["d_mat"]),
421+
TypeRefTypeHint::BoxedAsRef(Const, "d_mat", Lifetime::Elided),
422+
),
423+
(
424+
FuncId::new_mut("cv::_InputOutputArray::_InputOutputArray", ["buf"]),
425+
TypeRefTypeHint::BoxedAsRef(Const, "buf", Lifetime::Elided),
426+
),
427+
(
428+
FuncId::new_mut("cv::_InputOutputArray::_InputOutputArray", ["cuda_mem"]),
429+
TypeRefTypeHint::BoxedAsRef(Const, "cuda_mem", Lifetime::Elided),
345430
),
346431
(
347432
FuncId::new_mut("cv::QRCodeDetector::decode", ["img", "points", "straight_qrcode"]),

0 commit comments

Comments
 (0)