fast image operations
Diffstat (limited to 'src/indexed.rs')
| -rw-r--r-- | src/indexed.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/indexed.rs b/src/indexed.rs index dfa00ac..426565d 100644 --- a/src/indexed.rs +++ b/src/indexed.rs @@ -2,6 +2,8 @@ #![allow(private_bounds)] mod builder; +use std::mem::MaybeUninit; + use crate::Image; #[allow(non_camel_case_types)] @@ -40,7 +42,8 @@ impl<I, P> IndexedImage<I, P> { self.buffer.map(|x| { x.as_ref() .iter() - .flat_map(|x| self.palette.as_ref()[x.nat()]) + // SAFETY: invariant. + .flat_map(|x| *self.palette.as_ref().get_unchecked(x.nat())) .collect() }) } @@ -104,3 +107,13 @@ impl<I, P> IndexedImage<I, P> { .ok_or("not all indexes are in palette") } } +impl<P, I: uint> IndexedImage<Box<[MaybeUninit<I>]>, P> { + /// Assumes this MU image is, in fact, initialized. You must be very sure that it is. Also, none of the pixels can be out of bounds. + pub unsafe fn assume_init(self) -> IndexedImage<Box<[I]>, P> { + IndexedImage { + // SAFETY: it really isnt. + buffer: unsafe { self.buffer.mapped(|x| x.assume_init()) }, + ..self + } + } +} |