pub struct ImageRef<'a, P: Pixel> { /* private fields */ }Expand description
A borrowed, length-validated view of an interleaved image of pixel type P.
Cheap to copy (a slice + Dimensions + a zero-sized marker). Construct one at an API boundary
with ImageRef::new; pass it to an crate::EncodeImage implementation.
Implementations§
Source§impl<'a, P: Pixel> ImageRef<'a, P>
impl<'a, P: Pixel> ImageRef<'a, P>
Sourcepub fn new(data: &'a [P::Sample], dims: Dimensions) -> Result<Self>
pub fn new(data: &'a [P::Sample], dims: Dimensions) -> Result<Self>
Brands data as an image of dims, validating that its length is exactly
width * height * P::CHANNELS.
§Errors
Returns Error::InvalidInput if dims is zero-sized, if width * height * channels
overflows usize, or if data.len() does not equal that product.
Sourcepub fn dimensions(self) -> Dimensions
pub fn dimensions(self) -> Dimensions
The image dimensions.
Sourcepub fn as_samples(self) -> &'a [P::Sample]
pub fn as_samples(self) -> &'a [P::Sample]
The raw interleaved samples (width * height * P::CHANNELS of them, row-major). The
zero-cost escape hatch a codec uses to feed its existing slice-based hot path.
Sourcepub fn rows(self) -> impl ExactSizeIterator<Item = &'a [P::Sample]>
pub fn rows(self) -> impl ExactSizeIterator<Item = &'a [P::Sample]>
Iterates the rows top to bottom, each a width * P::CHANNELS-sample slice.
Sourcepub fn as_raw(self) -> RawImage<'a, P::Sample>
pub fn as_raw(self) -> RawImage<'a, P::Sample>
Re-describes this view with P’s layout carried as a runtime crate::PixelFormat tag
instead of a brand, for crate::convert’s raw entry points.
Infallible: the brand guarantees everything RawImage::new would otherwise check.
Trait Implementations§
impl<'a, P: Copy + Pixel> Copy for ImageRef<'a, P>
impl<P: Pixel> Eq for ImageRef<'_, P>
Source§impl<P: Pixel> PartialEq for ImageRef<'_, P>
Two views are equal when they have the same dimensions and the same samples. Hand-written rather
than derived so the brand P carries no PartialEq bound (only the samples and dimensions are
compared). Comparing dimensions first short-circuits the sample comparison on a size mismatch.
impl<P: Pixel> PartialEq for ImageRef<'_, P>
Two views are equal when they have the same dimensions and the same samples. Hand-written rather
than derived so the brand P carries no PartialEq bound (only the samples and dimensions are
compared). Comparing dimensions first short-circuits the sample comparison on a size mismatch.