use crate::RgbaPixel;
pub(crate) fn from_fn<T>(
width: usize,
height: usize,
mut f: impl FnMut(usize, usize) -> T,
) -> imgref::ImgVec<T> {
imgref::ImgVec::new(
(0..height)
.flat_map(|y| (0..width).map(move |x| (x, y)))
.map(|(x, y)| f(x, y))
.collect(),
width,
height,
)
}
pub(crate) fn rgba_to_luma(pixel: RgbaPixel) -> u8 {
let [r, g, b, _a] = pixel;
let luma: u32 = (2126 * u32::from(r) + 7152 * u32::from(g) + 722 * u32::from(b)) / 10000;
debug_assert!(u8::try_from(luma).is_ok());
#[allow(clippy::cast_possible_truncation)]
{
luma as u8
}
}
#[cfg(test)]
pub(crate) fn luma_to_rgba(luma: u8) -> RgbaPixel {
[luma, luma, luma, 255]
}