screencapturekit/stream/configuration/
pixel_format.rs1use core::fmt;
6use std::fmt::{Display, Formatter};
7
8use crate::utils::four_char_code::FourCharCode;
9
10#[allow(non_camel_case_types)]
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
24pub enum PixelFormat {
25 #[default]
27 BGRA,
28 l10r,
30 YCbCr_420v,
32 YCbCr_420f,
34}
35impl Display for PixelFormat {
36 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
37 let c: FourCharCode = (*self).into();
38 write!(f, "{}", c.display())
39 }
40}
41
42impl From<PixelFormat> for FourCharCode {
43 fn from(val: PixelFormat) -> Self {
44 match val {
46 PixelFormat::BGRA => Self::from_bytes(*b"BGRA"),
47 PixelFormat::l10r => Self::from_bytes(*b"l10r"),
48 PixelFormat::YCbCr_420v => Self::from_bytes(*b"420v"),
49 PixelFormat::YCbCr_420f => Self::from_bytes(*b"420f"),
50 }
51 }
52}
53impl From<u32> for PixelFormat {
54 fn from(value: u32) -> Self {
55 let c = FourCharCode::from_bytes(value.to_le_bytes());
57 c.into()
58 }
59}
60impl From<FourCharCode> for PixelFormat {
61 fn from(val: FourCharCode) -> Self {
62 match val.display().as_str() {
63 "BGRA" => Self::BGRA,
64 "l10r" => Self::l10r,
65 "420v" => Self::YCbCr_420v,
66 "420f" => Self::YCbCr_420f,
67 _ => unreachable!("Unknown pixel format"),
68 }
69 }
70}