#[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>
impl<const CHANNELS: usize, T: AsMut<[u8]> + AsRef<[u8]>> Image<T, CHANNELS>
source§impl<T: AsRef<[u8]> + AsMut<[u8]>> Image<T, 2>
impl<T: AsRef<[u8]> + AsMut<[u8]>> Image<T, 2>
sourcepub fn blur(&mut self, radius: usize)
Available on crate feature blur
only.
pub fn blur(&mut self, radius: usize)
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>
impl<T: AsRef<[u8]> + AsMut<[u8]>> Image<T, 3>
sourcepub fn blur(&mut self, radius: usize)
Available on crate feature blur
only.
pub fn blur(&mut self, radius: usize)
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>
impl<T: AsRef<[u8]> + AsMut<[u8]>> Image<T, 4>
sourcepub fn blur(&mut self, radius: usize)
Available on crate feature blur
only.
pub fn blur(&mut self, radius: usize)
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: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub fn box(
&mut self,
(x1, y1): (u32, u32),
width: u32,
height: u32,
c: [u8; CHANNELS]
)
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§impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub fn border_circle(
&mut self,
(xc, yc): (i32, i32),
radius: i32,
c: [u8; CHANNELS]
)
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§impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub fn line(&mut self, a: (i32, i32), b: (i32, i32), color: [u8; CHANNELS])
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.
sourcepub fn thick_line(
&mut self,
a: impl Into<Vec2>,
b: impl Into<Vec2>,
stroke: f32,
color: [u8; CHANNELS]
)
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>
impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub fn points(&mut self, poly: &[(i32, i32)], c: [u8; CHANNELS])
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]);
sourcepub fn quad(
&mut self,
a: (i32, i32),
b: (i32, i32),
c: (i32, i32),
d: (i32, i32),
col: [u8; CHANNELS]
)
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.
sourcepub fn poly(
&mut self,
pos: impl Into<Vec2>,
sides: usize,
radius: f32,
rotation: f32,
c: [u8; CHANNELS]
)
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]);
sourcepub fn border_poly(
&mut self,
pos: impl Into<Vec2>,
sides: usize,
radius: f32,
rotation: f32,
stroke: f32,
c: [u8; CHANNELS]
)
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>
impl<const N: usize, T> Image<T, N>
sourcepub 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.
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>,
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>
impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub 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]
)
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>
impl<T, const C: usize> Image<T, 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
source§impl<T: AsRef<[u8]>> Image<T, 4>
impl<T: AsRef<[u8]>> Image<T, 4>
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
.
source§impl Image<Box<[u8]>, 4>
impl Image<Box<[u8]>, 4>
sourcepub fn download(
dev: &Device,
q: &Queue,
texture: &Texture,
(width, height): (NonZeroU32, NonZeroU32)
) -> Self
Available on crate feature wgpu-convert
only.
pub fn download( dev: &Device, q: &Queue, texture: &Texture, (width, height): (NonZeroU32, NonZeroU32) ) -> Self
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 Image<&[u8], 3>
impl Image<&[u8], 3>
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 times
source§impl<T, const CHANNELS: usize> Image<T, CHANNELS>
impl<T, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub const unsafe fn new(
width: NonZeroU32,
height: NonZeroU32,
buffer: T
) -> Self
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
sourcepub fn take_buffer(self) -> T
pub fn take_buffer(self) -> T
consumes the image, returning the image buffer
sourcepub unsafe fn buffer_mut(&mut self) -> &mut T
pub unsafe fn buffer_mut(&mut self) -> &mut T
source§impl<T, const CHANNELS: usize> Image<T, CHANNELS>
impl<T, const CHANNELS: usize> Image<T, CHANNELS>
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.
source§impl<T: AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
impl<T: AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub fn cloner(&self) -> ImageCloner<'_, CHANNELS>
pub fn cloner(&self) -> ImageCloner<'_, CHANNELS>
Procure a ImageCloner
.
source§impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
impl<T: AsMut<[u8]> + AsRef<[u8]>, const CHANNELS: usize> Image<T, CHANNELS>
sourcepub fn chunked_mut(&mut self) -> impl Iterator<Item = &mut [u8; CHANNELS]>
pub fn chunked_mut(&mut self) -> impl Iterator<Item = &mut [u8; CHANNELS]>
Returns a iterator over every pixel, mutably
sourcepub fn flatten_mut(&mut self) -> &mut [[u8; CHANNELS]]
pub fn flatten_mut(&mut self) -> &mut [[u8; CHANNELS]]
Flatten the chunks of this image into a mutable slice of slices.
source§impl<const CHANNELS: usize, T: ?Sized> Image<Box<T>, CHANNELS>
impl<const CHANNELS: usize, T: ?Sized> Image<Box<T>, CHANNELS>
sourcepub fn leak(self) -> Image<&'static mut T, CHANNELS>
pub fn leak(self) -> Image<&'static mut T, CHANNELS>
Consumes and leaks this image, returning a reference to the 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>
impl<const A: usize, const B: usize, T: AsMut<[u8]> + AsRef<[u8]>, U: AsRef<[u8]>> BlendingOverlay<Image<U, B>> for Image<T, A>
source§unsafe fn overlay_blended(&mut self, with: &Image<U, B>) -> &mut Self
unsafe fn overlay_blended(&mut self, with: &Image<U, B>) -> &mut Self
source§impl<T: Clone, const CHANNELS: usize> Clone for Image<T, CHANNELS>
impl<T: Clone, const CHANNELS: usize> Clone for Image<T, CHANNELS>
source§fn clone(&self) -> Self
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)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: PartialEq, const CHANNELS: usize> PartialEq for Image<T, CHANNELS>
impl<T: PartialEq, const CHANNELS: usize> PartialEq for Image<T, CHANNELS>
impl<const CHANNELS: usize> Copy for Image<&[u8], CHANNELS>
impl<T: Eq, const CHANNELS: usize> Eq for Image<T, CHANNELS>
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> 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.