Struct Image

Source
#[repr(C)]
pub struct Image<T, const CHANNELS: usize> { /* private fields */ }
Expand description

A image with a variable number of channels, and a nonzero size.

Implementations§

Source§

impl<const CHANNELS: usize, T: AsMut<[u8]> + AsRef<[u8]>> Image<T, CHANNELS>

Source

pub fn flip_v(&mut self)

Flip an image vertically.

Source

pub fn flip_h(&mut self)

Flip an image horizontally.

Source§

impl<const CHANNELS: usize, T: AsMut<[u8]> + AsRef<[u8]>> Image<T, CHANNELS>

Source

pub fn rot_180(&mut self)

Rotate an image 180 degrees clockwise.

Source

pub unsafe fn rot_90(&mut self)

Rotate an image 90 degrees clockwise.

§Safety

UB if the image is not square

Source

pub unsafe fn rot_270(&mut self)

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

§Safety

UB if the image is not square

Source§

impl<T: AsMut<[u32]> + AsRef<[u32]>> Image<T, 1>

Source

pub fn blur_argb(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image of packed 32 bit integers, [0xAARRGGBB].

Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>> Image<T, 4>

Source

pub fn blur_in(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image.

Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>> Image<T, 2>

Source

pub fn blur_in(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image.

Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>> Image<T, 3>

Source

pub fn blur_in(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image.

let mut i = Image::alloc(300, 300).boxed();
// draw a trongle
i.poly((150., 150.), 3, 100.0, 0.0, [255, 255, 255]);
// give it some blur
i.blur_in(25);
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>> Image<T, 1>

Source

pub fn blur(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image. No copy.

let mut i = Image::alloc(300, 300);
// draw a lil pentagon
i.poly((150., 150.), 5, 100.0, 0.0, [255]);
// give it some blur
i.blur(25);
Source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> Image<T, 2>

Source

pub fn blur(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image. This will allocate a Image<Box<[u32]>, 1>. If you want no copy, but slower if you dont have a simd-able cpu, check out Image::blur_in.

let mut i = Image::alloc(300, 300);
// draw a sqar
i.poly((150., 150.), 4, 100.0, 0.0, [255]);
// give it some blur
i.blur(25);
Source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> Image<T, 3>

Source

pub fn blur(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image. This will allocate a Image<Box<[u32]>, 1>. If you want no copy, but slower if you dont have a simd-able cpu, check out Image::blur_in.

let mut i = Image::alloc(300, 300);
// draw a sqar
i.poly((150., 150.), 4, 100.0, 0.0, [255]);
// give it some blur
i.blur(25);
Source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> Image<T, 4>

Source

pub fn blur(&mut self, radius: usize)

Available on crate feature blur only.

Blur a image. This will allocate a Image<Box<[u32]>, 1>. If you want no copy, but slower if you dont have a simd-able cpu, check out Image::blur_in.

let mut i = Image::alloc(300, 300);
// draw a sqar
i.poly((150., 150.), 4, 100.0, 0.0, [255]);
// give it some blur
i.blur(25);
Source§

impl<B, const C: usize> Image<B, C>

Source

pub const fn build<I>(w: u32, h: u32) -> Builder<B, C>
where B: AsRef<[I]>,

creates a builder

Source§

impl<const N: usize, T: AsRef<[u8]>> Image<T, N>

Source

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

just an into wrapper

Source§

impl<const N: usize, T: AsRef<[f32]>> Image<T, N>

Source

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

just an into wrapper

Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>

Source

pub fn box( &mut self, (x1, y1): (u32, u32), width: u32, height: u32, c: [u8; CHANNELS], )

Draw a bordered box

let mut b = Image::alloc(10, 9);
b.as_mut().r#box((1, 1), 7, 6, [255]);
Source

pub fn filled_box( &mut self, (x1, y1): (u32, u32), width: u32, height: u32, c: [u8; CHANNELS], )

Draw a filled box.

let mut b = Image::alloc(10, 9);
b.as_mut().filled_box((1, 1), 7, 6, [255]);
Source

pub fn stroked_box( &mut self, (x1, y1): (u32, u32), width: u32, height: u32, stroke: u32, c: [u8; CHANNELS], )

Draw a stroked box

let mut b = Image::alloc(11, 11);
b.as_mut().stroked_box((2, 2), 6, 6, 2, [255]);
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>

Source

pub fn border_circle( &mut self, (xc, yc): (i32, i32), radius: i32, c: [u8; CHANNELS], )

Draws a circle, using the Bresenham’s circle algorithm.

let mut i = Image::alloc(50, 50);
i.border_circle((25, 25), 20, [255]);
Source

pub fn circle(&mut self, (xc, yc): (i32, i32), radius: i32, c: [u8; CHANNELS])

Draw a filled circle.

let mut i = Image::alloc(50, 50);
i.circle((25, 25), 20, [255]);
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>

Source

pub fn line(&mut self, a: (i32, i32), b: (i32, i32), color: [u8; CHANNELS])

Draw a line from point a to point b.

Points not in bounds will not be included.

Source

pub fn thick_line( &mut self, a: impl Into<Vec2>, b: impl Into<Vec2>, stroke: f32, color: [u8; CHANNELS], )

Draw a thick line from point a to point b. Prefer Image::line when possible.

Points not in bounds will not be included.

Uses Image::quad.

let mut i = Image::alloc(10, 10);
i.thick_line((2.0, 2.0), (8.0, 8.0), 2.0, [255]);
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>

Source

pub fn points(&mut self, poly: &[(i32, i32)], c: [u8; CHANNELS])

Draws a filled polygon from a slice of points. Please close your poly. (first == last)

Borrowed from imageproc, modified for less allocations.

let mut i = Image::alloc(10, 10);
i.points(&[(1, 8), (3, 1), (8, 1), (6, 6), (8, 8), (1, 8)], [255]);
Source

pub fn quad( &mut self, a: (i32, i32), b: (i32, i32), c: (i32, i32), d: (i32, i32), col: [u8; CHANNELS], )

Draws a filled quadrilateral. This currently just uses Image::points, but in the future this may change.

Source

pub fn poly( &mut self, pos: impl Into<Vec2>, sides: usize, radius: f32, rotation: f32, c: [u8; CHANNELS], )

Draws a regular convex polygon with a specified number of sides, a radius, and a rotation (radians). Prefer Image::circle over poly(.., 600, ..). Calls into Image::tri and Image::quad.

let mut i = Image::alloc(300, 300);
//          draw a enneagon
// at  x150, y150    │  unrotated   white
// with a radius of ─┼──╮      │      │
i.poly((150., 150.), 9, 100.0, 0.0, [255]);
Source

pub fn border_poly( &mut self, pos: impl Into<Vec2>, sides: usize, radius: f32, rotation: f32, stroke: f32, c: [u8; CHANNELS], )

Draw a bordered polygon. Prefer Image::border_circle to draw circles. See also Image::poly.

let mut i = fimg::Image::alloc(100, 100);
i.border_poly((50., 50.), 5, 25., 0., 7., [255]);
Source§

impl<const N: usize, T> Image<T, N>

Source

pub fn text<const P: usize>( &mut self, x: u32, y: u32, size: f32, font: &Font, text: &str, color: [u8; P], )
where Image<T, N>: Text<P>,

Available on crate feature text only.

Draw text.

let font = fontdue::Font::from_bytes(
    &include_bytes!("../../data/CascadiaCode.ttf")[..],
    fontdue::FontSettings {
        scale: 200.0,
        ..Default::default()
    },
).unwrap();
let mut i: Image<_, 4> = Image::alloc(750, 250).boxed();
i.text(50, 10, 200.0, &font, "hello", [0, 0, 0, 255]);
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>

Source

pub fn tri<F: Float<f32>>( &mut self, a: impl Into<Vector2<F>>, b: impl Into<Vector2<F>>, c: impl Into<Vector2<F>>, col: [u8; CHANNELS], )

Draw a (filled) triangle

let mut a = Image::alloc(10, 10);
// draw a triangle
a.as_mut().tri::<f32>(
  (3.0, 2.0), // point a
  (8.0, 7.0), // point b
  (1.0, 8.0), // point c
  [255] // white
);
Source§

impl<T, const C: usize> Image<T, 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 crop_mut<'a, U: 'a>( &'a mut self, width: u32, height: u32, ) -> impl Cropper<&'a mut [U], C>
where T: AsMut<[U]> + AsRef<[U]>,

Like Image::crop, but returns a mutable SubImage.

Source§

impl<T, const N: usize> Image<T, N>

Source

pub fn wgpu_size(&self) -> Extent3d

Available on crate feature wgpu-convert only.

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

Source§

impl<T: AsRef<[u8]>> Image<T, 4>

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§

impl Image<Box<[u8]>, 4>

Source

pub fn download( dev: &Device, q: &Queue, texture: &Texture, (width, height): (NonZeroU32, NonZeroU32), ) -> Self

Available on crate feature wgpu-convert only.

Downloads a purportedly TextureFormat::Rgba8Unorm image from the gpu.

§Panics

When a “error occurs while trying to async map a buffer”.

Source§

impl<T: AsRef<[u8]>> Image<T, 1>

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§

impl<T: AsMut<[u8]> + AsRef<[u8]>> Image<T, 2>

Source

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

Available on crate feature scale only.

Scale a YA image with a given scaling algorithm.

Source§

impl<T: AsRef<[u8]>> Image<T, 3>

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§

impl<T: AsMut<[u8]> + AsRef<[u8]>> Image<T, 4>

Source

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

Available on crate feature scale only.

Scale a RGBA image with a given scaling algorithm.

Source§

impl Image<Vec<u8>, 1>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Vec<u8>, 2>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Vec<u8>, 3>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Vec<u8>, 4>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Box<[u8]>, 1>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Box<[u8]>, 2>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Box<[u8]>, 3>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Box<[u8]>, 4>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<&[u8], 1>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<&[u8], 2>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<&[u8], 3>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<&[u8], 4>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<Box<[u32]>, 1>

Source

pub fn show(self) -> Self

Available on crate features save or real-show only.

Open a window showing this image. Blocks until the window finishes.

This is like dbg! for images.

§Panics

if the window is un creatable

Source§

impl Image<&[u8], 3>

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§

impl<T, const CHANNELS: usize> Image<T, CHANNELS>

Source

pub const fn height(&self) -> u32

get the height as a u32

Source

pub const fn width(&self) -> u32

get the width as a u32

Source

pub const unsafe fn new( width: NonZeroU32, height: NonZeroU32, buffer: T, ) -> Self

create a new image

§Safety

does not check that buffer.len() == w * h * C

using this with invalid values may result in future UB

Source

pub fn take_buffer(self) -> T

consumes the image, returning the image buffer

Source

pub const fn buffer(&self) -> &T

returns a immutable reference to the backing buffer

Source

pub unsafe fn buffer_mut(&mut self) -> &mut T

returns a mutable(!) reference to the backing buffer

§Safety

please do not change buffer size.

Source§

impl<const CHANNELS: usize, T: Clone> Image<&[T], CHANNELS>

Source

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

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

Source§

impl<const CHANNELS: usize, T: Clone> Image<&mut [T], CHANNELS>

Source

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

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

Source§

impl<const CHANNELS: usize> Image<&[u8], CHANNELS>

Source

pub const fn copy(&self) -> Self

Copy this ref image

Source

pub const fn make<'a, const WIDTH: u32, const HEIGHT: u32>() -> Image<&'a [u8], CHANNELS>
where [(); { _ }]:,

Create a new immutable image of width x, y.

§Panics

if width || height == 0

let img = Image::make::<5, 5>();
Source§

impl<const CHANNELS: usize, const N: usize, T> Image<[T; N], CHANNELS>

Source

pub fn boxed(self) -> Image<Box<[T]>, CHANNELS>

Box this array image.

Source§

impl<const CHANNELS: usize, T: Copy> Image<&[T], CHANNELS>

Source

pub fn boxed(self) -> Image<Box<[T]>, CHANNELS>

Box this image.

Source§

impl<const CHANNELS: usize, T> Image<Vec<T>, CHANNELS>

Source

pub fn boxed(self) -> Image<Box<[T]>, CHANNELS>

Box this owned image.

Source§

impl<const CHANNELS: usize, T> Image<Box<[T]>, CHANNELS>

Source

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

Unbox this vec image.

Source§

impl<T, const CHANNELS: usize> Image<T, CHANNELS>

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_mut<U>(&mut self) -> Image<&mut [U], CHANNELS>
where T: AsMut<[U]>,

Create a mutref to this image

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 replace<U: Copy>( &mut self, x: u32, y: u32, f: impl FnOnce([U; CHANNELS]) -> [U; CHANNELS], ) -> Option<[U; CHANNELS]>
where T: AsRef<[U]> + AsMut<[U]>,

Returns a [PixelEntry]

Source

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

Return a mutable reference to a pixel at (x, y).

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

pub fn get_pixel_mut<U>(&mut self, x: u32, y: u32) -> Option<&mut [U; CHANNELS]>
where T: AsMut<[U]> + AsRef<[U]>,

Returns a mutable reference to a pixel at (x, y), if (x, y) is in bounds.

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§

impl<T: AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>

Source

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

Bytes of this image.

Source

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

Procure a ImageCloner.

Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>

Source

pub fn chunked_mut(&mut self) -> impl Iterator<Item = &mut [u8; CHANNELS]>

Returns a iterator over every pixel, mutably

Source

pub fn flatten_mut(&mut self) -> &mut [[u8; CHANNELS]]

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

Source

pub unsafe fn set_pixel(&mut self, x: u32, y: u32, px: [u8; CHANNELS])

Set the pixel at x, y

§Safety

UB if x, y is out of bounds.

Source§

impl<const CHANNELS: usize> Image<&mut [u8], CHANNELS>

Source

pub fn copy(&mut self) -> Image<&mut [u8], CHANNELS>

Copy this ref image

Source§

impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS>

Source

pub fn alloc(width: u32, height: u32) -> Self

Allocates a new image. If width and height are constant, try using make.

§Panics

if width || height == 0

Source

pub fn leak(self) -> Image<&'static mut [u8], CHANNELS>

Consumes and leaks this image, returning a reference to the image.

Source§

impl<const CHANNELS: usize, T: ?Sized> Image<Box<T>, CHANNELS>

Source

pub fn leak(self) -> Image<&'static mut T, CHANNELS>

Consumes and leaks this image, returning a reference to the image.

Source§

impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS>
where [(); { _ }]:,

Source

pub fn open(f: impl AsRef<Path>) -> Self

Available on crate feature save only.

Open a PNG image

Source§

impl<T: AsRef<[u8]>> Image<T, 3>

Source

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

Available on crate feature save only.

Save this RGB image.

Source§

impl<T: AsRef<[u8]>> Image<T, 4>

Source

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

Available on crate feature save only.

Save this RGBA image.

Source§

impl<T: AsRef<[u8]>> Image<T, 2>

Source

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

Available on crate feature save only.

Save this YA image.

Source§

impl<T: AsRef<[u8]>> Image<T, 1>

Source

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

Available on crate feature save only.

Save this Y image.

Trait Implementations§

Source§

impl<const A: usize, const B: usize, T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> BlendingOverlay<Image<U, B>> for Image<T, A>
where [u8; A]: Blend<B>,

Source§

unsafe fn overlay_blended(&mut self, with: &Image<U, B>) -> &mut Self

Overlay with => self, blending. You probably do not need this, unless your images make much usage of alpha. If you only have 2 alpha states, 0 | 255 (transparent | opaque), please use Overlay, as it is much faster. Read more
Source§

impl<const A: usize, const B: usize, T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> BlendingOverlayAt<Image<U, B>> for Image<T, A>
where [u8; A]: Blend<B>,

Source§

unsafe fn overlay_blended_at( &mut self, with: &Image<U, B>, x: u32, y: u32, ) -> &mut Self

Source§

impl<T: Clone, const CHANNELS: usize> Clone for Image<T, CHANNELS>

Source§

fn clone(&self) -> Self

Returns a duplicate of this image.

let new_i = i.clone();

If you find yourself in the pattern of

let mut i = i.clone();
unsafe { i.rot_90() };

STOP!

Instead use

let i = unsafe { i.cloner().rot_90() };
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const CHANNELS: usize> Debug for Image<T, CHANNELS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, const N: usize> Display for Image<&'a [u8], N>
where [(); N]: Basic,

Available on crate feature term only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Display an image in the terminal.

Source§

impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 1>

Source§

fn from(value: DynImage<Box<[u8]>>) -> Self

Converts to this type from the input type.
Source§

impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 2>

Source§

fn from(value: DynImage<Box<[u8]>>) -> Self

Converts to this type from the input type.
Source§

impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 3>

Source§

fn from(value: DynImage<Box<[u8]>>) -> Self

Converts to this type from the input type.
Source§

impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 4>

Source§

fn from(value: DynImage<Box<[u8]>>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<Image<&[f32], N>> for Image<Box<[u8]>, N>

Source§

fn from(value: Image<&[f32], N>) -> Self

Expand to 0-255 from 0.0-1.0

Source§

impl<const N: usize> From<Image<&[u32], 1>> for Image<Box<[u8]>, N>
where [u8; N]: Pack,

Source§

fn from(value: Image<&[u32], 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 1>> for Image<Box<[u8]>, 1>

Source§

fn from(value: Image<&[u8], 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 1>> for Image<Box<[u8]>, 2>

Source§

fn from(value: Image<&[u8], 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 1>> for Image<Box<[u8]>, 3>

Source§

fn from(value: Image<&[u8], 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 1>> for Image<Box<[u8]>, 4>

Source§

fn from(value: Image<&[u8], 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 2>> for Image<Box<[u8]>, 1>

Source§

fn from(value: Image<&[u8], 2>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 2>> for Image<Box<[u8]>, 2>

Source§

fn from(value: Image<&[u8], 2>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 2>> for Image<Box<[u8]>, 3>

Source§

fn from(value: Image<&[u8], 2>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 2>> for Image<Box<[u8]>, 4>

Source§

fn from(value: Image<&[u8], 2>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 3>> for Image<Box<[u8]>, 1>

Source§

fn from(value: Image<&[u8], 3>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 3>> for Image<Box<[u8]>, 2>

Source§

fn from(value: Image<&[u8], 3>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 3>> for Image<Box<[u8]>, 3>

Source§

fn from(value: Image<&[u8], 3>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 3>> for Image<Box<[u8]>, 4>

Source§

fn from(value: Image<&[u8], 3>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 4>> for Image<Box<[u8]>, 1>

Source§

fn from(value: Image<&[u8], 4>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 4>> for Image<Box<[u8]>, 2>

Source§

fn from(value: Image<&[u8], 4>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 4>> for Image<Box<[u8]>, 3>

Source§

fn from(value: Image<&[u8], 4>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<&[u8], 4>> for Image<Box<[u8]>, 4>

Source§

fn from(value: Image<&[u8], 4>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<Image<&[u8], N>> for Image<Box<[f32]>, N>

Source§

fn from(value: Image<&[u8], N>) -> Self

Reduce to 0.0-1.0 from 0-255.

Source§

impl<const N: usize> From<Image<&[u8], N>> for Image<Box<[u32]>, 1>
where [u8; N]: Pack,

Source§

fn from(value: Image<&[u8], N>) -> Self

Pack into ARGB.

Source§

impl From<Image<Box<[u8]>, 1>> for Image<Box<[u8]>, 2>

Source§

fn from(value: Image<Box<[u8]>, 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 1>> for Image<Box<[u8]>, 3>

Source§

fn from(value: Image<Box<[u8]>, 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 1>> for Image<Box<[u8]>, 4>

Source§

fn from(value: Image<Box<[u8]>, 1>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 2>> for Image<Box<[u8]>, 1>

Source§

fn from(value: Image<Box<[u8]>, 2>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 2>> for Image<Box<[u8]>, 3>

Source§

fn from(value: Image<Box<[u8]>, 2>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 2>> for Image<Box<[u8]>, 4>

Source§

fn from(value: Image<Box<[u8]>, 2>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 3>> for Image<Box<[u8]>, 1>

Source§

fn from(value: Image<Box<[u8]>, 3>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 3>> for Image<Box<[u8]>, 2>

Source§

fn from(value: Image<Box<[u8]>, 3>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 3>> for Image<Box<[u8]>, 4>

Source§

fn from(value: Image<Box<[u8]>, 3>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 4>> for Image<Box<[u8]>, 1>

Source§

fn from(value: Image<Box<[u8]>, 4>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 4>> for Image<Box<[u8]>, 2>

Source§

fn from(value: Image<Box<[u8]>, 4>) -> Self

Converts to this type from the input type.
Source§

impl From<Image<Box<[u8]>, 4>> for Image<Box<[u8]>, 3>

Source§

fn from(value: Image<Box<[u8]>, 4>) -> Self

Converts to this type from the input type.
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> Overlay<Image<U, 4>> for Image<T, 3>

Source§

unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self

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

impl<T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> Overlay<Image<U, 4>> for Image<T, 4>

Source§

unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self

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

impl<T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> OverlayAt<Image<U, 3>> for Image<T, 3>

Source§

unsafe fn overlay_at(&mut self, with: &Image<U, 3>, x: u32, y: u32) -> &mut Self

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<U: AsRef<[u8]>> OverlayAt<Image<U, 3>> for Image<u8, 3>

Source§

unsafe fn overlay_at(&mut self, with: &Image<U, 3>, x: u32, y: u32) -> &mut Self

Overlay with => self at coordinates x, y, without blending Read more
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> OverlayAt<Image<U, 4>> for Image<T, 3>

Source§

unsafe fn overlay_at(&mut self, with: &Image<U, 4>, x: u32, y: u32) -> &mut Self

Overlay with => self at coordinates x, y, without blending Read more
Source§

impl<T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> OverlayAt<Image<U, 4>> for Image<T, 4>

Source§

unsafe fn overlay_at(&mut self, with: &Image<U, 4>, x: u32, y: u32) -> &mut Self

Overlay with => self at coordinates x, y, without blending Read more
Source§

impl<U: AsRef<[u8]>> OverlayAt<Image<U, 4>> for Image<u8, 3>

Source§

unsafe fn overlay_at(&mut self, with: &Image<U, 4>, x: u32, y: u32) -> &mut Self

Overlay with => self at coordinates x, y, without blending Read more
Source§

impl<T: PartialEq, const CHANNELS: usize> PartialEq for Image<T, CHANNELS>

Source§

fn eq(&self, other: &Image<T, CHANNELS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ReadPng for Image<Box<[u8]>, 1>

Available on crate feature save only.
Source§

fn read(f: &mut impl Read) -> Result<Self>

Open a PNG image

Source§

impl ReadPng for Image<Box<[u8]>, 2>

Available on crate feature save only.
Source§

fn read(f: &mut impl Read) -> Result<Self>

Open a PNG image

Source§

impl ReadPng for Image<Box<[u8]>, 3>

Available on crate feature save only.
Source§

fn read(f: &mut impl Read) -> Result<Self>

Open a PNG image

Source§

impl ReadPng for Image<Box<[u8]>, 4>

Available on crate feature save only.
Source§

fn read(f: &mut impl Read) -> Result<Self>

Open a PNG image

Source§

impl<T: AsRef<[u8]>> WritePng for Image<T, 1>

Available on crate feature save only.
Source§

fn write(&self, f: &mut impl Write) -> Result<()>

Save this Y image.

Source§

impl<T: AsRef<[u8]>> WritePng for Image<T, 2>

Available on crate feature save only.
Source§

fn write(&self, f: &mut impl Write) -> Result<()>

Save this YA image.

Source§

impl<T: AsRef<[u8]>> WritePng for Image<T, 3>

Available on crate feature save only.
Source§

fn write(&self, f: &mut impl Write) -> Result<()>

Save this RGB image.

Source§

impl<T: AsRef<[u8]>> WritePng for Image<T, 4>

Available on crate feature save only.
Source§

fn write(&self, f: &mut impl Write) -> Result<()>

Save this RGBA image.

Source§

impl<const CHANNELS: usize> Copy for Image<&[u8], CHANNELS>

Source§

impl<T: Eq, const CHANNELS: usize> Eq for Image<T, CHANNELS>

Source§

impl<T, const CHANNELS: usize> StructuralPartialEq for Image<T, CHANNELS>

Auto Trait Implementations§

§

impl<T, const CHANNELS: usize> Freeze for Image<T, CHANNELS>
where T: Freeze,

§

impl<T, const CHANNELS: usize> RefUnwindSafe for Image<T, CHANNELS>
where T: RefUnwindSafe,

§

impl<T, const CHANNELS: usize> Send for Image<T, CHANNELS>
where T: Send,

§

impl<T, const CHANNELS: usize> Sync for Image<T, CHANNELS>
where T: Sync,

§

impl<T, const CHANNELS: usize> Unpin for Image<T, CHANNELS>
where T: Unpin,

§

impl<T, const CHANNELS: usize> UnwindSafe for Image<T, CHANNELS>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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,