Struct fimg::ImageCloner
source · pub struct ImageCloner<'a, const C: usize>(/* private fields */);Expand description
A neat way to clone a image.
Consider it a way to clone->apply a image operation, but better. Please note that some methods may(although none at current) have different safety invariants from their in place counterparts.
Implementations§
source§impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS>
impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS>
source§impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS>
impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS>
Methods from Deref<Target = Image<&'a [u8], C>>§
sourcepub fn crop<'a, U: 'a>(
&'a self,
width: u32,
height: u32
) -> impl Cropper<&'a [U], C>
pub fn crop<'a, U: 'a>( &'a self, width: u32, height: u32 ) -> impl Cropper<&'a [U], C>
Crop a image.
The signature looks something like: i.crop(width, height).from(top_left_x, top_left_y), which gives you a SubImage<&[T], _>
If you want a owned image, i.crop(w, h).from(x, y).own() gets you a back.Image<Box<[T], _>>
let mut i = Image::<_, 1>::build(4, 3).buf([
1, 2, 3, 1,
4, 5, 6, 2,
7, 8, 9, 3,
]);
let c = i.crop(2, 2).from(1, 1);
assert_eq!(c.pixel(0, 0), [5]);
assert_eq!(c.pixel(1, 1), [9]);
assert_eq!(
c.own().bytes(),
&[5, 6,
8, 9]
);§Panics
if width == 0 || height == 0
sourcepub fn wgpu_size(&self) -> Extent3d
Available on crate feature wgpu-convert only.
pub fn wgpu_size(&self) -> Extent3d
wgpu-convert only.Get the size as a [wgpu::Extend3d].
sourcepub fn send(&self, dev: &Device, q: &Queue, usage: TextureUsages) -> Texture
Available on crate feature wgpu-convert only.
pub fn send(&self, dev: &Device, q: &Queue, usage: TextureUsages) -> Texture
wgpu-convert only.Upload this image to the gpu, returning a wgpu::Texture.
sourcepub fn scale<A: ScalingAlgorithm>(
&self,
width: u32,
height: u32
) -> Image<Box<[u8]>, 1>
Available on crate feature scale only.
pub fn scale<A: ScalingAlgorithm>( &self, width: u32, height: u32 ) -> Image<Box<[u8]>, 1>
scale only.Scale a Y image with a given scaling algorithm.
sourcepub fn scale<A: ScalingAlgorithm>(
&self,
width: u32,
height: u32
) -> Image<Box<[u8]>, 3>
Available on crate feature scale only.
pub fn scale<A: ScalingAlgorithm>( &self, width: u32, height: u32 ) -> Image<Box<[u8]>, 3>
scale only.Scale a RGB image with a given scaling algorithm.
sourcepub unsafe fn repeated(
&self,
out_width: u32,
out_height: u32
) -> Image<Vec<u8>, 3>
pub unsafe fn repeated( &self, out_width: u32, out_height: u32 ) -> Image<Vec<u8>, 3>
Tile self till it fills a new image of size x, y
§Safety
UB if self’s width is not a multiple of x, or self’s height is not a multiple of y
let x: Image<&[u8], 3> = Image::build(8, 8).buf(include_bytes!("../benches/3_8x8.imgbuf"));
let tiled = unsafe { x.repeated(48, 48) }; // repeat 6 timessourcepub fn to_owned(&self) -> Image<Vec<T>, CHANNELS>
pub fn to_owned(&self) -> Image<Vec<T>, CHANNELS>
Allocate a new Image<Vec<T>> from this imageref.
sourcepub fn to_owned(&self) -> Image<Vec<T>, CHANNELS>
pub fn to_owned(&self) -> Image<Vec<T>, CHANNELS>
Allocate a new Image<Vec<T>> from this mutable imageref.
sourcepub fn chunked<'a, U: 'a>(
&'a self
) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]>
pub fn chunked<'a, U: 'a>( &'a self ) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]>
Returns a iterator over every pixel
sourcepub fn flatten<U>(&self) -> &[[U; CHANNELS]]
pub fn flatten<U>(&self) -> &[[U; CHANNELS]]
Flatten the chunks of this image into a slice of slices.
sourcepub fn cloner(&self) -> ImageCloner<'_, CHANNELS>
pub fn cloner(&self) -> ImageCloner<'_, CHANNELS>
Procure a ImageCloner.
sourcepub fn save(&self, f: impl AsRef<Path>)
Available on crate feature save only.
pub fn save(&self, f: impl AsRef<Path>)
save only.Save this RGB image.
sourcepub fn save(&self, f: impl AsRef<Path>)
Available on crate feature save only.
pub fn save(&self, f: impl AsRef<Path>)
save only.Save this RGBA image.
Trait Implementations§
source§impl ClonerOverlay<4, 3> for ImageCloner<'_, 3>
impl ClonerOverlay<4, 3> for ImageCloner<'_, 3>
source§impl ClonerOverlay<4, 4> for ImageCloner<'_, 4>
impl ClonerOverlay<4, 4> for ImageCloner<'_, 4>
source§impl ClonerOverlayAt<3, 3> for ImageCloner<'_, 3>
impl ClonerOverlayAt<3, 3> for ImageCloner<'_, 3>
source§impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3>
impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3>
source§impl ClonerOverlayAt<4, 4> for ImageCloner<'_, 4>
impl ClonerOverlayAt<4, 4> for ImageCloner<'_, 4>
Auto Trait Implementations§
impl<'a, const C: usize> RefUnwindSafe for ImageCloner<'a, C>
impl<'a, const C: usize> Send for ImageCloner<'a, C>
impl<'a, const C: usize> Sync for ImageCloner<'a, C>
impl<'a, const C: usize> Unpin for ImageCloner<'a, C>
impl<'a, const C: usize> UnwindSafe for ImageCloner<'a, C>
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
§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.