mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 10:28:21 -06:00
add make()
This commit is contained in:
parent
58a769292b
commit
5139fa82f7
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "fimg"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
authors = ["bend-n <bend.n@outlook.com>"]
|
||||
license = "MIT"
|
||||
edition = "2021"
|
||||
|
|
27
src/lib.rs
27
src/lib.rs
|
@ -3,9 +3,11 @@
|
|||
//! Provides fast image operations, such as rotation, flipping, and overlaying.
|
||||
#![feature(
|
||||
slice_swap_unchecked,
|
||||
generic_const_exprs,
|
||||
slice_as_chunks,
|
||||
unchecked_math,
|
||||
portable_simd,
|
||||
const_option,
|
||||
array_chunks,
|
||||
test
|
||||
)]
|
||||
|
@ -19,7 +21,7 @@
|
|||
clippy::dbg_macro,
|
||||
missing_docs
|
||||
)]
|
||||
#![allow(clippy::zero_prefixed_literal)]
|
||||
#![allow(clippy::zero_prefixed_literal, incomplete_features)]
|
||||
|
||||
use std::{num::NonZeroU32, slice::SliceIndex};
|
||||
|
||||
|
@ -140,6 +142,29 @@ impl<const CHANNELS: usize> Image<&[u8], CHANNELS> {
|
|||
buffer: self.buffer,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new immutable image of width x, y.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// if width || height == 0
|
||||
///
|
||||
/// ```
|
||||
/// # use fimg::Image;
|
||||
/// let img = Image::make::<5, 5>();
|
||||
/// # let img: Image<_, 4> = img;
|
||||
/// ```
|
||||
|
||||
pub const fn make<'a, const WIDTH: u32, const HEIGHT: u32>() -> Image<&'a [u8], CHANNELS>
|
||||
where
|
||||
[(); CHANNELS * WIDTH as usize * HEIGHT as usize]: Sized,
|
||||
{
|
||||
Image {
|
||||
width: NonZeroU32::new(WIDTH).expect("passed zero width to builder"),
|
||||
height: NonZeroU32::new(HEIGHT).expect("passed zero height to builder"),
|
||||
buffer: &[0; CHANNELS * WIDTH as usize * HEIGHT as usize],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: std::ops::Deref<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||
|
|
Loading…
Reference in a new issue