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
44/// Mirrors `VNSaliencyRegionRaw` in Vision.swift. Layout-compatible.
45#[repr(C)]
46pub struct SaliencyRegionRaw {
47    pub confidence: f32,
48    pub bbox_x: f64,
49    pub bbox_y: f64,
50    pub bbox_w: f64,
51    pub bbox_h: f64,
52}
53
54extern "C" {
55    pub fn vn_string_free(s: *mut c_char);
56
57    pub fn vn_recognize_text_in_path(
58        path: *const c_char,
59        recognition_level: i32,
60        uses_language_correction: bool,
61        out_array: *mut *mut c_void,
62        out_count: *mut usize,
63        out_error_message: *mut *mut c_char,
64    ) -> i32;
65
66    pub fn vn_recognize_text_in_pixel_buffer(
67        pixel_buffer: *mut c_void,
68        recognition_level: i32,
69        uses_language_correction: bool,
70        out_array: *mut *mut c_void,
71        out_count: *mut usize,
72        out_error_message: *mut *mut c_char,
73    ) -> i32;
74
75    pub fn vn_recognized_text_free(array: *mut c_void, count: usize);
76
77    pub fn vn_detect_faces_in_path(
78        path: *const c_char,
79        out_array: *mut *mut c_void,
80        out_count: *mut usize,
81        out_error_message: *mut *mut c_char,
82    ) -> i32;
83
84    pub fn vn_detect_faces_in_pixel_buffer(
85        pixel_buffer: *mut c_void,
86        out_array: *mut *mut c_void,
87        out_count: *mut usize,
88        out_error_message: *mut *mut c_char,
89    ) -> i32;
90
91    pub fn vn_detected_faces_free(array: *mut c_void, count: usize);
92
93    pub fn vn_detect_barcodes_in_path(
94        path: *const c_char,
95        out_array: *mut *mut c_void,
96        out_count: *mut usize,
97        out_error_message: *mut *mut c_char,
98    ) -> i32;
99
100    pub fn vn_detected_barcodes_free(array: *mut c_void, count: usize);
101
102    pub fn vn_attention_saliency_in_path(
103        path: *const c_char,
104        out_array: *mut *mut c_void,
105        out_count: *mut usize,
106        out_error_message: *mut *mut c_char,
107    ) -> i32;
108
109    pub fn vn_saliency_regions_free(array: *mut c_void, count: usize);
110
111    pub fn vn_test_helper_render_text_png(
112        text: *const c_char,
113        width: i32,
114        height: i32,
115        output_path: *const c_char,
116    ) -> i32;
117}
118
119pub mod status {
120    pub const OK: i32 = 0;
121    pub const INVALID_ARGUMENT: i32 = -1;
122    pub const IMAGE_LOAD_FAILED: i32 = -2;
123    pub const REQUEST_FAILED: i32 = -3;
124    pub const UNKNOWN: i32 = -99;
125}
126
127// silence unused
128const _: () = {
129    let _ = core::mem::size_of::<*mut c_void>();
130};