fast image operations
add Image::boxed
| -rw-r--r-- | benches/drawing.rs | 6 | ||||
| -rw-r--r-- | src/lib.rs | 16 |
2 files changed, 19 insertions, 3 deletions
diff --git a/benches/drawing.rs b/benches/drawing.rs index b0668d3..8375bf3 100644 --- a/benches/drawing.rs +++ b/benches/drawing.rs @@ -1,7 +1,7 @@ use fimg::*; fn tri() { - let mut i: Image<_, 4> = fimg::make!(4 channels 1000 x 1000); - i.as_mut() - .tri((0., 0.), (1000., 500.), (0., 999.), [255, 255, 255, 255]); + let mut i: Image<_, 4> = fimg::make!(4 channels 1000 x 1000).boxed(); + i.tri((0., 0.), (1000., 500.), (0., 999.), [255, 255, 255, 255]); + std::hint::black_box(i); } iai::main!(tri); @@ -243,6 +243,22 @@ impl<const CHANNELS: usize> Image<&[u8], CHANNELS> { } } +impl<const CHANNELS: usize, const N: usize> Image<[u8; N], CHANNELS> { + /// Box this array image. + pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> { + // SAFETY: ctor + unsafe { Image::new(self.width, self.height, Box::new(self.buffer)) } + } +} + +impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS> { + /// Box this owned image. + pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> { + // SAFETY: ctor + unsafe { Image::new(self.width, self.height, self.buffer.into_boxed_slice()) } + } +} + #[macro_export] /// Create a <code>[Image]<[[u8]; N], C></code> with ease. If your looking for a <code>[Image]<&'static [[u8]]></code>, try [`Image::make`]. /// |