use image::RgbImage;
use crate::types::{OcrBackend, OcrLine};
#[cfg(all(target_os = "macos", feature = "native"))]
pub mod vision;
#[cfg(all(windows, feature = "native"))]
pub mod win_native;
pub const fn native_backend() -> Option<OcrBackend> {
if !cfg!(feature = "native") {
None
} else if cfg!(target_os = "macos") {
Some(OcrBackend::Vision)
} else if cfg!(windows) {
Some(OcrBackend::WindowsMedia)
} else {
None
}
}
pub fn recognize(img: &RgbImage) -> Result<Vec<OcrLine>, String> {
#[cfg(all(target_os = "macos", feature = "native"))]
{
vision::recognize(img)
}
#[cfg(all(windows, feature = "native"))]
{
win_native::recognize(img)
}
#[cfg(not(all(any(target_os = "macos", windows), feature = "native")))]
{
let _ = img;
Err(format!(
"{} no native OCR backend on this platform",
crate::types::OCR_UNSUPPORTED_PLATFORM
))
}
}
pub fn recognize_once(img: &RgbImage) -> Result<Vec<OcrLine>, String> {
#[cfg(all(target_os = "macos", feature = "native"))]
{
vision::recognize_once(img)
}
#[cfg(not(all(target_os = "macos", feature = "native")))]
{
recognize(img)
}
}
pub fn canary_png() -> &'static [u8] {
include_bytes!("assets/vision_canary.png")
}