#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum PixelFormat {
Argb8888 = 0,
Xrgb8888 = 1,
Abgr8888 = 2,
Xbgr8888 = 3,
}
pub fn fourcc_to_format(fourcc: u32) -> Option<PixelFormat> {
match fourcc {
0x34325241 => Some(PixelFormat::Argb8888), 0x34325258 => Some(PixelFormat::Xrgb8888), 0x34324241 => Some(PixelFormat::Abgr8888), 0x34324258 => Some(PixelFormat::Xbgr8888), _ => None,
}
}
pub fn convert_to_rgba(data: &mut [u8], format: PixelFormat) {
match format {
PixelFormat::Xrgb8888 => {
for chunk in data.chunks_exact_mut(4) {
chunk.swap(0, 2);
chunk[3] = 255;
}
}
PixelFormat::Argb8888 => {
for chunk in data.chunks_exact_mut(4) {
chunk.swap(0, 2);
}
}
PixelFormat::Xbgr8888 => {
for chunk in data.chunks_exact_mut(4) {
chunk[3] = 255;
}
}
PixelFormat::Abgr8888 => {}
}
}