use crate::Image;
mod algorithms;
pub mod traits;
pub use algorithms::*;
macro_rules! transparent {
($n: literal, $name: ident) => {
impl<T: AsMut<[u8]> + AsRef<[u8]>> Image<T, $n> {
#[doc = stringify!($name)]
pub fn scale<A: traits::ScalingAlgorithm>(
&mut self,
width: u32,
height: u32,
) -> Image<std::boxed::Box<[u8]>, $n> {
A::scale_transparent(
self.as_mut(),
width.try_into().unwrap(),
height.try_into().unwrap(),
)
}
}
};
}
macro_rules! opaque {
($n: literal, $name: ident) => {
impl<T: AsRef<[u8]>> Image<T, $n> {
#[doc = stringify!($name)]
pub fn scale<A: traits::ScalingAlgorithm>(
&self,
width: u32,
height: u32,
) -> Image<std::boxed::Box<[u8]>, $n> {
A::scale_opaque(
self.as_ref(),
width.try_into().unwrap(),
height.try_into().unwrap(),
)
}
}
};
}
opaque!(1, Y);
transparent!(2, YA);
opaque!(3, RGB);
transparent!(4, RGBA);
#[test]
fn test_nearest() {
let i = Image::<_, 3>::open("tdata/cat.png");
assert_eq!(
&*i.scale::<Nearest>(268, 178).buffer,
&*Image::<_, 3>::open("tdata/small_cat.png").buffer
);
}