use super::Ditherer;
use crate::{buffer::Buffer, pixel, view};
pub trait Dither<P, C>
where
P: pixel::Read<C> + pixel::Write<C>,
C: pixel::Channel,
{
fn dither<A>(self, colors: u32) -> Buffer<P, C, Vec<C>>
where
A: Ditherer<P, C, P, C>;
}
impl<'i, P, C, I> Dither<P, C> for I
where
P: pixel::Read<C> + pixel::Write<C>,
C: pixel::Channel,
I: Into<view::Read<'i, P, C>>,
{
fn dither<A>(self, colors: u32) -> Buffer<P, C, Vec<C>>
where
A: Ditherer<P, C, P, C>,
{
it::<A, _, P, C, P, C>(self, colors)
}
}
#[inline]
pub fn it<'i, A, I, PI, CI, PO, CO>(input: I, colors: u32) -> Buffer<PO, CO, Vec<CO>>
where
A: Ditherer<PI, CI, PO, CO>,
PO: From<PI>,
PO: pixel::Write<CO>,
CO: pixel::Channel,
PI: pixel::Read<CI>,
CI: pixel::Channel,
I: Into<view::Read<'i, PI, CI>>,
{
A::dither(&input.into(), colors)
}