[−][src]Struct imgref::Img
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.
Methods
impl<Container> Img<Container>
[src]
pub fn width(&self) -> usize
[src]
Width of the image in pixels.
Note that this isn't same as the width of the row in image data, see stride()
pub fn height(&self) -> usize
[src]
Height of the image in pixels.
pub fn stride(&self) -> usize
[src]
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.
pub fn buf(&self) -> &Container
[src]
Immutable reference to the pixel storage.
pub fn buf_mut(&mut self) -> &mut Container
[src]
Mutable reference to the pixel storage.
pub fn into_buf(self) -> Container
[src]
Get the pixel storage by consuming the image.
pub fn rows_buf<'a, T: 'a>(&self, buf: &'a [T]) -> RowsIter<'a, T>
[src]
impl<'a, T> Img<&'a [Pixel]>
[src]
#[must_use]pub fn sub_image(
&self,
left: usize,
top: usize,
width: usize,
height: usize
) -> Self
[src]
&self,
left: usize,
top: usize,
width: usize,
height: usize
) -> Self
Make a reference for a part of the image, without copying any pixels.
#[must_use]pub fn rows(&self) -> RowsIter<T>
[src]
pub fn iter(&self) -> Iter<T>
[src]
Size of this buffer is unpredictable. Use .rows() instead
Deprecated
Note: it iterates all pixels in the underlying buffer, not just limited by width/height.
impl<'a, T> Img<&'a mut [Pixel]>
[src]
#[must_use]pub fn sub_image(
&'a mut self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRef<'a, T>
[src]
&'a mut self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRef<'a, T>
Turn this into immutable reference, and slice a subregion of it
#[must_use]pub fn sub_image_mut(
&mut self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRefMut<T>
[src]
&mut self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRefMut<T>
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.
#[must_use]pub fn as_ref(&self) -> ImgRef<T>
[src]
Make mutable reference immutable
impl<'a, T: Copy> Img<&'a [Pixel]>
[src]
#[must_use]pub fn pixels(&self) -> PixelsIter<T>
[src]
impl<'a, T: Copy> Img<&'a mut [Pixel]>
[src]
#[must_use]pub fn pixels(&self) -> PixelsIter<T>
[src]
#[must_use]pub fn pixels_mut(&mut self) -> PixelsIterMut<T>
[src]
impl<'a, T: Copy> Img<Vec<Pixel>>
[src]
#[must_use]pub fn pixels(&self) -> PixelsIter<T>
[src]
#[must_use]pub fn pixels_mut(&mut self) -> PixelsIterMut<T>
[src]
impl<'a, T> Img<&'a mut [Pixel]>
[src]
#[must_use]pub fn rows(&self) -> RowsIter<T>
[src]
#[must_use]pub fn rows_mut(&mut self) -> RowsIterMut<T>
[src]
impl<T> Img<Vec<Pixel>>
[src]
#[must_use]pub fn sub_image_mut(
&mut self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRefMut<T>
[src]
&mut self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRefMut<T>
Create a mutable view into a region within the image. See sub_image()
for read-only views.
#[must_use]pub fn sub_image(
&self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRef<T>
[src]
&self,
left: usize,
top: usize,
width: usize,
height: usize
) -> ImgRef<T>
Make a reference for a part of the image, without copying any pixels.
#[must_use]pub fn as_ref(&self) -> ImgRef<T>
[src]
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()
pub fn as_mut(&mut self) -> ImgRefMut<T>
[src]
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()
pub fn iter(&self) -> Iter<T>
[src]
Size of this buffer may be unpredictable. Use .rows() instead
#[must_use]pub fn rows(&self) -> RowsIter<T>
[src]
Iterate over rows of the image as slices
Each slice is guaranteed to be exactly width
pixels wide.
#[must_use]pub fn rows_mut(&mut self) -> RowsIterMut<T>
[src]
Iterate over rows of the image as mutable slices
Each slice is guaranteed to be exactly width
pixels wide.
impl<Container> Img<Container>
[src]
pub fn new_stride(
buf: Container,
width: usize,
height: usize,
stride: usize
) -> Self
[src]
buf: Container,
width: usize,
height: usize,
stride: usize
) -> Self
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.
pub fn new(buf: Container, width: usize, height: usize) -> Self
[src]
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.
impl<T: Copy> Img<Vec<T>>
[src]
#[must_use]pub fn into_contiguous_buf(self) -> (Vec<T>, usize, usize)
[src]
Returns 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()
.
impl<OldContainer> Img<OldContainer>
[src]
pub fn new_buf<NewContainer, OldPixel, NewPixel>(
&self,
new_buf: NewContainer
) -> Img<NewContainer> where
NewContainer: AsRef<[NewPixel]>,
OldContainer: AsRef<[OldPixel]>,
[src]
&self,
new_buf: NewContainer
) -> Img<NewContainer> where
NewContainer: AsRef<[NewPixel]>,
OldContainer: AsRef<[OldPixel]>,
A convenience method for creating an image of the same size and stride, but with a new buffer.
Trait Implementations
impl<Container: Clone> Clone for Img<Container>
[src]
impl<Container: Copy> Copy for Img<Container>
[src]
impl<Container: Debug> Debug for Img<Container>
[src]
impl<Container: Eq> Eq for Img<Container>
[src]
impl<Container: Hash> Hash for Img<Container>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<Pixel, Container> ImgExt<Pixel> for Img<Container> where
Container: AsRef<[Pixel]>,
[src]
Container: AsRef<[Pixel]>,
fn width_padded(&self) -> usize
[src]
fn height_padded(&self) -> usize
[src]
fn rows_padded(&self) -> Chunks<Pixel>
[src]
Iterate over the entire buffer as rows, including all padding
Rows will have up to stride
width, but the last row may be shorter.
impl<Pixel, Container> ImgExtMut<Pixel> for Img<Container> where
Container: AsMut<[Pixel]>,
[src]
Container: AsMut<[Pixel]>,
#[must_use]fn rows_padded_mut(&mut self) -> ChunksMut<Pixel>
[src]
Iterate over the entire buffer as rows, including all padding
Rows will have up to stride
width, but the last row may be shorter.
impl<'a, Pixel: Copy> Index<(u32, u32)> for Img<&'a [Pixel]>
[src]
type Output = Pixel
The returned type after indexing.
fn index(&self, index: (u32, u32)) -> &Self::Output
[src]
Read a pixel at (x,y)
location (e.g. px = img[(x,y)]
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> Index<(u32, u32)> for Img<&'a mut [Pixel]>
[src]
type Output = Pixel
The returned type after indexing.
fn index(&self, index: (u32, u32)) -> &Self::Output
[src]
Read a pixel at (x,y)
location (e.g. px = img[(x,y)]
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> Index<(u32, u32)> for Img<Vec<Pixel>>
[src]
type Output = Pixel
The returned type after indexing.
fn index(&self, index: (u32, u32)) -> &Self::Output
[src]
Read a pixel at (x,y)
location (e.g. px = img[(x,y)]
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> Index<(usize, usize)> for Img<&'a [Pixel]>
[src]
type Output = Pixel
The returned type after indexing.
fn index(&self, index: (usize, usize)) -> &Self::Output
[src]
Read a pixel at (x,y)
location (e.g. px = img[(x,y)]
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> Index<(usize, usize)> for Img<&'a mut [Pixel]>
[src]
type Output = Pixel
The returned type after indexing.
fn index(&self, index: (usize, usize)) -> &Self::Output
[src]
Read a pixel at (x,y)
location (e.g. px = img[(x,y)]
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> Index<(usize, usize)> for Img<Vec<Pixel>>
[src]
type Output = Pixel
The returned type after indexing.
fn index(&self, index: (usize, usize)) -> &Self::Output
[src]
Read a pixel at (x,y)
location (e.g. px = img[(x,y)]
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> IndexMut<(u32, u32)> for Img<&'a mut [Pixel]>
[src]
fn index_mut(&mut self, index: (u32, u32)) -> &mut Self::Output
[src]
Write a pixel at (x,y)
location (e.g. img[(x,y)] = px
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> IndexMut<(u32, u32)> for Img<Vec<Pixel>>
[src]
fn index_mut(&mut self, index: (u32, u32)) -> &mut Self::Output
[src]
Write a pixel at (x,y)
location (e.g. img[(x,y)] = px
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> IndexMut<(usize, usize)> for Img<&'a mut [Pixel]>
[src]
fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output
[src]
Write a pixel at (x,y)
location (e.g. img[(x,y)] = px
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<'a, Pixel: Copy> IndexMut<(usize, usize)> for Img<Vec<Pixel>>
[src]
fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output
[src]
Write a pixel at (x,y)
location (e.g. img[(x,y)] = px
)
Coordinates may be outside width
/height
if the buffer has enough padding.
The x coordinate can't exceed stride
.
impl<Container> IntoIterator for Img<Container> where
Container: IntoIterator,
[src]
Container: IntoIterator,
type Item = Container::Item
The type of the elements being iterated over.
type IntoIter = Container::IntoIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Container::IntoIter
[src]
impl<Container: PartialEq> PartialEq<Img<Container>> for Img<Container>
[src]
impl<Container> StructuralEq for Img<Container>
[src]
impl<Container> StructuralPartialEq for Img<Container>
[src]
Auto Trait Implementations
impl<Container> RefUnwindSafe for Img<Container> where
Container: RefUnwindSafe,
Container: RefUnwindSafe,
impl<Container> Send for Img<Container> where
Container: Send,
Container: Send,
impl<Container> Sync for Img<Container> where
Container: Sync,
Container: Sync,
impl<Container> Unpin for Img<Container> where
Container: Unpin,
Container: Unpin,
impl<Container> UnwindSafe for Img<Container> where
Container: UnwindSafe,
Container: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,