Struct imgref::Img [−][src]
pub struct Img<Container> { pub buf: Container, pub stride: usize, pub width: u32, pub height: u32, }
Expand description
Basic struct used for both owned (alias ImgVec
) and borrowed (alias ImgRef
) image fragments.
Note: the fields are pub
only because of borrow checker limitations. Please consider them as read-only.
Fields
buf: Container
Don’t access struct fields directly. Use buf(), buf_mut() or into_buf()
Storage for the pixels. Usually Vec<Pixel>
or &[Pixel]
. See ImgVec
and ImgRef
.
Note that future version will make this field private. Use .rows()
and .pixels()
iterators where possible, or buf()
/buf_mut()
/into_buf()
.
stride: usize
Don’t access struct fields directly. Use stride()
Number of pixels to skip in the container to advance to the next row.
Note: pixels between width
and stride
may not be usable, and may not even exist in the last row.
width: u32
Don’t access struct fields directly. Use width()
Width of the image in pixels.
Note that this isn’t same as the width of the row in the buf
, see stride
height: u32
Don’t access struct fields directly. Use height()
Height of the image in pixels.
Implementations
Width of the image in pixels.
Note that this isn’t same as the width of the row in image data, see stride()
Number of pixels to skip in the container to advance to the next row.
Note the last row may have fewer pixels than the stride. Some APIs use number of bytes for a stride. You may need to multiply this one by number of pixels.
Immutable reference to the pixel storage. Warning: exposes stride. Use pixels()
or rows()
insetad.
See also into_contiguous_buf()
.
Mutable reference to the pixel storage. Warning: exposes stride. Use pixels_mut()
or rows_mut()
insetad.
See also into_contiguous_buf()
.
Get the pixel storage by consuming the image. Be careful about stride — see into_contiguous_buf()
for a safe version.
this was meant to be private, use new_buf() and/or rows()
Make a reference for a part of the image, without copying any pixels.
Panics
It will panic if sub_image is outside of the image area (left + width must be <= container width, etc.)
Returns a reference to the buffer, width, height. Guarantees that the buffer is contiguous,
i.e. it’s width*height
elements long, and [x + y*width]
addresses each pixel.
It will create a copy if the buffer isn’t contiguous (width != stride).
For a more efficient version, see into_contiguous_buf()
Turn this into immutable reference, and slice a subregion of it
Trim this image without copying. Note that mutable borrows are exclusive, so it’s not possible to have more than one mutable subimage at a time.
pub fn pixels(&self) -> PixelsIter<'_, T>ⓘNotable traits for PixelsIter<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIter<'a, T> type Item = T;
pub fn pixels(&self) -> PixelsIter<'_, T>ⓘNotable traits for PixelsIter<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIter<'a, T> type Item = T;
pub fn pixels_ref(&self) -> PixelsRefIter<'_, T>ⓘNotable traits for PixelsRefIter<'a, T>
impl<'a, T: 'a> Iterator for PixelsRefIter<'a, T> type Item = &'a T;
pub fn pixels_ref(&self) -> PixelsRefIter<'_, T>ⓘNotable traits for PixelsRefIter<'a, T>
impl<'a, T: 'a> Iterator for PixelsRefIter<'a, T> type Item = &'a T;
pub fn pixels(&self) -> PixelsIter<'_, T>ⓘNotable traits for PixelsIter<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIter<'a, T> type Item = T;
pub fn pixels(&self) -> PixelsIter<'_, T>ⓘNotable traits for PixelsIter<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIter<'a, T> type Item = T;
Panics
if width is 0
pub fn pixels_mut(&mut self) -> PixelsIterMut<'_, T>ⓘNotable traits for PixelsIterMut<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIterMut<'a, T> type Item = &'a mut T;
pub fn pixels_mut(&mut self) -> PixelsIterMut<'_, T>ⓘNotable traits for PixelsIterMut<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIterMut<'a, T> type Item = &'a mut T;
Panics
if width is 0
pub fn pixels(&self) -> PixelsIter<'_, T>ⓘNotable traits for PixelsIter<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIter<'a, T> type Item = T;
pub fn pixels(&self) -> PixelsIter<'_, T>ⓘNotable traits for PixelsIter<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIter<'a, T> type Item = T;
Panics
if width is 0
pub fn pixels_mut(&mut self) -> PixelsIterMut<'_, T>ⓘNotable traits for PixelsIterMut<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIterMut<'a, T> type Item = &'a mut T;
pub fn pixels_mut(&mut self) -> PixelsIterMut<'_, T>ⓘNotable traits for PixelsIterMut<'a, T>
impl<'a, T: Copy + 'a> Iterator for PixelsIterMut<'a, T> type Item = &'a mut T;
Panics
if width is 0
Panics
if stride is 0
pub fn rows_mut(&mut self) -> RowsIterMut<'_, T>ⓘNotable traits for RowsIterMut<'a, T>
impl<'a, T: 'a> Iterator for RowsIterMut<'a, T> type Item = &'a mut [T];
pub fn rows_mut(&mut self) -> RowsIterMut<'_, T>ⓘNotable traits for RowsIterMut<'a, T>
impl<'a, T: 'a> Iterator for RowsIterMut<'a, T> type Item = &'a mut [T];
Panics
if stride is 0
Create a mutable view into a region within the image. See sub_image()
for read-only views.
Make a reference for a part of the image, without copying any pixels.
Make a reference to this image to pass it to functions without giving up ownership
The reference should be passed by value (ImgRef
, not &ImgRef
).
If you need a mutable reference, see as_mut()
and sub_image_mut()
Make a mutable reference to the entire image
The reference should be passed by value (ImgRefMut
, not &mut ImgRefMut
).
See also sub_image_mut()
and rows_mut()
Size of this buffer may be unpredictable. Use .rows() instead
Iterate over rows of the image as slices
Each slice is guaranteed to be exactly width
pixels wide.
pub fn rows_mut(&mut self) -> RowsIterMut<'_, T>ⓘNotable traits for RowsIterMut<'a, T>
impl<'a, T: 'a> Iterator for RowsIterMut<'a, T> type Item = &'a mut [T];
pub fn rows_mut(&mut self) -> RowsIterMut<'_, T>ⓘNotable traits for RowsIterMut<'a, T>
impl<'a, T: 'a> Iterator for RowsIterMut<'a, T> type Item = &'a mut [T];
Iterate over rows of the image as mutable slices
Each slice is guaranteed to be exactly width
pixels wide.
Same as new()
, except each row is located stride
number of pixels after the previous one.
Stride can be equal to width
or larger. If it’s larger, then pixels between end of previous row and start of the next are considered a padding, and may be ignored.
The Container
is usually a Vec
or a slice.
Create new image with Container
(which can be Vec
, &[]
or something else) with given width
and height
in pixels.
Assumes the pixels in container are contiguous, layed out row by row with width
pixels per row and at least height
rows.
If the container is larger than width
×height
pixels, the extra rows are a considered a padding and may be ignored.
Returns the buffer, width, height. Guarantees that the buffer is contiguous,
i.e. it’s width*height
elements long, and [x + y*width]
addresses each pixel.
Efficiently performs operation in-place. For other containers use pixels().collect()
.
Returns a reference to the buffer, width, height. Guarantees that the buffer is contiguous,
i.e. it’s width*height
elements long, and [x + y*width]
addresses each pixel.
Efficiently performs operation in-place. For other containers use pixels().collect()
.
Convert underlying buffer to owned (e.g. slice to vec)
See also to_contiguous_buf().0.into_owned()
Trait Implementations
Iterate over the entire buffer as rows, including all padding
Rows will have up to stride
width, but the last row may be shorter.
Maximum possible width of the data, including the stride. Read more
Height in number of full strides. If the underlying buffer is not an even multiple of strides, the last row is ignored. Read more
Deprecated. Use .rows() or .pixels() iterators which are more predictable
Auto Trait Implementations
impl<Container> RefUnwindSafe for Img<Container> where
Container: RefUnwindSafe,
impl<Container> UnwindSafe for Img<Container> where
Container: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more