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
👎 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

Width of the image in pixels.

Note that this isn’t same as the width of the row in image data, see stride()

Height of the image in pixels.

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.

👎 Deprecated:

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

Iterate over whole rows of pixels as slices

Panics

If stride is 0

See also pixels()

👎 Deprecated:

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.

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.

Make mutable reference immutable

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

Panics

if width is 0

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

Panics

if width is 0

Panics

if width is 0

Panics

if width is 0

Panics

if width is 0

Panics

if width is 0

Panics

if stride is 0

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

👎 Deprecated:

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.

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

A convenience method for creating an image of the same size and stride, but with a new buffer.

Convert underlying buffer to owned (e.g. slice to vec)

See also to_contiguous_buf().0.into_owned()

Convert underlying buffer to owned (e.g. slice to vec)

See also to_contiguous_buf().0.into_owned()

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

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

Borrow the container

Iterate over the entire buffer as rows, including all padding

Rows will have up to stride width, but the last row may be shorter.

Panics

If stride is 0

Borrow the container mutably

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.

The returned type after indexing.

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.

The returned type after indexing.

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.

The returned type after indexing.

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.

The returned type after indexing.

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.

The returned type after indexing.

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.

The returned type after indexing.

Take n-th row as a slice. Same as .rows().nth(n).unwrap()

Slice length is guaranteed to equal image width. Row must be within image height.

The returned type after indexing.

Take n-th row as a slice. Same as .rows().nth(n).unwrap()

Slice length is guaranteed to equal image width. Row must be within image height.

The returned type after indexing.

Take n-th row as a slice. Same as .rows().nth(n).unwrap()

Slice length is guaranteed to equal image width. Row must be within image height.

The returned type after indexing.

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.

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.

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.

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.

Take n-th row as a mutable slice. Same as .rows().nth(n).unwrap()

Slice length is guaranteed to equal image width. Row must be within image height.

Take n-th row as a mutable slice. Same as .rows().nth(n).unwrap()

Slice length is guaranteed to equal image width. Row must be within image height.

Deprecated. Use .rows() or .pixels() iterators which are more predictable

Deprecated. Use .rows() or .pixels() iterators which are more predictable

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.