Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: ui/gfx/color_transform.cc

Issue 2691213007: color: Don't use QCMS for transforms unless necessary (Closed)
Patch Set: Incorporate review feedback Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_space.cc ('k') | ui/gfx/color_transform_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 qcms_chain_transform(from_.get(), to_.get(), 651 qcms_chain_transform(from_.get(), to_.get(),
647 reinterpret_cast<float*>(colors), 652 reinterpret_cast<float*>(colors),
648 reinterpret_cast<float*>(colors), num * 3); 653 reinterpret_cast<float*>(colors), num * 3);
649 } 654 }
650 655
651 private: 656 private:
652 ScopedQcmsProfile from_; 657 ScopedQcmsProfile from_;
653 ScopedQcmsProfile to_; 658 ScopedQcmsProfile to_;
654 }; 659 };
655 660
656 ScopedQcmsProfile GetQCMSProfileIfAvailable(const ColorSpace& color_space) { 661 ScopedQcmsProfile ColorTransformInternal::GetQCMSProfileIfNecessary(
657 ICCProfile icc_profile = ICCProfile::FromColorSpace(color_space); 662 const ColorSpace& color_space) {
658 if (icc_profile.GetData().empty()) 663 ICCProfile icc_profile;
664 if (!ICCProfile::FromId(color_space.icc_profile_id_, true, &icc_profile))
659 return nullptr; 665 return nullptr;
660 return ScopedQcmsProfile(qcms_profile_from_memory( 666 return ScopedQcmsProfile(qcms_profile_from_memory(
661 icc_profile.GetData().data(), icc_profile.GetData().size())); 667 icc_profile.GetData().data(), icc_profile.GetData().size()));
662 } 668 }
663 669
664 ScopedQcmsProfile GetXYZD50Profile() { 670 ScopedQcmsProfile GetXYZD50Profile() {
665 // QCMS is trixy, it has a datatype called qcms_CIE_xyY, but what it expects 671 // 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 672 // is in fact not xyY color coordinates, it just wants the x/y values of the
667 // primaries with Y equal to 1.0. 673 // primaries with Y equal to 1.0.
668 qcms_CIE_xyYTRIPLE xyz; 674 qcms_CIE_xyYTRIPLE xyz;
(...skipping 14 matching lines...) Expand all
683 } 689 }
684 690
685 ColorTransformInternal::ColorTransformInternal(const ColorSpace& from, 691 ColorTransformInternal::ColorTransformInternal(const ColorSpace& from,
686 const ColorSpace& to, 692 const ColorSpace& to,
687 Intent intent) { 693 Intent intent) {
688 // If no source color space is specified, do no transformation. 694 // 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. 695 // TODO(ccameron): We may want to assume sRGB at some point in the future.
690 if (!from.IsValid()) 696 if (!from.IsValid())
691 return; 697 return;
692 698
693 ScopedQcmsProfile from_profile = GetQCMSProfileIfAvailable(from); 699 ScopedQcmsProfile from_profile = GetQCMSProfileIfNecessary(from);
694 ScopedQcmsProfile to_profile = GetQCMSProfileIfAvailable(to); 700 ScopedQcmsProfile to_profile = GetQCMSProfileIfNecessary(to);
695 bool has_from_profile = !!from_profile; 701 bool has_from_profile = !!from_profile;
696 bool has_to_profile = !!to_profile; 702 bool has_to_profile = !!to_profile;
697 703
698 if (from_profile) { 704 if (from_profile) {
699 steps_.push_back(base::MakeUnique<QCMSColorTransform>( 705 steps_.push_back(base::MakeUnique<QCMSColorTransform>(
700 std::move(from_profile), GetXYZD50Profile())); 706 std::move(from_profile), GetXYZD50Profile()));
701 } 707 }
702 708
703 AppendColorSpaceToColorSpaceTransform( 709 AppendColorSpaceToColorSpaceTransform(
704 has_from_profile ? ColorSpace::CreateXYZD50() : from, 710 has_from_profile ? ColorSpace::CreateXYZD50() : from,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 const ColorSpace& to, 758 const ColorSpace& to,
753 Intent intent) { 759 Intent intent) {
754 return std::unique_ptr<ColorTransform>( 760 return std::unique_ptr<ColorTransform>(
755 new ColorTransformInternal(from, to, intent)); 761 new ColorTransformInternal(from, to, intent));
756 } 762 }
757 763
758 ColorTransform::ColorTransform() {} 764 ColorTransform::ColorTransform() {}
759 ColorTransform::~ColorTransform() {} 765 ColorTransform::~ColorTransform() {}
760 766
761 } // namespace gfx 767 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_space.cc ('k') | ui/gfx/color_transform_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698