use core::cmp::Ordering;
#[derive(Copy, Clone, Debug, Eq, PartialEq,Default)]
#[non_exhaustive]
pub enum BitDepth {
Eight,
Sixteen,
Float32,
#[default]
Unknown,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum BitType {
U8,
U16,
F32,
}
impl BitType {
pub fn to_depth(self) -> BitDepth {
match self {
BitType::U8 => BitDepth::Eight,
BitType::U16 => BitDepth::Sixteen,
BitType::F32 => BitDepth::Float32,
}
}
}
impl core::cmp::PartialOrd for BitType {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl core::cmp::Ord for BitType {
fn cmp(&self, other: &Self) -> Ordering {
if self == other {
core::cmp::Ordering::Equal
} else if *self == BitType::U8 {
core::cmp::Ordering::Less
} else if *self == BitType::U16 && *other == BitType::F32 {
core::cmp::Ordering::Less
} else if *self == BitType::F32 {
core::cmp::Ordering::Greater
} else {
unreachable!()
}
}
}
impl BitDepth {
#[rustfmt::skip]
#[allow(clippy::zero_prefixed_literal)]
pub const fn max_value(self) -> u16
{
match self
{
Self::Eight => (1 << 08) - 1,
Self::Sixteen => u16::MAX,
Self::Float32 => 1,
Self::Unknown => 0,
}
}
pub const fn bit_type(self) -> BitType {
match self {
Self::Eight => BitType::U8,
Self::Sixteen => BitType::U16,
Self::Float32 => BitType::F32,
Self::Unknown => panic!("Unknown bit type"),
}
}
pub const fn size_of(self) -> usize {
match self {
Self::Eight => core::mem::size_of::<u8>(),
Self::Sixteen => core::mem::size_of::<u16>(),
Self::Float32 => core::mem::size_of::<f32>(),
Self::Unknown => panic!("Unknown bit type"),
}
}
pub const fn bit_size(&self) -> usize {
self.size_of() * 8
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ByteEndian {
LE,
BE,
}