mod pixels;
mod utils;
pub use image::{GrayImage, Luma};
pub use pixels::{luma_a_to_luma, luma_a_to_luma_convertor};
pub use utils::{dump_images, DumpError};
use crate::content::Area;
use image::{ImageBuffer, Pixel};
pub trait ImageSize {
fn width(&self) -> u32;
fn height(&self) -> u32;
}
pub trait ImageArea {
fn area(&self) -> Area;
}
impl<U> ImageSize for U
where
U: ImageArea,
{
fn width(&self) -> u32 {
u32::from(self.area().width())
}
fn height(&self) -> u32 {
u32::from(self.area().height())
}
}
pub trait ToImage {
type Pixel: Pixel<Subpixel = u8>;
fn to_image(&self) -> ImageBuffer<Self::Pixel, Vec<u8>>;
}
#[derive(Debug, Clone, Copy)]
pub struct ToOcrImageOpt {
pub border: u32,
pub text_color: Luma<u8>,
pub background_color: Luma<u8>,
}
impl Default for ToOcrImageOpt {
fn default() -> Self {
Self {
border: 5,
text_color: Luma([0]),
background_color: Luma([255]),
}
}
}
pub trait ToOcrImage {
fn image(&self, opt: &ToOcrImageOpt) -> GrayImage;
}