| 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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 steps_.push_back(base::MakeUnique<ColorTransformFromLinear>(to.transfer_)); | 739 steps_.push_back(base::MakeUnique<ColorTransformFromLinear>(to.transfer_)); |
| 740 } | 740 } |
| 741 | 741 |
| 742 steps_.push_back( | 742 steps_.push_back( |
| 743 base::MakeUnique<ColorTransformMatrix>(GetTransferMatrix(to))); | 743 base::MakeUnique<ColorTransformMatrix>(GetTransferMatrix(to))); |
| 744 | 744 |
| 745 steps_.push_back( | 745 steps_.push_back( |
| 746 base::MakeUnique<ColorTransformMatrix>(Invert(GetRangeAdjustMatrix(to)))); | 746 base::MakeUnique<ColorTransformMatrix>(Invert(GetRangeAdjustMatrix(to)))); |
| 747 } | 747 } |
| 748 | 748 |
| 749 // TODO(ccameron): Change this to SkColorSpaceXform. |
| 749 class QCMSColorTransform : public ColorTransformStep { | 750 class QCMSColorTransform : public ColorTransformStep { |
| 750 public: | 751 public: |
| 751 // Takes ownership of the profiles | 752 // Takes ownership of the profiles |
| 752 QCMSColorTransform(ScopedQcmsProfile from, ScopedQcmsProfile to) | 753 QCMSColorTransform(ScopedQcmsProfile from, ScopedQcmsProfile to) |
| 753 : from_(std::move(from)), to_(std::move(to)) {} | 754 : from_(std::move(from)), to_(std::move(to)) {} |
| 754 ~QCMSColorTransform() override {} | 755 ~QCMSColorTransform() override {} |
| 755 QCMSColorTransform* GetQCMS() override { return this; } | 756 QCMSColorTransform* GetQCMS() override { return this; } |
| 756 bool Join(ColorTransformStep* next_untyped) override { | 757 bool Join(ColorTransformStep* next_untyped) override { |
| 757 QCMSColorTransform* next = next_untyped->GetQCMS(); | 758 QCMSColorTransform* next = next_untyped->GetQCMS(); |
| 758 if (!next) | 759 if (!next) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 781 reinterpret_cast<float*>(colors), num * 3); | 782 reinterpret_cast<float*>(colors), num * 3); |
| 782 } | 783 } |
| 783 | 784 |
| 784 private: | 785 private: |
| 785 ScopedQcmsProfile from_; | 786 ScopedQcmsProfile from_; |
| 786 ScopedQcmsProfile to_; | 787 ScopedQcmsProfile to_; |
| 787 }; | 788 }; |
| 788 | 789 |
| 789 ScopedQcmsProfile ColorTransformInternal::GetQCMSProfileIfNecessary( | 790 ScopedQcmsProfile ColorTransformInternal::GetQCMSProfileIfNecessary( |
| 790 const ColorSpace& color_space) { | 791 const ColorSpace& color_space) { |
| 792 if (color_space.primaries_ != ColorSpace::PrimaryID::ICC_BASED && |
| 793 color_space.transfer_ != ColorSpace::TransferID::ICC_BASED) { |
| 794 return nullptr; |
| 795 } |
| 796 // TODO(ccameron): Use SkColorSpaceXform here to avoid looking up the |
| 797 // ICCProfile. |
| 791 ICCProfile icc_profile; | 798 ICCProfile icc_profile; |
| 792 if (!ICCProfile::FromId(color_space.icc_profile_id_, true, &icc_profile)) | 799 if (!ICCProfile::FromId(color_space.icc_profile_id_, &icc_profile)) { |
| 793 return nullptr; | 800 // We needed the original ICC profile to construct this transform, but it |
| 801 // has been flushed from our cache. Fall back to using the ICC profile's |
| 802 // inaccurate, so spam the console. |
| 803 // TODO(ccameron): This will go away when we switch to SkColorSpaceXform. |
| 804 LOG(ERROR) << "Failed to retrieve original ICC profile, using sRGB"; |
| 805 return ScopedQcmsProfile(qcms_profile_sRGB()); |
| 806 } |
| 794 return ScopedQcmsProfile(qcms_profile_from_memory( | 807 return ScopedQcmsProfile(qcms_profile_from_memory( |
| 795 icc_profile.GetData().data(), icc_profile.GetData().size())); | 808 icc_profile.GetData().data(), icc_profile.GetData().size())); |
| 796 } | 809 } |
| 797 | 810 |
| 798 ScopedQcmsProfile GetXYZD50Profile() { | 811 ScopedQcmsProfile GetXYZD50Profile() { |
| 799 // QCMS is trixy, it has a datatype called qcms_CIE_xyY, but what it expects | 812 // QCMS is trixy, it has a datatype called qcms_CIE_xyY, but what it expects |
| 800 // is in fact not xyY color coordinates, it just wants the x/y values of the | 813 // is in fact not xyY color coordinates, it just wants the x/y values of the |
| 801 // primaries with Y equal to 1.0. | 814 // primaries with Y equal to 1.0. |
| 802 qcms_CIE_xyYTRIPLE xyz; | 815 qcms_CIE_xyYTRIPLE xyz; |
| 803 qcms_CIE_xyY w; | 816 qcms_CIE_xyY w; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 const ColorSpace& to, | 926 const ColorSpace& to, |
| 914 Intent intent) { | 927 Intent intent) { |
| 915 return std::unique_ptr<ColorTransform>( | 928 return std::unique_ptr<ColorTransform>( |
| 916 new ColorTransformInternal(from, to, intent)); | 929 new ColorTransformInternal(from, to, intent)); |
| 917 } | 930 } |
| 918 | 931 |
| 919 ColorTransform::ColorTransform() {} | 932 ColorTransform::ColorTransform() {} |
| 920 ColorTransform::~ColorTransform() {} | 933 ColorTransform::~ColorTransform() {} |
| 921 | 934 |
| 922 } // namespace gfx | 935 } // namespace gfx |
| OLD | NEW |