Skip to main content

apple_vision/ffi/
mod.rs

1//! Raw FFI declarations matching the Swift bridge in
2//! `swift-bridge/Sources/VisionBridge/Vision.swift`.
3
4#![allow(missing_docs, non_camel_case_types)]
5
6use core::ffi::{c_char, c_void};
7
8/// Mirrors `VNRecognizedTextRaw` in Vision.swift. Layout-compatible.
9#[repr(C)]
10pub struct RecognizedTextRaw {
11    pub text: *mut c_char,
12    pub confidence: f32,
13    pub bbox_x: f64,
14    pub bbox_y: f64,
15    pub bbox_w: f64,
16    pub bbox_h: f64,
17}
18
19/// Mirrors `VNDetectedFaceRaw` in Vision.swift. Layout-compatible.
20#[repr(C)]
21pub struct DetectedFaceRaw {
22    pub bbox_x: f64,
23    pub bbox_y: f64,
24    pub bbox_w: f64,
25    pub bbox_h: f64,
26    pub confidence: f32,
27    pub roll: f32,
28    pub yaw: f32,
29    pub pitch: f32,
30}
31
32/// Mirrors `VNDetectedBarcodeRaw` in Vision.swift. Layout-compatible.
33#[repr(C)]
34pub struct DetectedBarcodeRaw {
35    pub payload: *mut c_char,
36    pub symbology: *mut c_char,
37    pub confidence: f32,
38    pub bbox_x: f64,
39    pub bbox_y: f64,
40    pub bbox_w: f64,
41    pub bbox_h: f64,
42}
43
44extern "C" {
45    pub fn vn_string_free(s: *mut c_char);
46
47    pub fn vn_recognize_text_in_path(
48        path: *const c_char,
49        recognition_level: i32,
50        uses_language_correction: bool,
51        out_array: *mut *mut c_void,
52        out_count: *mut usize,
53        out_error_message: *mut *mut c_char,
54    ) -> i32;
55
56    pub fn vn_recognize_text_in_pixel_buffer(
57        pixel_buffer: *mut c_void,
58        recognition_level: i32,
59        uses_language_correction: bool,
60        out_array: *mut *mut c_void,
61        out_count: *mut usize,
62        out_error_message: *mut *mut c_char,
63    ) -> i32;
64
65    pub fn vn_recognized_text_free(array: *mut c_void, count: usize);
66
67    pub fn vn_detect_faces_in_path(
68        path: *const c_char,
69        out_array: *mut *mut c_void,
70        out_count: *mut usize,
71        out_error_message: *mut *mut c_char,
72    ) -> i32;
73
74    pub fn vn_detect_faces_in_pixel_buffer(
75        pixel_buffer: *mut c_void,
76        out_array: *mut *mut c_void,
77        out_count: *mut usize,
78        out_error_message: *mut *mut c_char,
79    ) -> i32;
80
81    pub fn vn_detected_faces_free(array: *mut c_void, count: usize);
82
83    pub fn vn_detect_barcodes_in_path(
84        path: *const c_char,
85        out_array: *mut *mut c_void,
86        out_count: *mut usize,
87        out_error_message: *mut *mut c_char,
88    ) -> i32;
89
90    pub fn vn_detected_barcodes_free(array: *mut c_void, count: usize);
91
92    pub fn vn_test_helper_render_text_png(
93        text: *const c_char,
94        width: i32,
95        height: i32,
96        output_path: *const c_char,
97    ) -> i32;
98}
99
100pub mod status {
101    pub const OK: i32 = 0;
102    pub const INVALID_ARGUMENT: i32 = -1;
103    pub const IMAGE_LOAD_FAILED: i32 = -2;
104    pub const REQUEST_FAILED: i32 = -3;
105    pub const UNKNOWN: i32 = -99;
106}
107
108// silence unused
109const _: () = {
110    let _ = core::mem::size_of::<*mut c_void>();
111};