Skip to content

Commit

Permalink
add DynImage::pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
bend-n committed Nov 13, 2023
1 parent f7b1c21 commit 3b69335
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fimg"
version = "0.4.24"
version = "0.4.25"
authors = ["bend-n <[email protected]>"]
license = "MIT"
edition = "2021"
Expand Down
21 changes: 20 additions & 1 deletion src/dyn/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Image;
use crate::{pixels::convert::PFrom, Image};
mod affine;
mod convert;
#[cfg(feature = "scale")]
Expand Down Expand Up @@ -68,6 +68,25 @@ impl<T: AsRef<[u8]>> DynImage<T> {
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<const P: usize>(&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())
Expand Down

0 comments on commit 3b69335

Please sign in to comment.