pub struct SubImage<I> {
inner: SubImageInner<I>,
}
Expand description
A View into another image
Instances of this struct can be created using:
GenericImage::sub_image
to create a mutable view,GenericImageView::view
to create an immutable view,SubImage::new
to instantiate the struct directly.
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.
Fields§
§inner: SubImageInner<I>
Implementations§
§impl<I> SubImage<I>
impl<I> SubImage<I>
pub fn new(image: I, x: u32, y: u32, width: u32, height: u32) -> SubImage<I>
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
.
pub fn change_bounds(&mut self, x: u32, y: u32, width: u32, height: u32)
pub fn change_bounds(&mut self, x: u32, y: u32, width: u32, height: u32)
Change the coordinates of this subimage.
pub fn to_image(
&self
) -> ImageBuffer<<<I as Deref>::Target as GenericImageView>::Pixel, Vec<<<<I as Deref>::Target as GenericImageView>::Pixel as Pixel>::Subpixel>>
pub fn to_image( &self ) -> ImageBuffer<<<I as Deref>::Target as GenericImageView>::Pixel, Vec<<<<I as Deref>::Target as GenericImageView>::Pixel as Pixel>::Subpixel>>
Convert this subimage to an ImageBuffer
§impl<I> SubImage<I>
impl<I> SubImage<I>
Methods for readable images.
pub fn view(
&self,
x: u32,
y: u32,
width: u32,
height: u32
) -> SubImage<&<I as Deref>::Target>
pub fn view( &self, x: u32, y: u32, width: u32, height: u32 ) -> SubImage<&<I as Deref>::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);
Trait Implementations§
impl<I> Copy for SubImage<I>where
I: Copy,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request