| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 return nullptr; | 427 return nullptr; |
| 428 } | 428 } |
| 429 if (range_ != RangeID::FULL) { | 429 if (range_ != RangeID::FULL) { |
| 430 DLOG(ERROR) << "Not creating non-full-range SkColorSpace"; | 430 DLOG(ERROR) << "Not creating non-full-range SkColorSpace"; |
| 431 return nullptr; | 431 return nullptr; |
| 432 } | 432 } |
| 433 | 433 |
| 434 SkMatrix44 primaries; | 434 SkMatrix44 primaries; |
| 435 GetPrimaryMatrix(&primaries); | 435 GetPrimaryMatrix(&primaries); |
| 436 SkColorSpaceTransferFn tr_fn; | 436 SkColorSpaceTransferFn tr_fn; |
| 437 bool get_tr_fn_result = GetTransferFunction(&tr_fn); | 437 if (!GetTransferFunction(&tr_fn)) { |
| 438 if (!get_tr_fn_result) { | 438 DLOG(ERROR) << "Not creating non-parametric nonlinear-blended SkColorSpace"; |
| 439 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; | 439 return nullptr; |
| 440 CreateSRGB().GetTransferFunction(&tr_fn); | |
| 441 } | 440 } |
| 442 sk_sp<SkColorSpace> result = SkColorSpace::MakeRGB( | 441 return SkColorSpace::MakeRGB(tr_fn, primaries, |
| 443 tr_fn, primaries, SkColorSpace::kNonLinearBlending_ColorSpaceFlag); | 442 SkColorSpace::kNonLinearBlending_ColorSpaceFlag); |
| 444 if (!result) { | |
| 445 DLOG(ERROR) << "Failed to create nonlinearly blended SkColorSpace"; | |
| 446 CreateSRGB().GetTransferFunction(&tr_fn); | |
| 447 } | |
| 448 return result; | |
| 449 } | 443 } |
| 450 | 444 |
| 451 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { | 445 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { |
| 452 if (!IsValid()) { | 446 if (!IsValid()) { |
| 453 DLOG(ERROR) << "Cannot fetch ICCProfile for invalid space."; | 447 DLOG(ERROR) << "Cannot fetch ICCProfile for invalid space."; |
| 454 return false; | 448 return false; |
| 455 } | 449 } |
| 456 if (matrix_ != MatrixID::RGB) { | 450 if (matrix_ != MatrixID::RGB) { |
| 457 DLOG(ERROR) << "Not creating non-RGB ICCProfile"; | 451 DLOG(ERROR) << "Not creating non-RGB ICCProfile"; |
| 458 return false; | 452 return false; |
| 459 } | 453 } |
| 460 if (range_ != RangeID::FULL) { | 454 if (range_ != RangeID::FULL) { |
| 461 DLOG(ERROR) << "Not creating non-full-range ICCProfile"; | 455 DLOG(ERROR) << "Not creating non-full-range ICCProfile"; |
| 462 return false; | 456 return false; |
| 463 } | 457 } |
| 464 | 458 |
| 465 // If this was created from an ICC profile, retrieve that exact profile. | 459 // If this was created from an ICC profile, retrieve that exact profile. |
| 466 ICCProfile result; | 460 ICCProfile result; |
| 467 if (ICCProfile::FromId(icc_profile_id_, false, icc_profile)) | 461 if (ICCProfile::FromId(icc_profile_id_, icc_profile)) |
| 468 return true; | 462 return true; |
| 469 | 463 |
| 470 // Otherwise, construct an ICC profile based on the best approximated | 464 // Otherwise, construct an ICC profile based on the best approximated |
| 471 // primaries and matrix. | 465 // primaries and matrix. |
| 472 SkMatrix44 to_XYZD50_matrix; | 466 SkMatrix44 to_XYZD50_matrix; |
| 473 GetPrimaryMatrix(&to_XYZD50_matrix); | 467 GetPrimaryMatrix(&to_XYZD50_matrix); |
| 474 SkColorSpaceTransferFn fn; | 468 SkColorSpaceTransferFn fn; |
| 475 if (!GetTransferFunction(&fn)) { | 469 if (!GetTransferFunction(&fn)) { |
| 476 DLOG(ERROR) << "Failed to get ColorSpace transfer function for ICCProfile."; | 470 DLOG(ERROR) << "Failed to get ColorSpace transfer function for ICCProfile."; |
| 477 return false; | 471 return false; |
| 478 } | 472 } |
| 479 sk_sp<SkData> data = SkICC::WriteToICC(fn, to_XYZD50_matrix); | 473 sk_sp<SkData> data = SkICC::WriteToICC(fn, to_XYZD50_matrix); |
| 480 if (!data) { | 474 if (!data) { |
| 481 DLOG(ERROR) << "Failed to create SkICC."; | 475 DLOG(ERROR) << "Failed to create SkICC."; |
| 482 return false; | 476 return false; |
| 483 } | 477 } |
| 484 *icc_profile = ICCProfile::FromData(data->data(), data->size()); | 478 *icc_profile = ICCProfile::FromData(data->data(), data->size()); |
| 485 DCHECK(icc_profile->IsValid()); | 479 DCHECK(icc_profile->IsValid()); |
| 486 return true; | 480 return true; |
| 487 } | 481 } |
| 488 | 482 |
| 489 void ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const { | 483 void ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const { |
| 490 SkColorSpacePrimaries primaries = {0}; | 484 SkColorSpacePrimaries primaries = {0}; |
| 491 switch (primaries_) { | 485 switch (primaries_) { |
| 492 case ColorSpace::PrimaryID::CUSTOM: | 486 case ColorSpace::PrimaryID::CUSTOM: |
| 493 to_XYZD50->set3x3RowMajorf(custom_primary_matrix_); | 487 to_XYZD50->set3x3RowMajorf(custom_primary_matrix_); |
| 494 return; | 488 return; |
| 495 | 489 |
| 496 case ColorSpace::PrimaryID::INVALID: | 490 case ColorSpace::PrimaryID::INVALID: |
| 491 case ColorSpace::PrimaryID::ICC_BASED: |
| 497 to_XYZD50->setIdentity(); | 492 to_XYZD50->setIdentity(); |
| 498 return; | 493 return; |
| 499 | 494 |
| 500 case ColorSpace::PrimaryID::BT709: | 495 case ColorSpace::PrimaryID::BT709: |
| 501 // BT709 is our default case. Put it after the switch just | 496 // BT709 is our default case. Put it after the switch just |
| 502 // in case we somehow get an id which is not listed in the switch. | 497 // in case we somehow get an id which is not listed in the switch. |
| 503 // (We don't want to use "default", because we want the compiler | 498 // (We don't want to use "default", because we want the compiler |
| 504 // to tell us if we forgot some enum values.) | 499 // to tell us if we forgot some enum values.) |
| 505 primaries.fRX = 0.640f; | 500 primaries.fRX = 0.640f; |
| 506 primaries.fRY = 0.330f; | 501 primaries.fRY = 0.330f; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 // This could potentially be represented the same as IEC61966_2_1, but | 687 // This could potentially be represented the same as IEC61966_2_1, but |
| 693 // it handles negative values differently. | 688 // it handles negative values differently. |
| 694 break; | 689 break; |
| 695 case ColorSpace::TransferID::ARIB_STD_B67: | 690 case ColorSpace::TransferID::ARIB_STD_B67: |
| 696 case ColorSpace::TransferID::BT1361_ECG: | 691 case ColorSpace::TransferID::BT1361_ECG: |
| 697 case ColorSpace::TransferID::LOG: | 692 case ColorSpace::TransferID::LOG: |
| 698 case ColorSpace::TransferID::LOG_SQRT: | 693 case ColorSpace::TransferID::LOG_SQRT: |
| 699 case ColorSpace::TransferID::SMPTEST2084: | 694 case ColorSpace::TransferID::SMPTEST2084: |
| 700 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: | 695 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: |
| 701 case ColorSpace::TransferID::INVALID: | 696 case ColorSpace::TransferID::INVALID: |
| 697 case ColorSpace::TransferID::ICC_BASED: |
| 702 break; | 698 break; |
| 703 } | 699 } |
| 704 | 700 |
| 705 return false; | 701 return false; |
| 706 } | 702 } |
| 707 | 703 |
| 708 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { | 704 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { |
| 709 if (!GetTransferFunction(fn)) | 705 if (!GetTransferFunction(fn)) |
| 710 return false; | 706 return false; |
| 711 *fn = SkTransferFnInverse(*fn); | 707 *fn = SkTransferFnInverse(*fn); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); | 830 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); |
| 835 break; | 831 break; |
| 836 } | 832 } |
| 837 } | 833 } |
| 838 | 834 |
| 839 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { | 835 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { |
| 840 return out << color_space.ToString(); | 836 return out << color_space.ToString(); |
| 841 } | 837 } |
| 842 | 838 |
| 843 } // namespace gfx | 839 } // namespace gfx |
| OLD | NEW |