Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: media/formats/webm/webm_colour_parser.cc

Issue 2697863003: color: Clarify default behaviors (Closed)
Patch Set: Do less Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/formats/webm/webm_colour_parser.h" 5 #include "media/formats/webm/webm_colour_parser.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/formats/webm/webm_constants.h" 8 #include "media/formats/webm/webm_constants.h"
9 9
10 namespace media { 10 namespace media {
11 11
12 // The definitions below are copied from the current libwebm top-of-tree. 12 // The definitions below are copied from the current libwebm top-of-tree.
13 // Chromium's third_party/libwebm doesn't have these yet. We can probably just 13 // Chromium's third_party/libwebm doesn't have these yet. We can probably just
14 // include libwebm header directly in the future. 14 // include libwebm header directly in the future.
15 // ---- Begin copy/paste from libwebm/webm_parser/include/webm/dom_types.h ---- 15 // ---- Begin copy/paste from libwebm/webm_parser/include/webm/dom_types.h ----
16 16
17 /** 17 /**
18 A parsed \WebMID{MatrixCoefficients} element.
19
20 Matroska/WebM adopted these values from Table 4 of ISO/IEC 23001-8:2013/DCOR1.
21 See that document for further details.
22 */
23 enum class MatrixCoefficients : std::uint64_t {
hubbe 2017/02/16 05:02:39 The author of this will not want you to remove it.
24 /**
25 The identity matrix.
26
27 Typically used for GBR (often referred to as RGB); however, may also be used
28 for YZX (often referred to as XYZ).
29 */
30 kRgb = 0,
31
32 /**
33 Rec. ITU-R BT.709-5.
34 */
35 kBt709 = 1,
36
37 /**
38 Image characteristics are unknown or are determined by the application.
39 */
40 kUnspecified = 2,
41
42 /**
43 United States Federal Communications Commission Title 47 Code of Federal
44 Regulations (2003) 73.682 (a) (20).
45 */
46 kFcc = 4,
47
48 /**
49 Rec. ITU-R BT.470‑6 System B, G (historical).
50 */
51 kBt470Bg = 5,
52
53 /**
54 Society of Motion Picture and Television Engineers 170M (2004).
55 */
56 kSmpte170M = 6,
57
58 /**
59 Society of Motion Picture and Television Engineers 240M (1999).
60 */
61 kSmpte240M = 7,
62
63 /**
64 YCgCo.
65 */
66 kYCgCo = 8,
67
68 /**
69 Rec. ITU-R BT.2020 (non-constant luminance).
70 */
71 kBt2020NonconstantLuminance = 9,
72
73 /**
74 Rec. ITU-R BT.2020 (constant luminance).
75 */
76 kBt2020ConstantLuminance = 10,
77 };
78
79 /**
80 A parsed \WebMID{Range} element. 18 A parsed \WebMID{Range} element.
81 */ 19 */
82 enum class Range : std::uint64_t { 20 enum class Range : std::uint64_t {
83 /** 21 /**
84 Unspecified. 22 Unspecified.
85 */ 23 */
86 kUnspecified = 0, 24 kUnspecified = 0,
87 25
88 /** 26 /**
89 Broadcast range. 27 Broadcast range.
90 */ 28 */
91 kBroadcast = 1, 29 kBroadcast = 1,
92 30
93 /** 31 /**
94 Full range (no clipping). 32 Full range (no clipping).
95 */ 33 */
96 kFull = 2, 34 kFull = 2,
97 35
98 /** 36 /**
99 Defined by MatrixCoefficients/TransferCharacteristics. 37 Defined by MatrixCoefficients/TransferCharacteristics.
100 */ 38 */
101 kDerived = 3, 39 kDerived = 3,
102 }; 40 };
103 41
104 /**
105 A parsed \WebMID{TransferCharacteristics} element.
106
107 Matroska/WebM adopted these values from Table 3 of ISO/IEC 23001-8:2013/DCOR1.
108 See that document for further details.
109 */
110 enum class TransferCharacteristics : std::uint64_t {
111 /**
112 Rec. ITU-R BT.709-6.
113 */
114 kBt709 = 1,
115
116 /**
117 Image characteristics are unknown or are determined by the application.
118 */
119 kUnspecified = 2,
120
121 /**
122 Rec. ITU‑R BT.470‑6 System M (historical) with assumed display gamma 2.2.
123 */
124 kGamma22curve = 4,
125
126 /**
127 Rec. ITU‑R BT.470-6 System B, G (historical) with assumed display gamma 2.8.
128 */
129 kGamma28curve = 5,
130
131 /**
132 Society of Motion Picture and Television Engineers 170M (2004).
133 */
134 kSmpte170M = 6,
135
136 /**
137 Society of Motion Picture and Television Engineers 240M (1999).
138 */
139 kSmpte240M = 7,
140
141 /**
142 Linear transfer characteristics.
143 */
144 kLinear = 8,
145
146 /**
147 Logarithmic transfer characteristic (100:1 range).
148 */
149 kLog = 9,
150
151 /**
152 Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range).
153 */
154 kLogSqrt = 10,
155
156 /**
157 IEC 61966-2-4.
158 */
159 kIec6196624 = 11,
160
161 /**
162 Rec. ITU‑R BT.1361-0 extended colour gamut system (historical).
163 */
164 kBt1361ExtendedColourGamut = 12,
165
166 /**
167 IEC 61966-2-1 sRGB or sYCC.
168 */
169 kIec6196621 = 13,
170
171 /**
172 Rec. ITU-R BT.2020-2 (10-bit system).
173 */
174 k10BitBt2020 = 14,
175
176 /**
177 Rec. ITU-R BT.2020-2 (12-bit system).
178 */
179 k12BitBt2020 = 15,
180
181 /**
182 Society of Motion Picture and Television Engineers ST 2084.
183 */
184 kSmpteSt2084 = 16,
185
186 /**
187 Society of Motion Picture and Television Engineers ST 428-1.
188 */
189 kSmpteSt4281 = 17,
190
191 /**
192 Association of Radio Industries and Businesses (ARIB) STD-B67.
193 */
194 kAribStdB67Hlg = 18,
195 };
196
197 /**
198 A parsed \WebMID{Primaries} element.
199
200 Matroska/WebM adopted these values from Table 2 of ISO/IEC 23001-8:2013/DCOR1.
201 See that document for further details.
202 */
203 enum class Primaries : std::uint64_t {
204 /**
205 Rec. ITU‑R BT.709-6.
206 */
207 kBt709 = 1,
208
209 /**
210 Image characteristics are unknown or are determined by the application.
211 */
212 kUnspecified = 2,
213
214 /**
215 Rec. ITU‑R BT.470‑6 System M (historical).
216 */
217 kBt470M = 4,
218
219 /**
220 Rec. ITU‑R BT.470‑6 System B, G (historical).
221 */
222 kBt470Bg = 5,
223
224 /**
225 Society of Motion Picture and Television Engineers 170M (2004).
226 */
227 kSmpte170M = 6,
228
229 /**
230 Society of Motion Picture and Television Engineers 240M (1999).
231 */
232 kSmpte240M = 7,
233
234 /**
235 Generic film.
236 */
237 kFilm = 8,
238
239 /**
240 Rec. ITU-R BT.2020-2.
241 */
242 kBt2020 = 9,
243
244 /**
245 Society of Motion Picture and Television Engineers ST 428-1.
246 */
247 kSmpteSt4281 = 10,
248
249 /**
250 JEDEC P22 phosphors/EBU Tech. 3213-E (1975).
251 */
252 kJedecP22Phosphors = 22,
253 };
254
255 // ---- End copy/paste from libwebm/webm_parser/include/webm/dom_types.h ---- 42 // ---- End copy/paste from libwebm/webm_parser/include/webm/dom_types.h ----
256 43
257 // Ensure that libwebm enum values match enums in gfx::ColorSpace.
258 #define STATIC_ASSERT_ENUM(a, b) \
259 static_assert(static_cast<int>(a) == static_cast<int>(gfx::ColorSpace::b), \
260 "mismatching enums: " #a " and " #b)
261
262 STATIC_ASSERT_ENUM(MatrixCoefficients::kRgb, MatrixID::RGB);
263 STATIC_ASSERT_ENUM(MatrixCoefficients::kBt709, MatrixID::BT709);
264 STATIC_ASSERT_ENUM(MatrixCoefficients::kUnspecified, MatrixID::UNSPECIFIED);
265 STATIC_ASSERT_ENUM(MatrixCoefficients::kFcc, MatrixID::FCC);
266 STATIC_ASSERT_ENUM(MatrixCoefficients::kBt470Bg, MatrixID::BT470BG);
267 STATIC_ASSERT_ENUM(MatrixCoefficients::kSmpte170M, MatrixID::SMPTE170M);
268 STATIC_ASSERT_ENUM(MatrixCoefficients::kSmpte240M, MatrixID::SMPTE240M);
269 STATIC_ASSERT_ENUM(MatrixCoefficients::kYCgCo, MatrixID::YCOCG);
270 STATIC_ASSERT_ENUM(MatrixCoefficients::kBt2020NonconstantLuminance,
271 MatrixID::BT2020_NCL);
272 STATIC_ASSERT_ENUM(MatrixCoefficients::kBt2020ConstantLuminance,
273 MatrixID::BT2020_CL);
274
275 gfx::ColorSpace::MatrixID FromWebMMatrixCoefficients(MatrixCoefficients c) {
276 return static_cast<gfx::ColorSpace::MatrixID>(c);
277 }
278
279 STATIC_ASSERT_ENUM(Range::kUnspecified, RangeID::UNSPECIFIED);
280 STATIC_ASSERT_ENUM(Range::kBroadcast, RangeID::LIMITED);
281 STATIC_ASSERT_ENUM(Range::kFull, RangeID::FULL);
282 STATIC_ASSERT_ENUM(Range::kDerived, RangeID::DERIVED);
283
284 gfx::ColorSpace::RangeID FromWebMRange(Range range) {
285 return static_cast<gfx::ColorSpace::RangeID>(range);
286 }
287
288 STATIC_ASSERT_ENUM(TransferCharacteristics::kBt709, TransferID::BT709);
289 STATIC_ASSERT_ENUM(TransferCharacteristics::kUnspecified,
290 TransferID::UNSPECIFIED);
291 STATIC_ASSERT_ENUM(TransferCharacteristics::kGamma22curve, TransferID::GAMMA22);
292 STATIC_ASSERT_ENUM(TransferCharacteristics::kGamma28curve, TransferID::GAMMA28);
293 STATIC_ASSERT_ENUM(TransferCharacteristics::kSmpte170M, TransferID::SMPTE170M);
294 STATIC_ASSERT_ENUM(TransferCharacteristics::kSmpte240M, TransferID::SMPTE240M);
295 STATIC_ASSERT_ENUM(TransferCharacteristics::kLinear, TransferID::LINEAR);
296 STATIC_ASSERT_ENUM(TransferCharacteristics::kLog, TransferID::LOG);
297 STATIC_ASSERT_ENUM(TransferCharacteristics::kLogSqrt, TransferID::LOG_SQRT);
298 STATIC_ASSERT_ENUM(TransferCharacteristics::kIec6196624,
299 TransferID::IEC61966_2_4);
300 STATIC_ASSERT_ENUM(TransferCharacteristics::kBt1361ExtendedColourGamut,
301 TransferID::BT1361_ECG);
302 STATIC_ASSERT_ENUM(TransferCharacteristics::kIec6196621,
303 TransferID::IEC61966_2_1);
304 STATIC_ASSERT_ENUM(TransferCharacteristics::k10BitBt2020,
305 TransferID::BT2020_10);
306 STATIC_ASSERT_ENUM(TransferCharacteristics::k12BitBt2020,
307 TransferID::BT2020_12);
308 STATIC_ASSERT_ENUM(TransferCharacteristics::kSmpteSt2084,
309 TransferID::SMPTEST2084);
310 STATIC_ASSERT_ENUM(TransferCharacteristics::kSmpteSt4281,
311 TransferID::SMPTEST428_1);
312 STATIC_ASSERT_ENUM(TransferCharacteristics::kAribStdB67Hlg,
313 TransferID::ARIB_STD_B67);
314
315 gfx::ColorSpace::TransferID FromWebMTransferCharacteristics(
316 TransferCharacteristics tc) {
317 return static_cast<gfx::ColorSpace::TransferID>(tc);
318 }
319
320 STATIC_ASSERT_ENUM(Primaries::kBt709, PrimaryID::BT709);
321 STATIC_ASSERT_ENUM(Primaries::kUnspecified, PrimaryID::UNSPECIFIED);
322 STATIC_ASSERT_ENUM(Primaries::kBt470M, PrimaryID::BT470M);
323 STATIC_ASSERT_ENUM(Primaries::kBt470Bg, PrimaryID::BT470BG);
324 STATIC_ASSERT_ENUM(Primaries::kSmpte170M, PrimaryID::SMPTE170M);
325 STATIC_ASSERT_ENUM(Primaries::kSmpte240M, PrimaryID::SMPTE240M);
326 STATIC_ASSERT_ENUM(Primaries::kFilm, PrimaryID::FILM);
327 STATIC_ASSERT_ENUM(Primaries::kBt2020, PrimaryID::BT2020);
328 STATIC_ASSERT_ENUM(Primaries::kSmpteSt4281, PrimaryID::SMPTEST428_1);
329
330 gfx::ColorSpace::PrimaryID FromWebMPrimaries(Primaries primaries) {
331 return static_cast<gfx::ColorSpace::PrimaryID>(primaries);
332 }
333
334 WebMColorMetadata::WebMColorMetadata() {} 44 WebMColorMetadata::WebMColorMetadata() {}
335 WebMColorMetadata::WebMColorMetadata(const WebMColorMetadata& rhs) = default; 45 WebMColorMetadata::WebMColorMetadata(const WebMColorMetadata& rhs) = default;
336 46
337 WebMMasteringMetadataParser::WebMMasteringMetadataParser() {} 47 WebMMasteringMetadataParser::WebMMasteringMetadataParser() {}
338 WebMMasteringMetadataParser::~WebMMasteringMetadataParser() {} 48 WebMMasteringMetadataParser::~WebMMasteringMetadataParser() {}
339 49
340 bool WebMMasteringMetadataParser::OnFloat(int id, double val) { 50 bool WebMMasteringMetadataParser::OnFloat(int id, double val) {
341 switch (id) { 51 switch (id) {
342 case kWebMIdPrimaryRChromaticityX: 52 case kWebMIdPrimaryRChromaticityX:
343 mastering_metadata_.primary_r_chromaticity_x = val; 53 mastering_metadata_.primary_r_chromaticity_x = val;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 color_metadata.ChromaSubsamplingVert = chroma_subsampling_vert_; 193 color_metadata.ChromaSubsamplingVert = chroma_subsampling_vert_;
484 if (cb_subsampling_horz_ != -1) 194 if (cb_subsampling_horz_ != -1)
485 color_metadata.CbSubsamplingHorz = cb_subsampling_horz_; 195 color_metadata.CbSubsamplingHorz = cb_subsampling_horz_;
486 if (cb_subsampling_vert_ != -1) 196 if (cb_subsampling_vert_ != -1)
487 color_metadata.CbSubsamplingVert = cb_subsampling_vert_; 197 color_metadata.CbSubsamplingVert = cb_subsampling_vert_;
488 if (chroma_siting_horz_ != -1) 198 if (chroma_siting_horz_ != -1)
489 color_metadata.ChromaSitingHorz = chroma_siting_horz_; 199 color_metadata.ChromaSitingHorz = chroma_siting_horz_;
490 if (chroma_siting_vert_ != -1) 200 if (chroma_siting_vert_ != -1)
491 color_metadata.ChromaSitingVert = chroma_siting_vert_; 201 color_metadata.ChromaSitingVert = chroma_siting_vert_;
492 202
493 gfx::ColorSpace::MatrixID matrix_id = gfx::ColorSpace::MatrixID::UNSPECIFIED; 203 gfx::ColorSpace::RangeID range_id = gfx::ColorSpace::RangeID::FULL;
494 if (matrix_coefficients_ != -1) 204 switch (static_cast<Range>(range_)) {
495 matrix_id = FromWebMMatrixCoefficients( 205 case Range::kUnspecified:
496 static_cast<MatrixCoefficients>(matrix_coefficients_)); 206 range_id = gfx::ColorSpace::RangeID::FULL;
497 207 break;
498 gfx::ColorSpace::RangeID range_id = gfx::ColorSpace::RangeID::UNSPECIFIED; 208 case Range::kBroadcast:
499 if (range_ != -1) 209 range_id = gfx::ColorSpace::RangeID::LIMITED;
500 range_id = FromWebMRange(static_cast<Range>(range_)); 210 break;
501 211 case Range::kFull:
502 gfx::ColorSpace::TransferID transfer_id = 212 range_id = gfx::ColorSpace::RangeID::FULL;
503 gfx::ColorSpace::TransferID::UNSPECIFIED; 213 break;
504 if (transfer_characteristics_ != -1) 214 case Range::kDerived:
505 transfer_id = FromWebMTransferCharacteristics( 215 range_id = gfx::ColorSpace::RangeID::DERIVED;
506 static_cast<TransferCharacteristics>(transfer_characteristics_)); 216 break;
507 217 }
508 gfx::ColorSpace::PrimaryID primary_id = 218 color_metadata.color_space = gfx::ColorSpace::CreateVideo(
509 gfx::ColorSpace::PrimaryID::UNSPECIFIED; 219 primaries_, transfer_characteristics_, matrix_coefficients_, range_id);
510 if (primaries_ != -1)
511 primary_id = FromWebMPrimaries(static_cast<Primaries>(primaries_));
512
513 color_metadata.color_space =
514 gfx::ColorSpace(primary_id, transfer_id, matrix_id, range_id);
515 220
516 if (max_cll_ != -1) 221 if (max_cll_ != -1)
517 color_metadata.hdr_metadata.max_cll = max_cll_; 222 color_metadata.hdr_metadata.max_cll = max_cll_;
518 223
519 if (max_fall_ != -1) 224 if (max_fall_ != -1)
520 color_metadata.hdr_metadata.max_fall = max_fall_; 225 color_metadata.hdr_metadata.max_fall = max_fall_;
521 226
522 if (mastering_metadata_parsed_) 227 if (mastering_metadata_parsed_)
523 color_metadata.hdr_metadata.mastering_metadata = 228 color_metadata.hdr_metadata.mastering_metadata =
524 mastering_metadata_parser_.GetMasteringMetadata(); 229 mastering_metadata_parser_.GetMasteringMetadata();
525 230
526 return color_metadata; 231 return color_metadata;
527 } 232 }
528 233
529 } // namespace media 234 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/h264_parser.cc ('k') | ui/gfx/color_space.h » ('j') | ui/gfx/color_space.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698