| OLD | NEW |
| 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 { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 kSmpteSt4281 = 10, | 247 kSmpteSt4281 = 10, |
| 248 | 248 |
| 249 /** | 249 /** |
| 250 JEDEC P22 phosphors/EBU Tech. 3213-E (1975). | 250 JEDEC P22 phosphors/EBU Tech. 3213-E (1975). |
| 251 */ | 251 */ |
| 252 kJedecP22Phosphors = 22, | 252 kJedecP22Phosphors = 22, |
| 253 }; | 253 }; |
| 254 | 254 |
| 255 // ---- End copy/paste from libwebm/webm_parser/include/webm/dom_types.h ---- | 255 // ---- End copy/paste from libwebm/webm_parser/include/webm/dom_types.h ---- |
| 256 | 256 |
| 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() {} | 257 WebMColorMetadata::WebMColorMetadata() {} |
| 335 WebMColorMetadata::WebMColorMetadata(const WebMColorMetadata& rhs) = default; | 258 WebMColorMetadata::WebMColorMetadata(const WebMColorMetadata& rhs) = default; |
| 336 | 259 |
| 337 WebMMasteringMetadataParser::WebMMasteringMetadataParser() {} | 260 WebMMasteringMetadataParser::WebMMasteringMetadataParser() {} |
| 338 WebMMasteringMetadataParser::~WebMMasteringMetadataParser() {} | 261 WebMMasteringMetadataParser::~WebMMasteringMetadataParser() {} |
| 339 | 262 |
| 340 bool WebMMasteringMetadataParser::OnFloat(int id, double val) { | 263 bool WebMMasteringMetadataParser::OnFloat(int id, double val) { |
| 341 switch (id) { | 264 switch (id) { |
| 342 case kWebMIdPrimaryRChromaticityX: | 265 case kWebMIdPrimaryRChromaticityX: |
| 343 mastering_metadata_.primary_r_chromaticity_x = val; | 266 mastering_metadata_.primary_r_chromaticity_x = val; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 color_metadata.ChromaSubsamplingVert = chroma_subsampling_vert_; | 406 color_metadata.ChromaSubsamplingVert = chroma_subsampling_vert_; |
| 484 if (cb_subsampling_horz_ != -1) | 407 if (cb_subsampling_horz_ != -1) |
| 485 color_metadata.CbSubsamplingHorz = cb_subsampling_horz_; | 408 color_metadata.CbSubsamplingHorz = cb_subsampling_horz_; |
| 486 if (cb_subsampling_vert_ != -1) | 409 if (cb_subsampling_vert_ != -1) |
| 487 color_metadata.CbSubsamplingVert = cb_subsampling_vert_; | 410 color_metadata.CbSubsamplingVert = cb_subsampling_vert_; |
| 488 if (chroma_siting_horz_ != -1) | 411 if (chroma_siting_horz_ != -1) |
| 489 color_metadata.ChromaSitingHorz = chroma_siting_horz_; | 412 color_metadata.ChromaSitingHorz = chroma_siting_horz_; |
| 490 if (chroma_siting_vert_ != -1) | 413 if (chroma_siting_vert_ != -1) |
| 491 color_metadata.ChromaSitingVert = chroma_siting_vert_; | 414 color_metadata.ChromaSitingVert = chroma_siting_vert_; |
| 492 | 415 |
| 493 gfx::ColorSpace::MatrixID matrix_id = gfx::ColorSpace::MatrixID::UNSPECIFIED; | 416 gfx::ColorSpace::RangeID range_id = gfx::ColorSpace::RangeID::FULL; |
| 494 if (matrix_coefficients_ != -1) | 417 switch (static_cast<Range>(range_)) { |
| 495 matrix_id = FromWebMMatrixCoefficients( | 418 case Range::kUnspecified: |
| 496 static_cast<MatrixCoefficients>(matrix_coefficients_)); | 419 range_id = gfx::ColorSpace::RangeID::FULL; |
| 497 | 420 break; |
| 498 gfx::ColorSpace::RangeID range_id = gfx::ColorSpace::RangeID::UNSPECIFIED; | 421 case Range::kBroadcast: |
| 499 if (range_ != -1) | 422 range_id = gfx::ColorSpace::RangeID::LIMITED; |
| 500 range_id = FromWebMRange(static_cast<Range>(range_)); | 423 break; |
| 501 | 424 case Range::kFull: |
| 502 gfx::ColorSpace::TransferID transfer_id = | 425 range_id = gfx::ColorSpace::RangeID::FULL; |
| 503 gfx::ColorSpace::TransferID::UNSPECIFIED; | 426 break; |
| 504 if (transfer_characteristics_ != -1) | 427 case Range::kDerived: |
| 505 transfer_id = FromWebMTransferCharacteristics( | 428 range_id = gfx::ColorSpace::RangeID::DERIVED; |
| 506 static_cast<TransferCharacteristics>(transfer_characteristics_)); | 429 break; |
| 507 | 430 } |
| 508 gfx::ColorSpace::PrimaryID primary_id = | 431 color_metadata.color_space = gfx::ColorSpace::CreateVideo( |
| 509 gfx::ColorSpace::PrimaryID::UNSPECIFIED; | 432 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 | 433 |
| 516 if (max_cll_ != -1) | 434 if (max_cll_ != -1) |
| 517 color_metadata.hdr_metadata.max_cll = max_cll_; | 435 color_metadata.hdr_metadata.max_cll = max_cll_; |
| 518 | 436 |
| 519 if (max_fall_ != -1) | 437 if (max_fall_ != -1) |
| 520 color_metadata.hdr_metadata.max_fall = max_fall_; | 438 color_metadata.hdr_metadata.max_fall = max_fall_; |
| 521 | 439 |
| 522 if (mastering_metadata_parsed_) | 440 if (mastering_metadata_parsed_) |
| 523 color_metadata.hdr_metadata.mastering_metadata = | 441 color_metadata.hdr_metadata.mastering_metadata = |
| 524 mastering_metadata_parser_.GetMasteringMetadata(); | 442 mastering_metadata_parser_.GetMasteringMetadata(); |
| 525 | 443 |
| 526 return color_metadata; | 444 return color_metadata; |
| 527 } | 445 } |
| 528 | 446 |
| 529 } // namespace media | 447 } // namespace media |
| OLD | NEW |