pub struct ImageBuf<P: Pixel> { /* private fields */ }Expand description
An owned, length-validated interleaved image of pixel type P.
The owning counterpart of ImageRef; the natural return of a decoder, carrying its
dimensions, samples, and layout brand as one unit so a caller can never misinterpret the result.
Implementations§
Source§impl<P: Pixel> ImageBuf<P>
impl<P: Pixel> ImageBuf<P>
Sourcepub fn new(data: Vec<P::Sample>, dims: Dimensions) -> Result<Self>
pub fn new(data: Vec<P::Sample>, dims: Dimensions) -> Result<Self>
Takes ownership of data as an image of dims, validating its length the same way as
ImageRef::new.
§Errors
Returns Error::InvalidInput if dims is zero-sized, if the sample count overflows
usize, or if data.len() does not equal width * height * P::CHANNELS.
Sourcepub fn zeroed(dims: Dimensions) -> Result<Self>
pub fn zeroed(dims: Dimensions) -> Result<Self>
An all-zero image of dims (every sample P::Sample::default()).
§Errors
Returns Error::InvalidInput if dims is zero-sized or the sample count overflows usize.
Sourcepub fn as_ref(&self) -> ImageRef<'_, P>
pub fn as_ref(&self) -> ImageRef<'_, P>
Borrows this image as an ImageRef. Infallible — the invariant already holds.
Sourcepub fn dimensions(&self) -> Dimensions
pub fn dimensions(&self) -> Dimensions
The image dimensions.
Sourcepub fn as_samples(&self) -> &[P::Sample]
pub fn as_samples(&self) -> &[P::Sample]
The raw interleaved samples, row-major.
Sourcepub fn into_samples(self) -> Vec<P::Sample>
pub fn into_samples(self) -> Vec<P::Sample>
Consumes the image, returning its backing sample vector.