Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/color_space.h" | 5 #include "ui/gfx/color_space.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 } | 79 } |
| 80 if (primaries_ == PrimaryID::CUSTOM) { | 80 if (primaries_ == PrimaryID::CUSTOM) { |
| 81 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, | 81 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, |
| 82 sizeof(custom_primary_matrix_)); | 82 sizeof(custom_primary_matrix_)); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 ColorSpace::~ColorSpace() = default; | 86 ColorSpace::~ColorSpace() = default; |
| 87 | 87 |
| 88 bool ColorSpace::IsValid() const { | 88 bool ColorSpace::IsValid() const { |
| 89 return *this != gfx::ColorSpace(); | 89 return primaries_ != PrimaryID::UNSPECIFIED && |
| 90 transfer_ != TransferID::UNSPECIFIED && | |
| 91 matrix_ != MatrixID::UNSPECIFIED; | |
|
hubbe
2017/02/15 08:48:56
What if a video specifies the range but nothing el
ccameron
2017/02/15 09:34:28
Errr... I meant to put UNKNOWN here.
So, UNSPECIF
| |
| 90 } | 92 } |
| 91 | 93 |
| 92 // static | 94 // static |
| 93 ColorSpace ColorSpace::CreateSRGB() { | 95 ColorSpace ColorSpace::CreateSRGB() { |
| 94 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, | 96 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, |
| 95 RangeID::FULL); | 97 RangeID::FULL); |
| 96 } | 98 } |
| 97 | 99 |
| 98 // static | 100 // static |
| 101 ColorSpace ColorSpace::CreateCustom(const SkMatrix44& to_XYZD50, | |
| 102 const SkColorSpaceTransferFn& fn) { | |
| 103 ColorSpace result(ColorSpace::PrimaryID::CUSTOM, | |
| 104 ColorSpace::TransferID::CUSTOM, ColorSpace::MatrixID::RGB, | |
| 105 ColorSpace::RangeID::FULL); | |
| 106 for (int row = 0; row < 3; ++row) { | |
| 107 for (int col = 0; col < 3; ++col) { | |
| 108 result.custom_primary_matrix_[3 * row + col] = to_XYZD50.get(row, col); | |
| 109 } | |
| 110 } | |
| 111 result.custom_transfer_params_[0] = fn.fA; | |
| 112 result.custom_transfer_params_[1] = fn.fB; | |
| 113 result.custom_transfer_params_[2] = fn.fC; | |
| 114 result.custom_transfer_params_[3] = fn.fD; | |
| 115 result.custom_transfer_params_[4] = fn.fE; | |
| 116 result.custom_transfer_params_[5] = fn.fF; | |
| 117 result.custom_transfer_params_[6] = fn.fG; | |
| 118 return result; | |
| 119 } | |
| 120 | |
| 121 // static | |
| 99 ColorSpace ColorSpace::CreateSCRGBLinear() { | 122 ColorSpace ColorSpace::CreateSCRGBLinear() { |
| 100 return ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR, MatrixID::RGB, | 123 return ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR, MatrixID::RGB, |
| 101 RangeID::FULL); | 124 RangeID::FULL); |
| 102 } | 125 } |
| 103 | 126 |
| 104 // Static | 127 // Static |
| 105 ColorSpace ColorSpace::CreateXYZD50() { | 128 ColorSpace ColorSpace::CreateXYZD50() { |
| 106 return ColorSpace(PrimaryID::XYZ_D50, TransferID::LINEAR, MatrixID::RGB, | 129 return ColorSpace(PrimaryID::XYZ_D50, TransferID::LINEAR, MatrixID::RGB, |
| 107 RangeID::FULL); | 130 RangeID::FULL); |
| 108 } | 131 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 return false; | 213 return false; |
| 191 } | 214 } |
| 192 | 215 |
| 193 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { | 216 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { |
| 194 // If we got a specific SkColorSpace from the ICCProfile that this color space | 217 // If we got a specific SkColorSpace from the ICCProfile that this color space |
| 195 // was created from, use that. | 218 // was created from, use that. |
| 196 if (icc_profile_sk_color_space_) | 219 if (icc_profile_sk_color_space_) |
| 197 return icc_profile_sk_color_space_; | 220 return icc_profile_sk_color_space_; |
| 198 | 221 |
| 199 // Unspecified color spaces correspond to the null SkColorSpace. | 222 // Unspecified color spaces correspond to the null SkColorSpace. |
| 200 if (primaries_ == PrimaryID::UNSPECIFIED || | 223 if (!IsValid()) |
|
hubbe
2017/02/15 08:48:56
Not sure I understand why this was the way it was
ccameron
2017/02/15 09:34:28
This is the same as before, just expressed in a wa
| |
| 201 transfer_ == TransferID::UNSPECIFIED) { | |
| 202 return nullptr; | 224 return nullptr; |
| 203 } | |
| 204 | 225 |
| 205 // Handle only full-range RGB spaces. | 226 // Handle only full-range RGB spaces. |
| 206 if (matrix_ != MatrixID::RGB) { | 227 if (matrix_ != MatrixID::RGB) { |
| 207 DLOG(ERROR) << "Not creating non-RGB SkColorSpace"; | 228 DLOG(ERROR) << "Not creating non-RGB SkColorSpace"; |
| 208 return nullptr; | 229 return nullptr; |
| 209 } | 230 } |
| 210 if (range_ != RangeID::FULL) { | 231 if (range_ != RangeID::FULL) { |
| 211 DLOG(ERROR) << "Not creating non-full-range SkColorSpace"; | 232 DLOG(ERROR) << "Not creating non-full-range SkColorSpace"; |
| 212 return nullptr; | 233 return nullptr; |
| 213 } | 234 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 fn->fG = 2.2f; | 430 fn->fG = 2.2f; |
| 410 return true; | 431 return true; |
| 411 case ColorSpace::TransferID::GAMMA24: | 432 case ColorSpace::TransferID::GAMMA24: |
| 412 fn->fG = 2.4f; | 433 fn->fG = 2.4f; |
| 413 return true; | 434 return true; |
| 414 case ColorSpace::TransferID::GAMMA28: | 435 case ColorSpace::TransferID::GAMMA28: |
| 415 fn->fG = 2.8f; | 436 fn->fG = 2.8f; |
| 416 return true; | 437 return true; |
| 417 case ColorSpace::TransferID::RESERVED0: | 438 case ColorSpace::TransferID::RESERVED0: |
| 418 case ColorSpace::TransferID::RESERVED: | 439 case ColorSpace::TransferID::RESERVED: |
| 419 case ColorSpace::TransferID::UNSPECIFIED: | |
| 420 case ColorSpace::TransferID::UNKNOWN: | 440 case ColorSpace::TransferID::UNKNOWN: |
| 421 // All unknown values default to BT709 | 441 // All unknown values default to BT709 |
| 422 case ColorSpace::TransferID::BT709: | 442 case ColorSpace::TransferID::BT709: |
| 423 case ColorSpace::TransferID::SMPTE170M: | 443 case ColorSpace::TransferID::SMPTE170M: |
| 424 case ColorSpace::TransferID::BT2020_10: | 444 case ColorSpace::TransferID::BT2020_10: |
| 425 case ColorSpace::TransferID::BT2020_12: | 445 case ColorSpace::TransferID::BT2020_12: |
| 426 fn->fA = 0.909672431050f; | 446 fn->fA = 0.909672431050f; |
| 427 fn->fB = 0.090327568950f; | 447 fn->fB = 0.090327568950f; |
| 428 fn->fC = 0.222222222222f; | 448 fn->fC = 0.222222222222f; |
| 429 fn->fD = 0.081242862158f; | 449 fn->fD = 0.081242862158f; |
| 430 fn->fG = 2.222222222222f; | 450 fn->fG = 2.222222222222f; |
| 431 return true; | 451 return true; |
| 432 case ColorSpace::TransferID::SMPTE240M: | 452 case ColorSpace::TransferID::SMPTE240M: |
| 433 fn->fA = 0.899626676224f; | 453 fn->fA = 0.899626676224f; |
| 434 fn->fB = 0.100373323776f; | 454 fn->fB = 0.100373323776f; |
| 435 fn->fC = 0.250000000000f; | 455 fn->fC = 0.250000000000f; |
| 436 fn->fD = 0.091286342118f; | 456 fn->fD = 0.091286342118f; |
| 437 fn->fG = 2.222222222222f; | 457 fn->fG = 2.222222222222f; |
| 438 return true; | 458 return true; |
| 459 // Unspecified values are given the sRGB transfer function. | |
|
hubbe
2017/02/15 08:48:56
The comment above says otherwise.
ccameron
2017/02/15 09:34:28
This is the UNSPECIFIED versus UNKNOWN deal ... th
| |
| 460 case ColorSpace::TransferID::UNSPECIFIED: | |
| 439 case ColorSpace::TransferID::IEC61966_2_1: | 461 case ColorSpace::TransferID::IEC61966_2_1: |
| 440 fn->fA = 0.947867345704f; | 462 fn->fA = 0.947867345704f; |
| 441 fn->fB = 0.052132654296f; | 463 fn->fB = 0.052132654296f; |
| 442 fn->fC = 0.077399380805f; | 464 fn->fC = 0.077399380805f; |
| 443 fn->fD = 0.040449937172f; | 465 fn->fD = 0.040449937172f; |
| 444 fn->fG = 2.400000000000f; | 466 fn->fG = 2.400000000000f; |
| 445 return true; | 467 return true; |
| 446 case ColorSpace::TransferID::SMPTEST428_1: | 468 case ColorSpace::TransferID::SMPTEST428_1: |
| 447 fn->fA = 0.225615407568f; | 469 fn->fA = 0.225615407568f; |
| 448 fn->fE = -1.091041666667f; | 470 fn->fE = -1.091041666667f; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 467 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { | 489 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { |
| 468 if (!GetTransferFunction(fn)) | 490 if (!GetTransferFunction(fn)) |
| 469 return false; | 491 return false; |
| 470 *fn = SkTransferFnInverse(*fn); | 492 *fn = SkTransferFnInverse(*fn); |
| 471 return true; | 493 return true; |
| 472 } | 494 } |
| 473 | 495 |
| 474 void ColorSpace::GetTransferMatrix(SkMatrix44* matrix) const { | 496 void ColorSpace::GetTransferMatrix(SkMatrix44* matrix) const { |
| 475 float Kr = 0; | 497 float Kr = 0; |
| 476 float Kb = 0; | 498 float Kb = 0; |
| 477 switch (matrix_) { | 499 switch (matrix_) { |
|
hubbe
2017/02/15 08:48:56
I'm worried that changing all these defaults will
ccameron
2017/02/15 09:34:28
Should have been UNKNOWN ... does this fix it?
hubbe
2017/02/15 18:47:45
I don't think so. For video you we want unknown va
| |
| 500 case ColorSpace::MatrixID::UNSPECIFIED: | |
| 478 case ColorSpace::MatrixID::RGB: | 501 case ColorSpace::MatrixID::RGB: |
| 479 matrix->setIdentity(); | 502 matrix->setIdentity(); |
| 480 return; | 503 return; |
| 481 | 504 |
| 482 case ColorSpace::MatrixID::BT709: | 505 case ColorSpace::MatrixID::BT709: |
| 483 case ColorSpace::MatrixID::UNSPECIFIED: | |
| 484 case ColorSpace::MatrixID::RESERVED: | 506 case ColorSpace::MatrixID::RESERVED: |
| 485 case ColorSpace::MatrixID::UNKNOWN: | 507 case ColorSpace::MatrixID::UNKNOWN: |
| 486 Kr = 0.2126f; | 508 Kr = 0.2126f; |
| 487 Kb = 0.0722f; | 509 Kb = 0.0722f; |
| 488 break; | 510 break; |
| 489 | 511 |
| 490 case ColorSpace::MatrixID::FCC: | 512 case ColorSpace::MatrixID::FCC: |
| 491 Kr = 0.30f; | 513 Kr = 0.30f; |
| 492 Kb = 0.11f; | 514 Kb = 0.11f; |
| 493 break; | 515 break; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 case MatrixID::BT2020_CL: | 610 case MatrixID::BT2020_CL: |
| 589 case MatrixID::YDZDX: | 611 case MatrixID::YDZDX: |
| 590 case MatrixID::UNKNOWN: | 612 case MatrixID::UNKNOWN: |
| 591 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f); | 613 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f); |
| 592 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); | 614 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); |
| 593 break; | 615 break; |
| 594 } | 616 } |
| 595 } | 617 } |
| 596 | 618 |
| 597 } // namespace gfx | 619 } // namespace gfx |
| OLD | NEW |