Struct SubImage

struct SubImage<I> { ... }

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

impl<I> SubImage<I>

fn view(self: &Self, x: u32, y: u32, width: u32, height: u32) -> SubImage<&<I as >::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);
fn inner(self: &Self) -> &<I as >::Target

Get a reference to the underlying image.

impl<I> SubImage<I>

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.

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

Change the coordinates of this subimage.

fn offsets(self: &Self) -> (u32, u32)

The offsets of this subimage relative to the underlying image.

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

Convert this subimage to an ImageBuffer

impl<I> SubImage<I>

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

Create a mutable sub-view of the image.

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

fn inner_mut(self: &mut Self) -> &mut <I as >::Target

Get a mutable reference to the underlying image.

impl<I> Deref for SubImage<I>

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

impl<I> DerefMut for SubImage<I>

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

impl<I> Freeze for SubImage<I>

impl<I> RefUnwindSafe for SubImage<I>

impl<I> Send for SubImage<I>

impl<I> Sync for SubImage<I>

impl<I> Unpin for SubImage<I>

impl<I> UnsafeUnpin for SubImage<I>

impl<I> UnwindSafe for SubImage<I>

impl<I: $crate::clone::Clone> Clone for SubImage<I>

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

impl<I: $crate::marker::Copy> Copy for SubImage<I>

impl<P, T> Receiver for SubImage<I>

impl<T> Any for SubImage<I>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for SubImage<I>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for SubImage<I>

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

impl<T> CloneToUninit for SubImage<I>

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

impl<T> From for SubImage<I>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Pointable for SubImage<I>

unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> ToOwned for SubImage<I>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for SubImage<I>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for SubImage<I>

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

impl<T, U> TryInto for SubImage<I>

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