1use std::mem;
2
3#[derive(Debug, Copy, Clone)]
4pub struct ColorCharacteristics {
5 pub cp: ColourPrimaries,
6 pub mc: MatrixCoefficients,
7 pub tc: TransferCharacteristic,
8}
9
10impl ColorCharacteristics {
11 pub fn or(self, other: Self) -> Self {
12 Self {
13 cp: if matches!(self.cp, ColourPrimaries::Unspecified) {
14 other.cp
15 } else {
16 self.cp
17 },
18 mc: if matches!(self.mc, MatrixCoefficients::Unspecified) {
19 other.mc
20 } else {
21 self.mc
22 },
23 tc: if matches!(self.tc, TransferCharacteristic::Unspecified) {
24 other.tc
25 } else {
26 self.tc
27 },
28 }
29 }
30}
31
32#[derive(Debug, Copy, Clone)]
34#[repr(u8)]
35pub enum ColourPrimaries {
36 Forbidden = 0,
37 BT709 = 1,
38 Unspecified = 2,
39 Reserved = 3,
40 FCC = 4,
41 BT601_625 = 5,
42 BT601_525 = 6,
43 Smpte240m = 7,
44 }
46
47impl ColourPrimaries {
48 pub fn from_byte(byte: u8) -> Self {
49 if byte > ColourPrimaries::Smpte240m as u8 {
50 Self::Reserved
51 } else {
52 unsafe { mem::transmute::<u8, ColourPrimaries>(byte) }
53 }
54 }
55}
56
57#[derive(Debug, Copy, Clone)]
59#[repr(u8)]
60pub enum TransferCharacteristic {
61 Forbidden = 0,
62 BT709 = 1,
63 Unspecified = 2,
64 Reserved = 3,
65 Gamma22 = 4,
66 Gamma28 = 5,
67 BT601 = 6,
68 }
70
71impl TransferCharacteristic {
72 pub fn from_byte(byte: u8) -> Self {
73 assert!(byte <= TransferCharacteristic::BT601 as u8);
74 unsafe { mem::transmute::<u8, TransferCharacteristic>(byte) }
75 }
76}
77
78#[derive(Debug, Copy, Clone)]
80#[repr(u8)]
81pub enum MatrixCoefficients {
82 Forbidden = 0,
83 BT709 = 1,
84 Unspecified = 2,
85 Reserved = 3,
86 FCC = 4,
87 BT601_625 = 5,
88 BT601_525 = 6,
89 Smpte240m = 7,
90 YCgCo = 8,
91 }
93
94impl MatrixCoefficients {
95 pub fn from_byte(byte: u8) -> Self {
96 if byte > MatrixCoefficients::YCgCo as u8 {
97 Self::Reserved
98 } else {
99 unsafe { mem::transmute::<u8, MatrixCoefficients>(byte) }
100 }
101 }
102}