fast image operations
Diffstat (limited to 'src/pack.rs')
| -rw-r--r-- | src/pack.rs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/src/pack.rs b/src/pack.rs deleted file mode 100644 index e9ae84a..0000000 --- a/src/pack.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! trait for packing pixels - -use crate::pixels::convert::{PFrom, RGB, RGBA, Y, YA}; - -#[inline] -pub const fn pack(x: [u8; 4]) -> u32 { - u32::from_le_bytes(x).rotate_left(8).swap_bytes() -} - -#[inline] -pub const fn unpack(n: u32) -> [u8; 4] { - n.rotate_left(8).to_be_bytes() -} - -/// packs and unpacks this pixel -/// note that `unpack(pack(p))` may not equal `p` -pub trait Pack<P = u32> { - /// pack this pixel - fn pack(&self) -> P; - /// unpacks this pixel - fn unpack(from: P) -> Self; -} - -macro_rules! simple { - ($p:ident) => { - impl Pack for $p { - fn pack(&self) -> u32 { - pack(PFrom::pfrom(*self)) - } - - fn unpack(from: u32) -> $p { - PFrom::pfrom(unpack(from)) - } - } - }; -} -simple!(RGBA); -simple!(RGB); -simple!(YA); -simple!(Y); - -impl Pack<u8> for Y { - fn pack(&self) -> u8 { - self[0] - } - - fn unpack(from: u8) -> Self { - [from] - } -} |