aom_decode/color.rs
1//! Color space metadata of a decoded frame
2//!
3//! These enums describe the frame's metadata, as defined by the
4//! “Colour information” (CICP) section of [ITU-T H.273](https://www.itu.int/rec/T-REC-H.273).
5//!
6//! They are the frame's own description of its pixel data — pass them to
7//! the [yuv](https://lib.rs/yuv) crate to convert pixels to RGB.
8
9/// Chroma subsampling format
10#[derive(Debug, Copy, Clone, Eq, PartialEq)]
11pub enum ChromaSampling {
12 /// 4:2:0 = 2x2 pixels of luma per 1 pixel of chroma
13 Cs420,
14 /// 4:2:2 = Horizontally subsampled
15 Cs422,
16 /// 4:4:4 = Not subsampled (chroma and luma are 1:1)
17 Cs444,
18 /// 4:0:0 = Only luma (grayscale)
19 Monochrome,
20}
21
22/// Range of allowed values for pixels
23#[repr(C)]
24#[derive(Debug, Copy, Clone, Eq, PartialEq)]
25pub enum Range {
26 /// Luma is 16-235, Chroma is 16-240
27 Limited,
28 /// 0-255
29 Full,
30}
31
32/// Supported color primaries, as defined by “Color primaries” section of ISO/IEC 23091-4/ITU-T H.273
33#[repr(C)]
34#[derive(Debug, Copy, Clone, Eq, PartialEq)]
35pub enum ColorPrimaries {
36 /// BT.709, sRGB, sYCC. BT.709 is the standard for high definition (HD) television; sRGB is the most common color space used for computer displays.
37 BT709 = 1,
38 /// BT.470 System M, NTSC (standard definition television in the United States) (historical)
39 BT470M = 4,
40 /// BT.470 System B, G; BT.601; BT.1358 625; BT.1700 625 PAL and 625 SECAM (historical)
41 BT470BG,
42 /// BT.601-7 525 (SMPTE 170 M) and SMPTE 240M (historical)
43 BT601,
44 /// ITU-T H.264
45 GenericFilm = 8,
46 /// BT.2020; BT.2100. Used for ultra-high definition (4K) High Dynamic Range (HDR) video, these have a very wide color gamut and support 10-bit and 12-bit color component depths.
47 BT2020,
48 /// CIE 1921 XYZ; SMPTE ST 428 (D-Cinema Distribution Master: Image characteristics). Defines the uncompressed image characteristics for DCDM.
49 XYZ,
50 /// SMPTE RP 431 (D-Cinema Quality: Reference projector and environment).
51 SMPTE431,
52 /// SMPTE EG 432-1 (Digital Source Processing: Color Processing for D-Cinema).
53 SMPTE432,
54 /// EBU Tech. 3213-E
55 EBU3213 = 22,
56}
57
58/// Gamma correction, essentially, as defined by “Transfer characteristics” section of ISO/IEC 23091-4/ITU-T H.273.
59#[repr(C)]
60#[derive(Debug, Copy, Clone, Eq, PartialEq)]
61pub enum TransferCharacteristics {
62 /// BT.709
63 BT709 = 1,
64 /// BT.470 System M (historical)
65 BT470M = 4,
66 /// BT.470 System B, G (historical)
67 BT470BG,
68 /// BT.601-7 525 (SMPTE 170 M)
69 BT601,
70 /// SMPTE 240 M
71 SMPTE240,
72 /// Linear
73 Linear,
74 /// Logarithmic (100:1 range)
75 Log100,
76 /// Logarithmic ((100 * √10):1 range)
77 Log100Sqrt10,
78 /// IEC 61966-2-4
79 IEC61966,
80 /// BT.1361 extended color gamut system (historical)
81 BT1361,
82 /// sRGB or sYCC
83 SRGB,
84 /// BT.2020 10-bit systems
85 BT2020_10Bit,
86 /// BT.2020 12-bit systems
87 BT2020_12Bit,
88 /// SMPTE ST 2084, ITU BT.2100 PQ
89 SMPTE2084,
90 /// SMPTE ST 428
91 SMPTE428,
92 /// BT.2100 HLG (Hybrid Log Gamma), ARIB STD-B67
93 HLG,
94}
95
96/// Bit depth (8 = 1 byte, >=10 = 2 bytes)
97#[repr(C)]
98#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord)]
99pub enum Depth {
100 Depth8 = 8,
101 Depth10 = 10,
102 Depth12 = 12,
103 Depth16 = 16,
104}
105
106impl Depth {
107 /// Number of bits used by each pixel component
108 #[inline(always)]
109 #[must_use]
110 pub const fn bits(self) -> u32 {
111 self as u32
112 }
113}
114
115/// As defined by the “Matrix coefficients” section of ISO/IEC 23091-4/ITU-T H.273.
116#[repr(C)]
117#[derive(Debug, Copy, Clone, Eq, PartialEq)]
118pub enum MatrixCoefficients {
119 /// Identity matrix
120 Identity = 0,
121 /// BT.709 ITU-R Rec. BT.709-5, ITU-R Rec. BT.1361 conventional colour gamut system and extended colour gamut system,
122 /// IEC 61966-2-4 xvYCC709,
123 /// Society of Motion Picture and Television Engineers RP 177 (1993)
124 /// KR = 0.2126; KB = 0.0722
125 BT709,
126 /// United States Federal Communications Commission Title 47 Code of Federal Regulations (2003) 73.682 (a) (20)
127 /// KR = 0.30; KB = 0.11
128 FCC = 4,
129 /// ITU-R Rec. BT.470-6 System B,G, IEC 61966-2-4 xvYCC601 (historical)
130 /// KR = 0.299; KB = 0.114
131 BT470BG,
132 /// BT.601-7 525 (SMPTE 170 M)
133 /// KR = 0.299; KB = 0.114
134 BT601,
135 /// SMPTE 240 M
136 /// KR = 0.212; KB = 0.087
137 SMPTE240,
138 /// `YCgCo`
139 YCgCo,
140 /// BT.2020 non-constant luminance, BT.2100 YCbCr
141 BT2020NCL,
142 /// BT.2020 constant luminance
143 BT2020CL,
144 /// SMPTE ST 2085 `YDzDx`
145 SMPTE2085,
146 /// Chromaticity-derived non-constant luminance
147 ChromatNCL,
148 /// Chromaticity-derived constant luminance
149 ChromatCL,
150 /// BT.2020 `ICtCp`
151 ICtCp,
152}
153
154/// Alignment of the chroma channels
155#[repr(C)]
156#[derive(Debug, Copy, Clone, Eq, PartialEq)]
157pub enum ChromaSamplePosition {
158 /// Horizontally co-located with (0, 0) luma sample, vertically positioned
159 /// in the middle between two luma samples.
160 Vertical,
161 /// Co-located with (0, 0) luma sample.
162 Colocated,
163}