fast image operations
add `Image::fill`
bendn 2023-12-06
parent 5839881 · commit b7c9127
-rw-r--r--Cargo.toml2
-rw-r--r--src/builder.rs14
2 files changed, 15 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index a84d271..f9bc1e6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "fimg"
-version = "0.4.28"
+version = "0.4.29"
authors = ["bend-n <[email protected]>"]
license = "MIT"
edition = "2021"
diff --git a/src/builder.rs b/src/builder.rs
index bff5e7c..6ae970e 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -61,6 +61,20 @@ impl<const C: usize> Builder<Vec<u8>, C> {
}
}
+impl<T: Copy, const C: usize> Builder<Box<[T]>, C> {
+ /// Fill this image with a certain pixel.
+ /// ```
+ /// # use fimg::Image;
+ ///
+ /// // fill black
+ /// Image::build(50, 50).fill([0, 0, 0, 255]);
+ /// ```
+ pub fn fill(self, with: [T; C]) -> Image<Box<[T]>, C> {
+ Image::build(self.width, self.height)
+ .buf((0..self.width * self.height).flat_map(|_| with).collect())
+ }
+}
+
/// seals the [`Buffer`] trait
mod buf {
/// A valid buffer for use in the builder