fast image operations
Diffstat (limited to 'src/builder.rs')
-rw-r--r--src/builder.rs14
1 files changed, 14 insertions, 0 deletions
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