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>

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 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 to_owned(&self) -> Image<Vec<T>, CHANNELS>

Allocate a new Image<Vec<T>> from this mutable 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]>
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 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 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>

§

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

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

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

§

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.
§

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.
§

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.
§

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.
§

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

§

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

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
§

impl<T> Upcast<T> for T

§

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

§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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