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