mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 10:28:21 -06:00
add Image::boxed
This commit is contained in:
parent
f465e25077
commit
a0f555439e
|
@ -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);
|
||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -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`].
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue