1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3#[repr(u32)]
4pub enum PixelFormat {
5 Argb8888 = 0,
7 Xrgb8888 = 1,
9 Abgr8888 = 2,
11 Xbgr8888 = 3,
13}
14
15pub fn fourcc_to_format(fourcc: u32) -> Option<PixelFormat> {
17 match fourcc {
18 0x34325241 => Some(PixelFormat::Argb8888), 0x34325258 => Some(PixelFormat::Xrgb8888), 0x34324241 => Some(PixelFormat::Abgr8888), 0x34324258 => Some(PixelFormat::Xbgr8888), _ => None,
23 }
24}
25
26pub fn convert_to_rgba(data: &mut [u8], format: PixelFormat) {
31 match format {
32 PixelFormat::Xrgb8888 => {
33 for chunk in data.chunks_exact_mut(4) {
34 chunk.swap(0, 2);
35 chunk[3] = 255;
36 }
37 }
38 PixelFormat::Argb8888 => {
39 for chunk in data.chunks_exact_mut(4) {
40 chunk.swap(0, 2);
41 }
42 }
43 PixelFormat::Xbgr8888 => {
44 for chunk in data.chunks_exact_mut(4) {
45 chunk[3] = 255;
46 }
47 }
48 PixelFormat::Abgr8888 => {}
49 }
50}