ezk_image/
image_traits.rsuse crate::{BoundsCheckError, ColorInfo, CropError, Cropped, PixelFormat, Window};
pub unsafe trait ImageRef {
fn format(&self) -> PixelFormat;
fn width(&self) -> usize;
fn height(&self) -> usize;
fn planes(&self) -> Box<dyn Iterator<Item = (&[u8], usize)> + '_>;
fn color(&self) -> ColorInfo;
}
pub unsafe trait ImageMut: ImageRef {
fn planes_mut(&mut self) -> Box<dyn Iterator<Item = (&mut [u8], usize)> + '_>;
}
pub trait ImageRefExt: ImageRef {
fn bounds_check(&self) -> Result<(), BoundsCheckError> {
self.format()
.bounds_check(self.planes(), self.width(), self.height())
}
fn crop(self, window: Window) -> Result<Cropped<Self>, CropError>
where
Self: Sized,
{
Cropped::new(self, window)
}
}
impl<T: ImageRef + ?Sized> ImageRefExt for T {}
unsafe impl<T: ImageRef> ImageRef for &T {
fn format(&self) -> PixelFormat {
<T as ImageRef>::format(self)
}
fn width(&self) -> usize {
<T as ImageRef>::width(self)
}
fn height(&self) -> usize {
<T as ImageRef>::height(self)
}
fn planes(&self) -> Box<dyn Iterator<Item = (&[u8], usize)> + '_> {
<T as ImageRef>::planes(self)
}
fn color(&self) -> ColorInfo {
<T as ImageRef>::color(self)
}
}
unsafe impl<T: ImageRef> ImageRef for &mut T {
fn format(&self) -> PixelFormat {
<T as ImageRef>::format(self)
}
fn width(&self) -> usize {
<T as ImageRef>::width(self)
}
fn height(&self) -> usize {
<T as ImageRef>::height(self)
}
fn planes(&self) -> Box<dyn Iterator<Item = (&[u8], usize)> + '_> {
<T as ImageRef>::planes(self)
}
fn color(&self) -> ColorInfo {
<T as ImageRef>::color(self)
}
}
unsafe impl<T: ImageMut> ImageMut for &mut T {
fn planes_mut(&mut self) -> Box<dyn Iterator<Item = (&mut [u8], usize)> + '_> {
<T as ImageMut>::planes_mut(self)
}
}