pub mod bytecast;
pub mod error;
pub mod util;
pub mod structs;
pub mod decoder;
pub mod encoder;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ByteOrder {
BigEndian,
LittleEndian,
}
macro_rules! cast_fn {
($name:ident, $type:ty, $length:literal) => {
#[inline(always)]
pub fn $name(&self, bytes: [u8; $length]) -> $type {
match self {
ByteOrder::LittleEndian => <$type>::from_le_bytes(bytes),
ByteOrder::BigEndian => <$type>::from_be_bytes(bytes),
}
}
};
}
impl ByteOrder {
cast_fn!(u8, u8, 1);
cast_fn!(i8, i8, 1);
cast_fn!(u16, u16, 2);
cast_fn!(i16, i16, 2);
cast_fn!(u32, u32, 4);
cast_fn!(i32, i32, 4);
cast_fn!(u64, u64, 8);
cast_fn!(i64, i64, 8);
cast_fn!(f32, f32, 4);
cast_fn!(f64, f64, 8);
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ChunkType {
Strip,
Tile,
}
#[derive(Copy, PartialEq, Eq, Debug, Clone, Hash)]
pub enum ColorType {
Gray(u8),
RGB(u8),
Palette(u8),
GrayA(u8),
RGBA(u8),
CMYK(u8),
YCbCr(u8),
Multiband { bit_depth: u8, num_samples: u16 },
}
impl ColorType {
fn bit_depth(&self) -> u8 {
match *self {
ColorType::Gray(b)
| ColorType::RGB(b)
| ColorType::Palette(b)
| ColorType::GrayA(b)
| ColorType::RGBA(b)
| ColorType::CMYK(b)
| ColorType::YCbCr(b)
| ColorType::Multiband { bit_depth: b, .. } => b,
}
}
}