| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 step->Transform(colors, num); | 266 step->Transform(colors, num); |
| 267 } | 267 } |
| 268 size_t NumberOfStepsForTesting() const override { return steps_.size(); } | 268 size_t NumberOfStepsForTesting() const override { return steps_.size(); } |
| 269 | 269 |
| 270 private: | 270 private: |
| 271 void AppendColorSpaceToColorSpaceTransform(ColorSpace from, | 271 void AppendColorSpaceToColorSpaceTransform(ColorSpace from, |
| 272 const ColorSpace& to, | 272 const ColorSpace& to, |
| 273 ColorTransform::Intent intent); | 273 ColorTransform::Intent intent); |
| 274 void Simplify(); | 274 void Simplify(); |
| 275 | 275 |
| 276 // Retrieve the ICC profile from which |color_space| was created, only if that |
| 277 // is a more precise representation of the color space than the primaries and |
| 278 // transfer function in |color_space|. |
| 279 ScopedQcmsProfile GetQCMSProfileIfNecessary(const ColorSpace& color_space); |
| 280 |
| 276 std::list<std::unique_ptr<ColorTransformStep>> steps_; | 281 std::list<std::unique_ptr<ColorTransformStep>> steps_; |
| 277 }; | 282 }; |
| 278 | 283 |
| 279 class ColorTransformNull : public ColorTransformStep { | 284 class ColorTransformNull : public ColorTransformStep { |
| 280 public: | 285 public: |
| 281 ColorTransformNull* GetNull() override { return this; } | 286 ColorTransformNull* GetNull() override { return this; } |
| 282 bool IsNull() override { return true; } | 287 bool IsNull() override { return true; } |
| 283 void Transform(ColorTransform::TriStim* color, size_t num) override {} | 288 void Transform(ColorTransform::TriStim* color, size_t num) override {} |
| 284 }; | 289 }; |
| 285 | 290 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 qcms_chain_transform(from_.get(), to_.get(), | 648 qcms_chain_transform(from_.get(), to_.get(), |
| 644 reinterpret_cast<float*>(colors), | 649 reinterpret_cast<float*>(colors), |
| 645 reinterpret_cast<float*>(colors), num * 3); | 650 reinterpret_cast<float*>(colors), num * 3); |
| 646 } | 651 } |
| 647 | 652 |
| 648 private: | 653 private: |
| 649 ScopedQcmsProfile from_; | 654 ScopedQcmsProfile from_; |
| 650 ScopedQcmsProfile to_; | 655 ScopedQcmsProfile to_; |
| 651 }; | 656 }; |
| 652 | 657 |
| 653 ScopedQcmsProfile GetQCMSProfileIfAvailable(const ColorSpace& color_space) { | 658 ScopedQcmsProfile ColorTransformInternal::GetQCMSProfileIfNecessary( |
| 654 ICCProfile icc_profile = ICCProfile::FromColorSpace(color_space); | 659 const ColorSpace& color_space) { |
| 655 if (icc_profile.GetData().empty()) | 660 ICCProfile icc_profile; |
| 661 if (!ICCProfile::FromId(color_space.icc_profile_id_, true, &icc_profile)) |
| 656 return nullptr; | 662 return nullptr; |
| 657 return ScopedQcmsProfile(qcms_profile_from_memory( | 663 return ScopedQcmsProfile(qcms_profile_from_memory( |
| 658 icc_profile.GetData().data(), icc_profile.GetData().size())); | 664 icc_profile.GetData().data(), icc_profile.GetData().size())); |
| 659 } | 665 } |
| 660 | 666 |
| 661 ScopedQcmsProfile GetXYZD50Profile() { | 667 ScopedQcmsProfile GetXYZD50Profile() { |
| 662 // QCMS is trixy, it has a datatype called qcms_CIE_xyY, but what it expects | 668 // QCMS is trixy, it has a datatype called qcms_CIE_xyY, but what it expects |
| 663 // is in fact not xyY color coordinates, it just wants the x/y values of the | 669 // is in fact not xyY color coordinates, it just wants the x/y values of the |
| 664 // primaries with Y equal to 1.0. | 670 // primaries with Y equal to 1.0. |
| 665 qcms_CIE_xyYTRIPLE xyz; | 671 qcms_CIE_xyYTRIPLE xyz; |
| 666 qcms_CIE_xyY w; | 672 qcms_CIE_xyY w; |
| 667 xyz.red.x = 1.0f; | 673 xyz.red.x = 1.0f; |
| 668 xyz.red.y = 0.0f; | 674 xyz.red.y = 0.0f; |
| 669 xyz.red.Y = 1.0f; | 675 xyz.red.Y = 1.0f; |
| 670 xyz.green.x = 0.0f; | 676 xyz.green.x = 0.0f; |
| 671 xyz.green.y = 1.0f; | 677 xyz.green.y = 1.0f; |
| 672 xyz.green.Y = 1.0f; | 678 xyz.green.Y = 1.0f; |
| 673 xyz.blue.x = 0.0f; | 679 xyz.blue.x = 0.0f; |
| 674 xyz.blue.y = 0.0f; | 680 xyz.blue.y = 0.0f; |
| 675 xyz.blue.Y = 1.0f; | 681 xyz.blue.Y = 1.0f; |
| 676 w.x = 0.34567f; | 682 w.x = 0.34567f; |
| 677 w.y = 0.35850f; | 683 w.y = 0.35850f; |
| 678 w.Y = 1.0f; | 684 w.Y = 1.0f; |
| 679 return ScopedQcmsProfile(qcms_profile_create_rgb_with_gamma(w, xyz, 1.0f)); | 685 return ScopedQcmsProfile(qcms_profile_create_rgb_with_gamma(w, xyz, 1.0f)); |
| 680 } | 686 } |
| 681 | 687 |
| 682 ColorTransformInternal::ColorTransformInternal(const ColorSpace& from, | 688 ColorTransformInternal::ColorTransformInternal(const ColorSpace& from, |
| 683 const ColorSpace& to, | 689 const ColorSpace& to, |
| 684 Intent intent) { | 690 Intent intent) { |
| 685 ScopedQcmsProfile from_profile = GetQCMSProfileIfAvailable(from); | 691 ScopedQcmsProfile from_profile = GetQCMSProfileIfNecessary(from); |
| 686 ScopedQcmsProfile to_profile = GetQCMSProfileIfAvailable(to); | 692 ScopedQcmsProfile to_profile = GetQCMSProfileIfNecessary(to); |
| 687 bool has_from_profile = !!from_profile; | 693 bool has_from_profile = !!from_profile; |
| 688 bool has_to_profile = !!to_profile; | 694 bool has_to_profile = !!to_profile; |
| 689 | 695 |
| 690 if (from_profile) { | 696 if (from_profile) { |
| 691 steps_.push_back(base::MakeUnique<QCMSColorTransform>( | 697 steps_.push_back(base::MakeUnique<QCMSColorTransform>( |
| 692 std::move(from_profile), GetXYZD50Profile())); | 698 std::move(from_profile), GetXYZD50Profile())); |
| 693 } | 699 } |
| 694 | 700 |
| 695 AppendColorSpaceToColorSpaceTransform( | 701 AppendColorSpaceToColorSpaceTransform( |
| 696 has_from_profile ? ColorSpace::CreateXYZD50() : from, | 702 has_from_profile ? ColorSpace::CreateXYZD50() : from, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 // static | 745 // static |
| 740 std::unique_ptr<ColorTransform> ColorTransform::NewColorTransform( | 746 std::unique_ptr<ColorTransform> ColorTransform::NewColorTransform( |
| 741 const ColorSpace& from, | 747 const ColorSpace& from, |
| 742 const ColorSpace& to, | 748 const ColorSpace& to, |
| 743 Intent intent) { | 749 Intent intent) { |
| 744 return std::unique_ptr<ColorTransform>( | 750 return std::unique_ptr<ColorTransform>( |
| 745 new ColorTransformInternal(from, to, intent)); | 751 new ColorTransformInternal(from, to, intent)); |
| 746 } | 752 } |
| 747 | 753 |
| 748 } // namespace gfx | 754 } // namespace gfx |
| OLD | NEW |