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 chunked<'a, U: 'a>(
&'a self,
) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]> + ExactSizeIterator
pub fn chunked<'a, U: 'a>( &'a self, ) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]> + ExactSizeIterator
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 get_pixel<U: Copy>(&self, x: u32, y: u32) -> Option<[U; CHANNELS]>
pub fn get_pixel<U: Copy>(&self, x: u32, y: u32) -> Option<[U; CHANNELS]>
Get a pixel. Optionally. Yeah!
Sourcepub fn cols<U: Copy>(
&self,
) -> impl DoubleEndedIterator + ExactSizeIterator<Item = impl ExactSizeIterator + DoubleEndedIterator<Item = [U; CHANNELS]> + '_>
pub fn cols<U: Copy>( &self, ) -> impl DoubleEndedIterator + ExactSizeIterator<Item = impl ExactSizeIterator + DoubleEndedIterator<Item = [U; CHANNELS]> + '_>
iterator over columns returned iterator returns a iterator for each column
┌ ┐┌ ┐┌ ┐
│1││2││3│
│4││5││6│
│7││8││9│
└ ┘└ ┘└ ┘let img: Image<&[u8],1> = Image::build(2, 3).buf(&[
1, 5,
2, 4,
7, 9
]);
assert_eq!(
img.cols().map(|x| x.collect::<Vec<_>>()).collect::<Vec<_>>(),
[[[1], [2], [7]], [[5], [4], [9]]]
);Sourcepub fn rows<'a, U: 'a>(
&'a self,
) -> impl ExactSizeIterator + DoubleEndedIterator<Item = &'a [[U; CHANNELS]]>
pub fn rows<'a, U: 'a>( &'a self, ) -> impl ExactSizeIterator + DoubleEndedIterator<Item = &'a [[U; CHANNELS]]>
iterator over rows returns a iterator over each row
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]let img: Image<&[u8],1> = Image::build(2, 3).buf(&[
1, 5,
2, 4,
7, 9
]);
assert_eq!(
img.rows().collect::<Vec<_>>(),
[[[1], [5]], [[2], [4]], [[7], [9]]]
);Sourcepub fn ordered(
&self,
) -> impl ExactSizeIterator + DoubleEndedIterator<Item = (u32, u32)> + use<T, CHANNELS>
pub fn ordered( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator<Item = (u32, u32)> + use<T, CHANNELS>
Itearte the pixels of this image in parse order.
use Image::chunked if you just want the pixels.
Sourcepub fn serpent(
&self,
) -> impl ExactSizeIterator + Iterator<Item = (u32, u32)> + use<T, CHANNELS>
pub fn serpent( &self, ) -> impl ExactSizeIterator + Iterator<Item = (u32, u32)> + use<T, CHANNELS>
Iterate the pixels of this image in serpentine order.
§Safety
The points are guaranteed to be on the image.
Sourcepub unsafe fn pixels_of<'l, U: Copy>(
&'l self,
iterator: impl ExactSizeIterator<Item = (u32, u32)> + 'l,
) -> impl ExactSizeIterator<Item = [U; CHANNELS]> + 'l
pub unsafe fn pixels_of<'l, U: Copy>( &'l self, iterator: impl ExactSizeIterator<Item = (u32, u32)> + 'l, ) -> impl ExactSizeIterator<Item = [U; CHANNELS]> + 'l
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> Freeze for ImageCloner<'a, C>
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.