mod config;
mod engine;
mod result;
#[cfg(feature = "gui")]
mod controller;
pub use config::MatchConfig;
pub use engine::ImageMatcher;
pub use result::MatchResult;
#[cfg(feature = "gui")]
pub use controller::ImageMatchFeature;
use crate::error::Result;
use image::DynamicImage;
pub fn find_on_screen(
template: &DynamicImage,
config: Option<MatchConfig>,
) -> Result<Option<MatchResult>> {
let screen_capture = crate::screen::capture_screen()?;
let screen = image::load_from_memory(&screen_capture.image)
.map_err(|e| crate::error::AumateError::Other(format!("Failed to decode screen: {}", e)))?;
ImageMatcher::find(&screen, template, &config.unwrap_or_default())
}
pub fn find_all_on_screen(
template: &DynamicImage,
config: Option<MatchConfig>,
) -> Result<Vec<MatchResult>> {
let screen_capture = crate::screen::capture_screen()?;
let screen = image::load_from_memory(&screen_capture.image)
.map_err(|e| crate::error::AumateError::Other(format!("Failed to decode screen: {}", e)))?;
ImageMatcher::find_all(&screen, template, &config.unwrap_or_default())
}
pub fn find_in_region(
template: &DynamicImage,
x: u32,
y: u32,
width: u32,
height: u32,
config: Option<MatchConfig>,
) -> Result<Option<MatchResult>> {
let screen_capture =
crate::screen::capture_screen_region(Some(x), Some(y), Some(width), Some(height))?;
let screen = image::load_from_memory(&screen_capture.image)
.map_err(|e| crate::error::AumateError::Other(format!("Failed to decode screen: {}", e)))?;
let mut result = ImageMatcher::find(&screen, template, &config.unwrap_or_default())?;
if let Some(ref mut r) = result {
r.x += x;
r.y += y;
}
Ok(result)
}
pub fn find_all_in_region(
template: &DynamicImage,
x: u32,
y: u32,
width: u32,
height: u32,
config: Option<MatchConfig>,
) -> Result<Vec<MatchResult>> {
let screen_capture =
crate::screen::capture_screen_region(Some(x), Some(y), Some(width), Some(height))?;
let screen = image::load_from_memory(&screen_capture.image)
.map_err(|e| crate::error::AumateError::Other(format!("Failed to decode screen: {}", e)))?;
let mut results = ImageMatcher::find_all(&screen, template, &config.unwrap_or_default())?;
for r in &mut results {
r.x += x;
r.y += y;
}
Ok(results)
}