diff --git a/Cargo.toml b/Cargo.toml index 6fd5c77..52a69ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fimg" -version = "0.4.24" +version = "0.4.25" authors = ["bend-n "] license = "MIT" edition = "2021" diff --git a/src/dyn/mod.rs b/src/dyn/mod.rs index b86742e..184047a 100644 --- a/src/dyn/mod.rs +++ b/src/dyn/mod.rs @@ -1,4 +1,4 @@ -use crate::Image; +use crate::{pixels::convert::PFrom, Image}; mod affine; mod convert; #[cfg(feature = "scale")] @@ -68,6 +68,25 @@ impl> DynImage { e!(self => |i| i.as_ref()) } + /// Get a pixel, of a type. + /// ``` + /// # use fimg::{Image, DynImage}; + /// let i = DynImage::Rgb(Image::alloc(50, 50)); + /// assert_eq!(unsafe { i.pixel::<4>(25, 25) }, [0, 0, 0, 255]); + /// ``` + /// # Safety + /// + /// undefined behaviour if pixel is out of bounds. + pub unsafe fn pixel(&self, x: u32, y: u32) -> [u8; P] + where + [u8; P]: PFrom<1>, + [u8; P]: PFrom<2>, + [u8; P]: PFrom<3>, + [u8; P]: PFrom<4>, + { + e!(self, |i| PFrom::pfrom(unsafe { i.pixel(x, y) })) + } + /// Bytes of this image. pub fn bytes(&self) -> &[u8] { e!(self, |i| i.bytes())