pixels_u32/lib.rs
1use pixels::Pixels;
2
3/// Extends the Pixel structure interface in the Pixels crate.
4pub trait PixelsExt {
5 /// Provides a 32-bit slice rather than the 8-bit one using `get_frame`.
6 fn get_frame_u32(&mut self) -> &mut [u32];
7}
8
9/// Implements the extra methods for Pixels.
10impl PixelsExt for Pixels {
11 fn get_frame_u32(&mut self) -> &mut [u32] {
12 if let Ok(slice) = bytemuck::try_cast_slice_mut::<u8, u32>(self.get_frame()) {
13 slice
14 } else {
15 panic!("Pixels are not aligned on a 4-byte boundary");
16 }
17 }
18}