mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 18:38:21 -06:00
add make()
This commit is contained in:
parent
58a769292b
commit
5139fa82f7
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "fimg"
|
name = "fimg"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
authors = ["bend-n <bend.n@outlook.com>"]
|
authors = ["bend-n <bend.n@outlook.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
27
src/lib.rs
27
src/lib.rs
|
@ -3,9 +3,11 @@
|
||||||
//! Provides fast image operations, such as rotation, flipping, and overlaying.
|
//! Provides fast image operations, such as rotation, flipping, and overlaying.
|
||||||
#![feature(
|
#![feature(
|
||||||
slice_swap_unchecked,
|
slice_swap_unchecked,
|
||||||
|
generic_const_exprs,
|
||||||
slice_as_chunks,
|
slice_as_chunks,
|
||||||
unchecked_math,
|
unchecked_math,
|
||||||
portable_simd,
|
portable_simd,
|
||||||
|
const_option,
|
||||||
array_chunks,
|
array_chunks,
|
||||||
test
|
test
|
||||||
)]
|
)]
|
||||||
|
@ -19,7 +21,7 @@
|
||||||
clippy::dbg_macro,
|
clippy::dbg_macro,
|
||||||
missing_docs
|
missing_docs
|
||||||
)]
|
)]
|
||||||
#![allow(clippy::zero_prefixed_literal)]
|
#![allow(clippy::zero_prefixed_literal, incomplete_features)]
|
||||||
|
|
||||||
use std::{num::NonZeroU32, slice::SliceIndex};
|
use std::{num::NonZeroU32, slice::SliceIndex};
|
||||||
|
|
||||||
|
@ -140,6 +142,29 @@ impl<const CHANNELS: usize> Image<&[u8], CHANNELS> {
|
||||||
buffer: self.buffer,
|
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> {
|
impl<T: std::ops::Deref<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
|
|
Loading…
Reference in a new issue