image

Struct SubImage

Source
pub struct SubImage<I> { /* private fields */ }
Expand description

A View into another image

Instances of this struct can be created using:

Note that this does not implement GenericImage, but it dereferences to one which allows you to use it as if it did. See Design Considerations below for details.

§Design Considerations

For reasons relating to coherence, this is not itself a GenericImage or a GenericImageView. In short, we want to reserve the ability of adding traits implemented for all generic images but in a different manner for SubImage. This may be required to ensure that stacking sub-images comes at no double indirect cost.

If, ultimately, this is not needed then a directly implementation of GenericImage can and will get added. This inconvenience may alternatively get resolved if Rust allows some forms of specialization, which might make this trick unnecessary and thus also allows for a direct implementation.

Implementations§

Source§

impl<I> SubImage<I>

Source

pub fn new(image: I, x: u32, y: u32, width: u32, height: u32) -> SubImage<I>

Construct a new subimage The coordinates set the position of the top left corner of the SubImage.

Source

pub fn change_bounds(&mut self, x: u32, y: u32, width: u32, height: u32)

Change the coordinates of this subimage.

Source

pub fn offsets(&self) -> (u32, u32)

The offsets of this subimage relative to the underlying image.

Source

pub fn to_image( &self, ) -> ImageBuffer<<<I as Deref>::Target as GenericImageView>::Pixel, Vec<<<<I as Deref>::Target as GenericImageView>::Pixel as Pixel>::Subpixel>>
where I: Deref, I::Target: GenericImageView + 'static,

Convert this subimage to an ImageBuffer

Source§

impl<I> SubImage<I>

Methods for readable images.

Source

pub fn view( &self, x: u32, y: u32, width: u32, height: u32, ) -> SubImage<&I::Target>

Create a sub-view of the image.

The coordinates given are relative to the current view on the underlying image.

Note that this method is preferred to the one from GenericImageView. This is accessible with the explicit method call syntax but it should rarely be needed due to causing an extra level of indirection.

use image::{GenericImageView, RgbImage, SubImage};
let buffer = RgbImage::new(10, 10);

let subimage: SubImage<&RgbImage> = buffer.view(0, 0, 10, 10);
let subview: SubImage<&RgbImage> = subimage.view(0, 0, 10, 10);

// Less efficient and NOT &RgbImage
let _: SubImage<&_> = GenericImageView::view(&*subimage, 0, 0, 10, 10);
Source

pub fn inner(&self) -> &I::Target

Get a reference to the underlying image.

Source§

impl<I> SubImage<I>

Source

pub fn sub_image( &mut self, x: u32, y: u32, width: u32, height: u32, ) -> SubImage<&mut I::Target>

Create a mutable sub-view of the image.

The coordinates given are relative to the current view on the underlying image.

Source

pub fn inner_mut(&mut self) -> &mut I::Target

Get a mutable reference to the underlying image.

Trait Implementations§

Source§

impl<I: Clone> Clone for SubImage<I>

Source§

fn clone(&self) -> SubImage<I>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<I> Deref for SubImage<I>
where I: Deref,

Source§

type Target = SubImageInner<I>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<I> DerefMut for SubImage<I>
where I: DerefMut,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<I: Copy> Copy for SubImage<I>

Auto Trait Implementations§

§

impl<I> Freeze for SubImage<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for SubImage<I>
where I: RefUnwindSafe,

§

impl<I> Send for SubImage<I>
where I: Send,

§

impl<I> Sync for SubImage<I>
where I: Sync,

§

impl<I> Unpin for SubImage<I>
where I: Unpin,

§

impl<I> UnwindSafe for SubImage<I>
where I: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.