1 | // Copyright (c) 2019-2022, The rav1e contributors. All rights reserved |
2 | // |
3 | // This source code is subject to the terms of the BSD 2 Clause License and |
4 | // the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
5 | // was not distributed with this source code in the LICENSE file, you can |
6 | // obtain it at www.aomedia.org/license/software. If the Alliance for Open |
7 | // Media Patent License 1.0 was not distributed with this source code in the |
8 | // PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
9 | |
10 | use crate::serialize::*; |
11 | use crate::wasm_bindgen::*; |
12 | |
13 | use arg_enum_proc_macro::ArgEnum; |
14 | use num_derive::FromPrimitive; |
15 | |
16 | /// Sample position for subsampled chroma |
17 | #[wasm_bindgen ] |
18 | #[derive ( |
19 | Copy, |
20 | Clone, |
21 | Debug, |
22 | PartialEq, |
23 | Eq, |
24 | FromPrimitive, |
25 | Serialize, |
26 | Deserialize, |
27 | Default, |
28 | )] |
29 | #[repr (C)] |
30 | pub enum ChromaSamplePosition { |
31 | /// The source video transfer function must be signaled |
32 | /// outside the AV1 bitstream. |
33 | #[default] |
34 | Unknown, |
35 | /// Horizontally co-located with (0, 0) luma sample, vertically positioned |
36 | /// in the middle between two luma samples. |
37 | Vertical, |
38 | /// Co-located with (0, 0) luma sample. |
39 | Colocated, |
40 | } |
41 | |
42 | pub use v_frame::pixel::ChromaSampling; |
43 | |
44 | /// Supported Color Primaries |
45 | /// |
46 | /// As defined by “Color primaries” section of ISO/IEC 23091-4/ITU-T H.273 |
47 | #[derive ( |
48 | ArgEnum, |
49 | Debug, |
50 | Clone, |
51 | Copy, |
52 | PartialEq, |
53 | Eq, |
54 | FromPrimitive, |
55 | Serialize, |
56 | Deserialize, |
57 | Default, |
58 | )] |
59 | #[repr (C)] |
60 | pub enum ColorPrimaries { |
61 | /// BT.709 |
62 | BT709 = 1, |
63 | /// Unspecified, must be signaled or inferred outside of the bitstream |
64 | #[default] |
65 | Unspecified, |
66 | /// BT.470 System M (historical) |
67 | BT470M = 4, |
68 | /// BT.470 System B, G (historical) |
69 | BT470BG, |
70 | /// BT.601-7 525 (SMPTE 170 M) |
71 | BT601, |
72 | /// SMPTE 240M (historical) |
73 | SMPTE240, |
74 | /// Generic film |
75 | GenericFilm, |
76 | /// BT.2020, BT.2100 |
77 | BT2020, |
78 | /// SMPTE 248 (CIE 1921 XYZ) |
79 | XYZ, |
80 | /// SMPTE RP 431-2 |
81 | SMPTE431, |
82 | /// SMPTE EG 432-1 |
83 | SMPTE432, |
84 | /// EBU Tech. 3213-E |
85 | EBU3213 = 22, |
86 | } |
87 | |
88 | /// Supported Transfer Characteristics |
89 | /// |
90 | /// As defined by “Transfer characteristics” section of ISO/IEC 23091-4/ITU-TH.273. |
91 | #[derive ( |
92 | ArgEnum, |
93 | Debug, |
94 | Clone, |
95 | Copy, |
96 | PartialEq, |
97 | Eq, |
98 | FromPrimitive, |
99 | Serialize, |
100 | Deserialize, |
101 | Default, |
102 | )] |
103 | #[repr (C)] |
104 | pub enum TransferCharacteristics { |
105 | /// BT.709 |
106 | BT709 = 1, |
107 | /// Unspecified, must be signaled or inferred outside of the bitstream |
108 | #[default] |
109 | Unspecified, |
110 | /// BT.470 System M (historical) |
111 | BT470M = 4, |
112 | /// BT.470 System B, G (historical) |
113 | BT470BG, |
114 | /// BT.601-7 525 (SMPTE 170 M) |
115 | BT601, |
116 | /// SMPTE 240 M |
117 | SMPTE240, |
118 | /// Linear |
119 | Linear, |
120 | /// Logarithmic (100:1 range) |
121 | Log100, |
122 | /// Logarithmic ((100 * √10):1 range) |
123 | Log100Sqrt10, |
124 | /// IEC 61966-2-4 |
125 | IEC61966, |
126 | /// BT.1361 extended color gamut system (historical) |
127 | BT1361, |
128 | /// sRGB or sYCC |
129 | SRGB, |
130 | /// BT.2020 10-bit systems |
131 | BT2020_10Bit, |
132 | /// BT.2020 12-bit systems |
133 | BT2020_12Bit, |
134 | /// SMPTE ST 2084, ITU BT.2100 PQ |
135 | SMPTE2084, |
136 | /// SMPTE ST 428 |
137 | SMPTE428, |
138 | /// BT.2100 HLG (Hybrid Log Gamma), ARIB STD-B67 |
139 | HLG, |
140 | } |
141 | |
142 | /// Matrix coefficients |
143 | /// |
144 | /// As defined by the “Matrix coefficients” section of ISO/IEC 23091-4/ITU-TH.273. |
145 | #[derive ( |
146 | ArgEnum, |
147 | Debug, |
148 | Clone, |
149 | Copy, |
150 | PartialEq, |
151 | Eq, |
152 | FromPrimitive, |
153 | Serialize, |
154 | Deserialize, |
155 | Default, |
156 | )] |
157 | #[repr (C)] |
158 | pub enum MatrixCoefficients { |
159 | /// Identity matrix |
160 | Identity = 0, |
161 | /// BT.709 |
162 | BT709, |
163 | /// Unspecified, must be signaled or inferred outside of the bitstream. |
164 | #[default] |
165 | Unspecified, |
166 | /// US FCC 73.628 |
167 | FCC = 4, |
168 | /// BT.470 System B, G (historical) |
169 | BT470BG, |
170 | /// BT.601-7 525 (SMPTE 170 M) |
171 | BT601, |
172 | /// SMPTE 240 M |
173 | SMPTE240, |
174 | /// YCgCo |
175 | YCgCo, |
176 | /// BT.2020 non-constant luminance, BT.2100 YCbCr |
177 | BT2020NCL, |
178 | /// BT.2020 constant luminance |
179 | BT2020CL, |
180 | /// SMPTE ST 2085 YDzDx |
181 | SMPTE2085, |
182 | /// Chromaticity-derived non-constant luminance |
183 | ChromatNCL, |
184 | /// Chromaticity-derived constant luminance |
185 | ChromatCL, |
186 | /// BT.2020 ICtCp |
187 | ICtCp, |
188 | } |
189 | |
190 | /// Signal the content color description |
191 | #[derive (Copy, Clone, Debug, Serialize, Deserialize)] |
192 | pub struct ColorDescription { |
193 | /// Color primaries. |
194 | pub color_primaries: ColorPrimaries, |
195 | /// Transfer charasteristics. |
196 | pub transfer_characteristics: TransferCharacteristics, |
197 | /// Matrix coefficients. |
198 | pub matrix_coefficients: MatrixCoefficients, |
199 | } |
200 | |
201 | impl ColorDescription { |
202 | pub(crate) fn is_srgb_triple(self) -> bool { |
203 | self.color_primaries == ColorPrimaries::BT709 |
204 | && self.transfer_characteristics == TransferCharacteristics::SRGB |
205 | && self.matrix_coefficients == MatrixCoefficients::Identity |
206 | } |
207 | } |
208 | |
209 | /// Allowed pixel value range |
210 | /// |
211 | /// C.f. `VideoFullRangeFlag` variable specified in ISO/IEC 23091-4/ITU-T H.273 |
212 | #[wasm_bindgen ] |
213 | #[derive ( |
214 | ArgEnum, |
215 | Debug, |
216 | Clone, |
217 | Copy, |
218 | PartialEq, |
219 | Eq, |
220 | FromPrimitive, |
221 | Serialize, |
222 | Deserialize, |
223 | Default, |
224 | )] |
225 | #[repr (C)] |
226 | pub enum PixelRange { |
227 | /// Studio swing representation |
228 | #[default] |
229 | Limited, |
230 | /// Full swing representation |
231 | Full, |
232 | } |
233 | |
234 | /// High dynamic range content light level |
235 | /// |
236 | /// As defined by CEA-861.3, Appendix A. |
237 | #[derive (Copy, Clone, Debug, Serialize, Deserialize)] |
238 | pub struct ContentLight { |
239 | /// Maximum content light level |
240 | pub max_content_light_level: u16, |
241 | /// Maximum frame-average light level |
242 | pub max_frame_average_light_level: u16, |
243 | } |
244 | |
245 | /// Chromaticity coordinates as defined by CIE 1931, expressed as 0.16 |
246 | /// fixed-point values. |
247 | #[derive (Clone, Copy, Debug, Serialize, Deserialize)] |
248 | #[repr (C)] |
249 | pub struct ChromaticityPoint { |
250 | /// The X coordinate. |
251 | pub x: u16, |
252 | /// The Y coordinate. |
253 | pub y: u16, |
254 | } |
255 | |
256 | /// High dynamic range mastering display color volume |
257 | /// |
258 | /// As defined by CIE 1931 |
259 | #[derive (Copy, Clone, Debug, Serialize, Deserialize)] |
260 | pub struct MasteringDisplay { |
261 | /// Chromaticity coordinates in Red, Green, Blue order |
262 | /// expressed as 0.16 fixed-point |
263 | pub primaries: [ChromaticityPoint; 3], |
264 | /// Chromaticity coordinates expressed as 0.16 fixed-point |
265 | pub white_point: ChromaticityPoint, |
266 | /// 24.8 fixed-point maximum luminance in candelas per square meter |
267 | pub max_luminance: u32, |
268 | /// 18.14 fixed-point minimum luminance in candelas per square meter |
269 | pub min_luminance: u32, |
270 | } |
271 | |