use crate::{
bitmap::BitmapAccess,
colour::{read_from_bytes, Colour},
formats::PixelFormatSpec,
math,
};
pub trait BitmapExt<Format: PixelFormatSpec>: BitmapAccess<Format> {
fn read_colour(&self, point: math::PixelPoint) -> Option<Colour> {
if point.x < 0
|| point.y < 0
|| point.x >= self.width() as i32
|| point.y >= self.height() as i32
{
return None;
} else {
let raw = &self.data()
[(self.stride() * point.y as usize) + (Format::PIXEL_STRIDE * point.x as usize)..];
Some(read_from_bytes::<Format>(raw))
}
}
}
impl<F: PixelFormatSpec, BA: BitmapAccess<F>> BitmapExt<F> for BA {}