fast image operations
add buf_unchecked
bendn 2025-01-31
parent a197434 · commit 3c69b5e
-rw-r--r--src/indexed/builder.rs10
-rw-r--r--src/lib.rs4
2 files changed, 13 insertions, 1 deletions
diff --git a/src/indexed/builder.rs b/src/indexed/builder.rs
index b00c12f..e8b5ad1 100644
--- a/src/indexed/builder.rs
+++ b/src/indexed/builder.rs
@@ -57,6 +57,16 @@ impl<B, P> Builder<B, P> {
.unwrap()
}
+ pub unsafe fn buf_unchecked<I>(self, buffer: B) -> Image<B, P>
+ where
+ B: AsRef<[I]>,
+ {
+ Image {
+ buffer: crate::Image::build(self.width, self.height).buf(buffer),
+ palette: self.palette.expect("require palette"),
+ }
+ }
+
/// Allocates a zeroed buffer.
#[track_caller]
#[must_use]
diff --git a/src/lib.rs b/src/lib.rs
index bbc83c4..6ce1813 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -485,7 +485,9 @@ impl<T, const CHANNELS: usize> Image<T, CHANNELS> {
#[inline]
/// Returns a iterator over every pixel
- pub fn chunked<'a, U: 'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]>
+ pub fn chunked<'a, U: 'a>(
+ &'a self,
+ ) -> impl DoubleEndedIterator<Item = &'a [U; CHANNELS]> + ExactSizeIterator
where
T: AsRef<[U]>,
{