use crate::core::OCRError;
use image::RgbImage;
pub(crate) fn ensure_non_empty_images(
images: &[RgbImage],
empty_batch_message: &str,
) -> Result<(), OCRError> {
ensure_images_with(images, empty_batch_message, |idx, width, height| {
format!(
"Invalid image dimensions for item {idx}: width={width}, height={height} must be positive. Please check your input image."
)
})
}
pub(crate) fn ensure_images_with(
images: &[RgbImage],
empty_batch_message: &str,
zero_dim_message: impl Fn(usize, u32, u32) -> String,
) -> Result<(), OCRError> {
if images.is_empty() {
return Err(OCRError::InvalidInput {
message: empty_batch_message.to_string(),
});
}
for (idx, img) in images.iter().enumerate() {
let (width, height) = (img.width(), img.height());
if width == 0 || height == 0 {
return Err(OCRError::InvalidInput {
message: zero_dim_message(idx, width, height),
});
}
}
Ok(())
}