Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/gfx/color_transform.h" | 5 #include "ui/gfx/color_transform.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <cmath> | 8 #include <cmath> | 
| 9 #include <list> | 9 #include <list> | 
| 10 #include <memory> | 10 #include <memory> | 
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 step->Transform(colors, num); | 270 step->Transform(colors, num); | 
| 271 } | 271 } | 
| 272 size_t NumberOfStepsForTesting() const override { return steps_.size(); } | 272 size_t NumberOfStepsForTesting() const override { return steps_.size(); } | 
| 273 | 273 | 
| 274 private: | 274 private: | 
| 275 void AppendColorSpaceToColorSpaceTransform(ColorSpace from, | 275 void AppendColorSpaceToColorSpaceTransform(ColorSpace from, | 
| 276 const ColorSpace& to, | 276 const ColorSpace& to, | 
| 277 ColorTransform::Intent intent); | 277 ColorTransform::Intent intent); | 
| 278 void Simplify(); | 278 void Simplify(); | 
| 279 | 279 | 
| 280 // Retrieve the ICC profile from which |color_space| was created, only if that | |
| 281 // is a more precise representation of the color space than the primaries and | |
| 282 // transfer function in |color_space|. | |
| 283 ScopedQcmsProfile GetQCMSProfileIfNecessary(const ColorSpace& color_space); | |
| 284 | |
| 280 std::list<std::unique_ptr<ColorTransformStep>> steps_; | 285 std::list<std::unique_ptr<ColorTransformStep>> steps_; | 
| 281 }; | 286 }; | 
| 282 | 287 | 
| 283 class ColorTransformNull : public ColorTransformStep { | 288 class ColorTransformNull : public ColorTransformStep { | 
| 284 public: | 289 public: | 
| 285 ColorTransformNull* GetNull() override { return this; } | 290 ColorTransformNull* GetNull() override { return this; } | 
| 286 bool IsNull() override { return true; } | 291 bool IsNull() override { return true; } | 
| 287 void Transform(ColorTransform::TriStim* color, size_t num) override {} | 292 void Transform(ColorTransform::TriStim* color, size_t num) override {} | 
| 288 }; | 293 }; | 
| 289 | 294 | 
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 } | 538 } | 
| 534 | 539 | 
| 535 private: | 540 private: | 
| 536 bool null_ = false; | 541 bool null_ = false; | 
| 537 }; | 542 }; | 
| 538 | 543 | 
| 539 void ColorTransformInternal::AppendColorSpaceToColorSpaceTransform( | 544 void ColorTransformInternal::AppendColorSpaceToColorSpaceTransform( | 
| 540 ColorSpace from, | 545 ColorSpace from, | 
| 541 const ColorSpace& to, | 546 const ColorSpace& to, | 
| 542 ColorTransform::Intent intent) { | 547 ColorTransform::Intent intent) { | 
| 548 // If the source was not specified, assume that it was sRGB. | |
| 549 if (!from.IsValid()) | |
| 
 
hubbe
2017/02/16 08:33:02
Can we just remove this?
 
ccameron
2017/02/16 22:33:10
Oops, yes, that was dead code.
 
 | |
| 550 from = gfx::ColorSpace::CreateSRGB(); | |
| 551 | |
| 543 if (intent == ColorTransform::Intent::INTENT_PERCEPTUAL) { | 552 if (intent == ColorTransform::Intent::INTENT_PERCEPTUAL) { | 
| 544 switch (from.transfer_) { | 553 switch (from.transfer_) { | 
| 545 case ColorSpace::TransferID::BT709: | 554 case ColorSpace::TransferID::BT709: | 
| 546 case ColorSpace::TransferID::SMPTE170M: | 555 case ColorSpace::TransferID::SMPTE170M: | 
| 547 // SMPTE 1886 suggests that we should be using gamma 2.4 for BT709 | 556 // SMPTE 1886 suggests that we should be using gamma 2.4 for BT709 | 
| 548 // content. However, most displays actually use a gamma of 2.2, and | 557 // content. However, most displays actually use a gamma of 2.2, and | 
| 549 // user studies shows that users don't really care. Using the same | 558 // user studies shows that users don't really care. Using the same | 
| 550 // gamma as the display will let us optimize a lot more, so lets stick | 559 // gamma as the display will let us optimize a lot more, so lets stick | 
| 551 // with using the SRGB transfer function. | 560 // with using the SRGB transfer function. | 
| 552 from.transfer_ = ColorSpace::TransferID::IEC61966_2_1; | 561 from.transfer_ = ColorSpace::TransferID::IEC61966_2_1; | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 qcms_chain_transform(from_.get(), to_.get(), | 655 qcms_chain_transform(from_.get(), to_.get(), | 
| 647 reinterpret_cast<float*>(colors), | 656 reinterpret_cast<float*>(colors), | 
| 648 reinterpret_cast<float*>(colors), num * 3); | 657 reinterpret_cast<float*>(colors), num * 3); | 
| 649 } | 658 } | 
| 650 | 659 | 
| 651 private: | 660 private: | 
| 652 ScopedQcmsProfile from_; | 661 ScopedQcmsProfile from_; | 
| 653 ScopedQcmsProfile to_; | 662 ScopedQcmsProfile to_; | 
| 654 }; | 663 }; | 
| 655 | 664 | 
| 656 ScopedQcmsProfile GetQCMSProfileIfAvailable(const ColorSpace& color_space) { | 665 ScopedQcmsProfile ColorTransformInternal::GetQCMSProfileIfNecessary( | 
| 657 ICCProfile icc_profile = ICCProfile::FromColorSpace(color_space); | 666 const ColorSpace& color_space) { | 
| 658 if (icc_profile.GetData().empty()) | 667 ICCProfile icc_profile; | 
| 668 if (!ICCProfile::FromId(color_space.icc_profile_id_, true, &icc_profile)) | |
| 659 return nullptr; | 669 return nullptr; | 
| 660 return ScopedQcmsProfile(qcms_profile_from_memory( | 670 return ScopedQcmsProfile(qcms_profile_from_memory( | 
| 661 icc_profile.GetData().data(), icc_profile.GetData().size())); | 671 icc_profile.GetData().data(), icc_profile.GetData().size())); | 
| 662 } | 672 } | 
| 663 | 673 | 
| 664 ScopedQcmsProfile GetXYZD50Profile() { | 674 ScopedQcmsProfile GetXYZD50Profile() { | 
| 665 // QCMS is trixy, it has a datatype called qcms_CIE_xyY, but what it expects | 675 // QCMS is trixy, it has a datatype called qcms_CIE_xyY, but what it expects | 
| 666 // is in fact not xyY color coordinates, it just wants the x/y values of the | 676 // is in fact not xyY color coordinates, it just wants the x/y values of the | 
| 667 // primaries with Y equal to 1.0. | 677 // primaries with Y equal to 1.0. | 
| 668 qcms_CIE_xyYTRIPLE xyz; | 678 qcms_CIE_xyYTRIPLE xyz; | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 683 } | 693 } | 
| 684 | 694 | 
| 685 ColorTransformInternal::ColorTransformInternal(const ColorSpace& from, | 695 ColorTransformInternal::ColorTransformInternal(const ColorSpace& from, | 
| 686 const ColorSpace& to, | 696 const ColorSpace& to, | 
| 687 Intent intent) { | 697 Intent intent) { | 
| 688 // If no source color space is specified, do no transformation. | 698 // If no source color space is specified, do no transformation. | 
| 689 // TODO(ccameron): We may want to assume sRGB at some point in the future. | 699 // TODO(ccameron): We may want to assume sRGB at some point in the future. | 
| 690 if (!from.IsValid()) | 700 if (!from.IsValid()) | 
| 691 return; | 701 return; | 
| 692 | 702 | 
| 693 ScopedQcmsProfile from_profile = GetQCMSProfileIfAvailable(from); | 703 ScopedQcmsProfile from_profile = GetQCMSProfileIfNecessary(from); | 
| 694 ScopedQcmsProfile to_profile = GetQCMSProfileIfAvailable(to); | 704 ScopedQcmsProfile to_profile = GetQCMSProfileIfNecessary(to); | 
| 695 bool has_from_profile = !!from_profile; | 705 bool has_from_profile = !!from_profile; | 
| 696 bool has_to_profile = !!to_profile; | 706 bool has_to_profile = !!to_profile; | 
| 697 | 707 | 
| 698 if (from_profile) { | 708 if (from_profile) { | 
| 699 steps_.push_back(base::MakeUnique<QCMSColorTransform>( | 709 steps_.push_back(base::MakeUnique<QCMSColorTransform>( | 
| 700 std::move(from_profile), GetXYZD50Profile())); | 710 std::move(from_profile), GetXYZD50Profile())); | 
| 701 } | 711 } | 
| 702 | 712 | 
| 703 AppendColorSpaceToColorSpaceTransform( | 713 AppendColorSpaceToColorSpaceTransform( | 
| 704 has_from_profile ? ColorSpace::CreateXYZD50() : from, | 714 has_from_profile ? ColorSpace::CreateXYZD50() : from, | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 const ColorSpace& to, | 762 const ColorSpace& to, | 
| 753 Intent intent) { | 763 Intent intent) { | 
| 754 return std::unique_ptr<ColorTransform>( | 764 return std::unique_ptr<ColorTransform>( | 
| 755 new ColorTransformInternal(from, to, intent)); | 765 new ColorTransformInternal(from, to, intent)); | 
| 756 } | 766 } | 
| 757 | 767 | 
| 758 ColorTransform::ColorTransform() {} | 768 ColorTransform::ColorTransform() {} | 
| 759 ColorTransform::~ColorTransform() {} | 769 ColorTransform::~ColorTransform() {} | 
| 760 | 770 | 
| 761 } // namespace gfx | 771 } // namespace gfx | 
| OLD | NEW |