Skip to main content

ImageRef

Struct ImageRef 

Source
pub struct ImageRef<'a, P: Pixel> { /* private fields */ }
Expand description

A borrowed, length-validated view of an interleaved image of pixel type P.

Cheap to copy (a slice + Dimensions + a zero-sized marker). Construct one at an API boundary with ImageRef::new; pass it to an crate::EncodeImage implementation.

Implementations§

Source§

impl<'a, P: Pixel> ImageRef<'a, P>

Source

pub fn new(data: &'a [P::Sample], dims: Dimensions) -> Result<Self>

Brands data as an image of dims, validating that its length is exactly width * height * P::CHANNELS.

§Errors

Returns Error::InvalidInput if dims is zero-sized, if width * height * channels overflows usize, or if data.len() does not equal that product.

Source

pub fn dimensions(self) -> Dimensions

The image dimensions.

Source

pub fn width(self) -> u32

Image width in pixels.

Source

pub fn height(self) -> u32

Image height in pixels.

Source

pub fn as_samples(self) -> &'a [P::Sample]

The raw interleaved samples (width * height * P::CHANNELS of them, row-major). The zero-cost escape hatch a codec uses to feed its existing slice-based hot path.

Source

pub fn row(self, y: u32) -> &'a [P::Sample]

Row y as a width * P::CHANNELS-sample slice.

§Panics

Panics if y >= height.

Source

pub fn rows(self) -> impl ExactSizeIterator<Item = &'a [P::Sample]>

Iterates the rows top to bottom, each a width * P::CHANNELS-sample slice.

Source

pub fn pixel(self, x: u32, y: u32) -> &'a [P::Sample]

The P::CHANNELS samples of the pixel at (x, y).

§Panics

Panics if x >= width or y >= height.

Trait Implementations§

Source§

impl<'a, P: Clone + Pixel> Clone for ImageRef<'a, P>
where P::Sample: Clone,

Source§

fn clone(&self) -> ImageRef<'a, P>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, P: Copy + Pixel> Copy for ImageRef<'a, P>
where P::Sample: Copy,

Source§

impl<'a, P: Debug + Pixel> Debug for ImageRef<'a, P>
where P::Sample: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, P> Freeze for ImageRef<'a, P>

§

impl<'a, P> RefUnwindSafe for ImageRef<'a, P>

§

impl<'a, P> Send for ImageRef<'a, P>
where P: Send, <P as Pixel>::Sample: Sync,

§

impl<'a, P> Sync for ImageRef<'a, P>
where P: Sync, <P as Pixel>::Sample: Sync,

§

impl<'a, P> Unpin for ImageRef<'a, P>
where P: Unpin,

§

impl<'a, P> UnsafeUnpin for ImageRef<'a, P>

§

impl<'a, P> UnwindSafe for ImageRef<'a, P>
where P: UnwindSafe, <P as Pixel>::Sample: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.