Struct 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>

Source

pub fn flip_v(&self) -> Image<Vec<u8>, CHANNELS>

Flip an image vertically.

let a = Image::<_, 1>::build(2,2).buf(vec![21,42,90,01]);
assert_eq!(a.cloner().flip_v().take_buffer(), [90,01,21,42]);
Source

pub fn flip_h(&self) -> Image<Vec<u8>, CHANNELS>

Flip an image horizontally

let a = Image::<_,1>::build(2,2).buf(vec![90,01,21,42]);
assert_eq!(a.cloner().flip_h().take_buffer(), [01,90,42,21]);
Source§

impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS>

Source

pub fn rot_180(&self) -> Image<Vec<u8>, CHANNELS>

Rotate an image 180 degrees clockwise.

let a = Image::<_,1>::build(2,2).buf(vec![00,01,02,10]);
assert_eq!(a.cloner().rot_180().take_buffer(), vec![10,02,01,00]);
Source

pub unsafe fn rot_90(&self) -> Image<Vec<u8>, CHANNELS>

Rotate an image 90 degrees clockwise.

§Safety

UB if the image is not square

Source

pub unsafe fn rot_270(&self) -> Image<Vec<u8>, CHANNELS>

Rotate an image 270 degrees clockwise, or 90 degrees anti clockwise.

§Safety

UB if the image is not square

Source§

impl<'a, const C: usize> ImageCloner<'a, C>

Source

pub const fn from(i: Image<&'a [u8], C>) -> Self

Create a ImageCloner from a Image<&[u8]>

Methods from Deref<Target = Image<&'a [u8], C>>§

Source

pub fn to_f32(&self) -> Image<Box<[f32]>, N>

just an into wrapper

Source

pub fn to_u8(&self) -> Image<Box<[u8]>, N>

just an into wrapper

Source

pub fn crop<'a, U: 'a>( &'a self, width: u32, height: u32, ) -> impl Cropper<&'a [U], C>
where T: AsRef<[U]>,

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 Image<Box<[T], _>> back.

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

Source

pub fn wgpu_size(&self) -> Extent3d

Available on crate feature wgpu-convert only.

Get the size as a [wgpu::Extend3d].

Source

pub fn send(&self, dev: &Device, q: &Queue, usage: TextureUsages) -> Texture

Available on crate feature wgpu-convert only.

Upload this image to the gpu, returning a wgpu::Texture.

Source

pub fn scale<A: ScalingAlgorithm>( &self, width: u32, height: u32, ) -> Image<Box<[u8]>, 1>

Available on crate feature scale only.

Scale a Y image with a given scaling algorithm.

Source

pub fn scale<A: ScalingAlgorithm>( &self, width: u32, height: u32, ) -> Image<Box<[u8]>, 3>

Available on crate feature scale only.

Scale a RGB image with a given scaling algorithm.

Source

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 times
Source

pub fn height(&self) -> u32

get the height as a u32

Source

pub fn width(&self) -> u32

get the width as a u32

Source

pub fn buffer(&self) -> &T

returns a immutable reference to the backing buffer

Source

pub fn to_owned(&self) -> Image<Vec<T>, CHANNELS>

Allocate a new Image<Vec<T>> from this imageref.

Source

pub fn copy(&self) -> Self

Copy this ref image

Source

pub fn len<U>(&self) -> usize
where T: AsRef<[U]>,

The size of the underlying buffer.

Source

pub fn chunked<'a, U: 'a>( &'a self, ) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]> + ExactSizeIterator
where T: AsRef<[U]>,

Returns a iterator over every pixel

Source

pub fn flatten<U>(&self) -> &[[U; CHANNELS]]
where T: AsRef<[U]>,

Flatten the chunks of this image into a slice of slices.

Source

pub fn as_ref<U>(&self) -> Image<&[U], CHANNELS>
where T: AsRef<[U]>,

Reference this image.

Source

pub fn get_pixel<U: Copy>(&self, x: u32, y: u32) -> Option<[U; CHANNELS]>
where T: AsRef<[U]>,

Get a pixel. Optionally. Yeah!

Source

pub unsafe fn pixel<U: Copy>(&self, x: u32, y: u32) -> [U; CHANNELS]
where T: AsRef<[U]>,

Return a pixel at (x, y).

§Safety
  • UB if x, y is out of bounds
  • UB if buffer is too small
Source

pub fn cols<U: Copy>( &self, ) -> impl DoubleEndedIterator + ExactSizeIterator<Item = impl ExactSizeIterator + DoubleEndedIterator<Item = [U; CHANNELS]> + '_>
where T: AsRef<[U]>,

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]]]
);
Source

pub fn rows<'a, U: 'a>( &'a self, ) -> impl ExactSizeIterator + DoubleEndedIterator<Item = &'a [[U; CHANNELS]]>
where T: AsRef<[U]>,

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]]]
);
Source

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.

Source

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.

Source

pub unsafe fn pixels_of<'l, U: Copy>( &'l self, iterator: impl ExactSizeIterator<Item = (u32, u32)> + 'l, ) -> impl ExactSizeIterator<Item = [U; CHANNELS]> + 'l
where T: AsRef<[U]>,

Get the pixels from an iterator.

§Safety

the points must be on the image.

Source

pub fn bytes(&self) -> &[u8]

Bytes of this image.

Source

pub fn cloner(&self) -> ImageCloner<'_, CHANNELS>

Procure a ImageCloner.

Source

pub fn save(&self, f: impl AsRef<Path>)

Available on crate feature save only.

Save this RGB image.

Source

pub fn save(&self, f: impl AsRef<Path>)

Available on crate feature save only.

Save this RGBA image.

Source

pub fn save(&self, f: impl AsRef<Path>)

Available on crate feature save only.

Save this YA image.

Source

pub fn save(&self, f: impl AsRef<Path>)

Available on crate feature save only.

Save this Y image.

Trait Implementations§

Source§

impl ClonerOverlay<4, 3> for ImageCloner<'_, 3>

Source§

unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 3>

Overlay with => self (does not blend) Read more
Source§

impl ClonerOverlay<4, 4> for ImageCloner<'_, 4>

Source§

unsafe fn overlay(&self, with: &Image<&[u8], 4>) -> Image<Vec<u8>, 4>

Overlay with => self (does not blend) Read more
Source§

impl ClonerOverlayAt<3, 3> for ImageCloner<'_, 3>

Source§

unsafe fn overlay_at( &self, with: &Image<&[u8], 3>, x: u32, y: u32, ) -> Image<Vec<u8>, 3>

Overlay a RGB image(with) => self at coordinates x, y. As this is a RGBxRGB operation, blending is unnecessary, and this is simply a copy.

§Safety

UB if x, y is out of bounds

Source§

impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3>

Source§

unsafe fn overlay_at( &self, with: &Image<&[u8], 4>, x: u32, y: u32, ) -> Image<Vec<u8>, 3>

Overlay with => self at coordinates x, y, without blending, and returning a new image. Read more
Source§

impl ClonerOverlayAt<4, 4> for ImageCloner<'_, 4>

Source§

unsafe fn overlay_at( &self, with: &Image<&[u8], 4>, x: u32, y: u32, ) -> Image<Vec<u8>, 4>

Overlay with => self at coordinates x, y, without blending, and returning a new image. Read more
Source§

impl<'a, const C: usize> Deref for ImageCloner<'a, C>

Source§

type Target = Image<&'a [u8], C>

The resulting type after dereferencing.
Source§

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

Dereferences the value.

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> 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Join<T, 1, 1, T> for T

Source§

fn join(self, with: T) -> [T; 2]

Join a array and an scalar together. For joining two arrays together, see Couple. Read more
Source§

impl<T, const O: usize> Join<T, 1, O, [T; O]> for T

Source§

fn join(self, with: [T; O]) -> [T; { _ }]

Join a array and an scalar together. For joining two arrays together, see Couple. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,