| 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 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 420 } |
| 421 | 421 |
| 422 // Use the named SRGB and linear-SRGB instead of the generic constructors. | 422 // Use the named SRGB and linear-SRGB instead of the generic constructors. |
| 423 if (primaries_ == PrimaryID::BT709) { | 423 if (primaries_ == PrimaryID::BT709) { |
| 424 if (transfer_ == TransferID::IEC61966_2_1) | 424 if (transfer_ == TransferID::IEC61966_2_1) |
| 425 return SkColorSpace::MakeSRGB(); | 425 return SkColorSpace::MakeSRGB(); |
| 426 if (transfer_ == TransferID::LINEAR || transfer_ == TransferID::LINEAR_HDR) | 426 if (transfer_ == TransferID::LINEAR || transfer_ == TransferID::LINEAR_HDR) |
| 427 return SkColorSpace::MakeSRGBLinear(); | 427 return SkColorSpace::MakeSRGBLinear(); |
| 428 } | 428 } |
| 429 | 429 |
| 430 // Prefer to used the named gamma and gamut, if possible. |
| 431 bool has_named_gamma = true; |
| 432 SkColorSpace::RenderTargetGamma named_gamma = |
| 433 SkColorSpace::kSRGB_RenderTargetGamma; |
| 434 switch (transfer_) { |
| 435 case TransferID::IEC61966_2_1: |
| 436 break; |
| 437 case TransferID::LINEAR: |
| 438 case TransferID::LINEAR_HDR: |
| 439 named_gamma = SkColorSpace::kLinear_RenderTargetGamma; |
| 440 break; |
| 441 default: |
| 442 has_named_gamma = false; |
| 443 break; |
| 444 } |
| 445 bool has_named_gamut = true; |
| 446 SkColorSpace::Gamut named_gamut = SkColorSpace::kSRGB_Gamut; |
| 447 switch (primaries_) { |
| 448 case PrimaryID::BT709: |
| 449 break; |
| 450 case PrimaryID::ADOBE_RGB: |
| 451 named_gamut = SkColorSpace::kAdobeRGB_Gamut; |
| 452 break; |
| 453 case PrimaryID::SMPTEST432_1: |
| 454 named_gamut = SkColorSpace::kDCIP3_D65_Gamut; |
| 455 break; |
| 456 case PrimaryID::BT2020: |
| 457 named_gamut = SkColorSpace::kRec2020_Gamut; |
| 458 break; |
| 459 default: |
| 460 has_named_gamut = false; |
| 461 break; |
| 462 } |
| 463 if (has_named_gamut && has_named_gamma) |
| 464 return SkColorSpace::MakeRGB(named_gamma, named_gamut); |
| 465 |
| 466 // Use named gamma with custom primaries, if possible. |
| 430 SkMatrix44 to_xyz_d50; | 467 SkMatrix44 to_xyz_d50; |
| 431 GetPrimaryMatrix(&to_xyz_d50); | 468 GetPrimaryMatrix(&to_xyz_d50); |
| 469 if (has_named_gamma) |
| 470 return SkColorSpace::MakeRGB(named_gamma, to_xyz_d50); |
| 432 | 471 |
| 433 // Use the named sRGB and linear transfer functions. | 472 // Use the parametric transfer function if there is no named transfer |
| 434 if (transfer_ == TransferID::IEC61966_2_1) { | 473 // function. |
| 435 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, | |
| 436 to_xyz_d50); | |
| 437 } | |
| 438 if (transfer_ == TransferID::LINEAR || transfer_ == TransferID::LINEAR_HDR) { | |
| 439 return SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, | |
| 440 to_xyz_d50); | |
| 441 } | |
| 442 | |
| 443 // Use the parametric transfer function if no other option is available. | |
| 444 SkColorSpaceTransferFn fn; | 474 SkColorSpaceTransferFn fn; |
| 445 if (!GetTransferFunction(&fn)) { | 475 if (!GetTransferFunction(&fn)) { |
| 446 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; | 476 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; |
| 447 return nullptr; | 477 return nullptr; |
| 448 } | 478 } |
| 479 if (has_named_gamut) |
| 480 return SkColorSpace::MakeRGB(fn, named_gamut); |
| 449 return SkColorSpace::MakeRGB(fn, to_xyz_d50); | 481 return SkColorSpace::MakeRGB(fn, to_xyz_d50); |
| 450 } | 482 } |
| 451 | 483 |
| 452 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { | 484 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { |
| 453 if (!IsValid()) { | 485 if (!IsValid()) { |
| 454 DLOG(ERROR) << "Cannot fetch ICCProfile for invalid space."; | 486 DLOG(ERROR) << "Cannot fetch ICCProfile for invalid space."; |
| 455 return false; | 487 return false; |
| 456 } | 488 } |
| 457 if (matrix_ != MatrixID::RGB) { | 489 if (matrix_ != MatrixID::RGB) { |
| 458 DLOG(ERROR) << "Not creating non-RGB ICCProfile"; | 490 DLOG(ERROR) << "Not creating non-RGB ICCProfile"; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); | 869 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); |
| 838 break; | 870 break; |
| 839 } | 871 } |
| 840 } | 872 } |
| 841 | 873 |
| 842 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { | 874 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { |
| 843 return out << color_space.ToString(); | 875 return out << color_space.ToString(); |
| 844 } | 876 } |
| 845 | 877 |
| 846 } // namespace gfx | 878 } // namespace gfx |
| OLD | NEW |