Type Alias imgref::ImgRef

source ·
pub type ImgRef<'a, Pixel> = Img<&'a [Pixel]>;
Expand description

Reference to pixels inside another image. Pass this structure by value (i.e. ImgRef, not &ImgRef).

Only width of pixels of every stride can be modified. The buf may be longer than height*stride, but the extra space should be ignored.

Aliased Type§

struct ImgRef<'a, Pixel> {
    pub buf: &'a [Pixel],
    pub stride: usize,
    pub width: u32,
    pub height: u32,
}

Fields§

§buf: &'a [Pixel]
👎Deprecated: 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
👎Deprecated: 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
👎Deprecated: 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
👎Deprecated: Don’t access struct fields directly. Use height()

Height of the image in pixels.

Implementations§

source§

impl<'a, T> ImgRef<'a, T>

source

pub fn sub_image( &self, left: usize, top: usize, width: usize, height: usize ) -> Self

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.)

source

pub fn rows(&self) -> RowsIter<'_, T>

Iterate over whole rows of pixels as slices

Panics

If stride is 0

See also pixels()

source§

impl<'a, T: Clone> ImgRef<'a, T>

source

pub fn to_contiguous_buf(&self) -> (Cow<'a, [T]>, usize, usize)

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()

source§

impl<'a, T: Copy> ImgRef<'a, T>

source

pub fn pixels(&self) -> PixelsIter<'_, T>

Iterate width*height pixels in the Img, ignoring padding area

If you want to iterate in parallel, parallelize rows() instead.

Panics

if width is 0

source§

impl<'a, T> ImgRef<'a, T>

source

pub fn pixels_ref(&self) -> PixelsRefIter<'_, T>

Iterate width*height pixels in the Img, by reference, ignoring padding area

If you want to iterate in parallel, parallelize rows() instead.

Panics

if width is 0

Trait Implementations§

source§

impl<'a, T: Hash> Hash for ImgRef<'a, T>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, 'b, T, U> PartialEq<Img<&'b [U]>> for ImgRef<'a, T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &ImgRef<'b, U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b, T, U> PartialEq<Img<&'b mut [U]>> for ImgRef<'a, T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &ImgRefMut<'b, U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, T, U> PartialEq<Img<Vec<U>>> for ImgRef<'a, T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &ImgVec<U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, T: Eq> Eq for ImgRef<'a, T>