use core::fmt;
use std::fmt::{Display, Formatter};
use crate::utils::four_char_code::FourCharCode;
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum PixelFormat {
#[default]
BGRA,
l10r,
YCbCr_420v,
YCbCr_420f,
xf44,
RGhA,
}
impl Display for PixelFormat {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let c: FourCharCode = (*self).into();
write!(f, "{}", c.display())
}
}
impl From<PixelFormat> for FourCharCode {
fn from(val: PixelFormat) -> Self {
match val {
PixelFormat::BGRA => Self::from_bytes(*b"BGRA"),
PixelFormat::l10r => Self::from_bytes(*b"l10r"),
PixelFormat::YCbCr_420v => Self::from_bytes(*b"420v"),
PixelFormat::YCbCr_420f => Self::from_bytes(*b"420f"),
PixelFormat::xf44 => Self::from_bytes(*b"xf44"),
PixelFormat::RGhA => Self::from_bytes(*b"RGhA"),
}
}
}
impl From<u32> for PixelFormat {
fn from(value: u32) -> Self {
let c = FourCharCode::from_u32(value);
c.into()
}
}
impl From<FourCharCode> for PixelFormat {
fn from(val: FourCharCode) -> Self {
match val.display().as_str() {
"l10r" => Self::l10r,
"420v" => Self::YCbCr_420v,
"420f" => Self::YCbCr_420f,
"xf44" => Self::xf44,
"RGhA" => Self::RGhA,
_ => Self::BGRA, }
}
}