#[repr(transparent)]pub struct Image { /* private fields */ }
Expand description
The single-channel image with pixels in bytes.
Implementations§
source§impl Image
impl Image
sourcepub unsafe fn new_uinit(width: usize, height: usize) -> Result<Self, Error>
pub unsafe fn new_uinit(width: usize, height: usize) -> Result<Self, Error>
Give width and height and create an uninitialized image.
Safety
After the image is returned, the caller must explicitly initialize the image buffer.
sourcepub unsafe fn new_uinit_with_stride(
width: usize,
height: usize,
stride: usize
) -> Result<Self, Error>
pub unsafe fn new_uinit_with_stride(
width: usize,
height: usize,
stride: usize
) -> Result<Self, Error>
Give width, height and stride and create an uninitialized image.
Safety
After the image is returned, the caller must explicitly initialize the image buffer.
sourcepub fn from_pnm_file(path: &str) -> Result<Self, Error>
pub fn from_pnm_file(path: &str) -> Result<Self, Error>
Create an image from a PNM file.
sourcepub fn from_pnm_file_with_alignment(
path: &str,
alignment: usize
) -> Result<Self, Error>
pub fn from_pnm_file_with_alignment(
path: &str,
alignment: usize
) -> Result<Self, Error>
Create an image from a PNM file with a specified alignment.
sourcepub fn zeros_with_stride(
width: usize,
height: usize,
stride: usize
) -> Result<Self, Error>
pub fn zeros_with_stride(
width: usize,
height: usize,
stride: usize
) -> Result<Self, Error>
Create a zerod image.
The stride
must be more than or equal to width
. Otherwise it returns None
.
sourcepub fn zeros_with_alignment(
width: usize,
height: usize,
alignment: usize
) -> Result<Self, Error>
pub fn zeros_with_alignment(
width: usize,
height: usize,
alignment: usize
) -> Result<Self, Error>
Create a zerod image.
The alignment
must be non-zero. Otherwise it returns None
.
sourcepub fn samples_iter(&self) -> impl Iterator<Item = u8> + '_
pub fn samples_iter(&self) -> impl Iterator<Item = u8> + '_
Create an iterator traversing pixels in row-major order.
sourcepub fn indexed_samples_iter(
&self
) -> impl Iterator<Item = (usize, usize, u8)> + '_
pub fn indexed_samples_iter(
&self
) -> impl Iterator<Item = (usize, usize, u8)> + '_
Create an iterator that traverses pixels with pixel positions in row-major order.
The iterator item is in (x, y, pixel_value) format.
sourcepub fn as_slice_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_slice_mut(&mut self) -> &mut [u8] ⓘ
Get the mutable pixel buffer with size height*stride.
sourcepub unsafe fn from_raw(ptr: *mut image_u8_t) -> Self
pub unsafe fn from_raw(ptr: *mut image_u8_t) -> Self
Creates an instance from pointer.
The pointer will be managed by the type. Do not run manual deallocation on the pointer. Panics if the pointer is null.
Safety
The method is safe when the pointer was created by image_u8_create_stride or image_u8_create_alignment.
sourcepub fn into_raw(self) -> NonNull<image_u8_t>
pub fn into_raw(self) -> NonNull<image_u8_t>
Returns the underlying pointer.