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

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

Issue 2496913003: Display linear-srgb color managed canvas (Closed)
Patch Set: Addressing layout test issue Created 4 years, 1 month 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
« ui/gfx/color_space.cc ('K') | « ui/gfx/icc_profile.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 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/icc_profile.h" 5 #include "ui/gfx/icc_profile.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/containers/mru_cache.h" 9 #include "base/containers/mru_cache.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 24 matching lines...) Expand all
35 35
36 } // namespace 36 } // namespace
37 37
38 ICCProfile::ICCProfile() = default; 38 ICCProfile::ICCProfile() = default;
39 ICCProfile::ICCProfile(ICCProfile&& other) = default; 39 ICCProfile::ICCProfile(ICCProfile&& other) = default;
40 ICCProfile::ICCProfile(const ICCProfile& other) = default; 40 ICCProfile::ICCProfile(const ICCProfile& other) = default;
41 ICCProfile& ICCProfile::operator=(ICCProfile&& other) = default; 41 ICCProfile& ICCProfile::operator=(ICCProfile&& other) = default;
42 ICCProfile& ICCProfile::operator=(const ICCProfile& other) = default; 42 ICCProfile& ICCProfile::operator=(const ICCProfile& other) = default;
43 ICCProfile::~ICCProfile() = default; 43 ICCProfile::~ICCProfile() = default;
44 44
45 // Turn off color correct rendering by default.
46 bool ICCProfile::color_correct_rendering_ = false;
47
45 bool ICCProfile::operator==(const ICCProfile& other) const { 48 bool ICCProfile::operator==(const ICCProfile& other) const {
46 return valid_ == other.valid_ && data_ == other.data_; 49 return valid_ == other.valid_ && data_ == other.data_;
47 } 50 }
48 51
49 // static 52 // static
50 ICCProfile ICCProfile::FromData(const char* data, size_t size) { 53 ICCProfile ICCProfile::FromData(const char* data, size_t size) {
51 ICCProfile icc_profile; 54 ICCProfile icc_profile;
52 if (IsValidProfileLength(size)) { 55 if (IsValidProfileLength(size)) {
53 icc_profile.valid_ = true; 56 icc_profile.valid_ = true;
54 icc_profile.data_.insert(icc_profile.data_.begin(), data, data + size); 57 icc_profile.data_.insert(icc_profile.data_.begin(), data, data + size);
(...skipping 17 matching lines...) Expand all
72 75
73 // Create a new cached id and add it to the cache. 76 // Create a new cached id and add it to the cache.
74 icc_profile.id_ = cache.next_unused_id++; 77 icc_profile.id_ = cache.next_unused_id++;
75 cache.id_to_icc_profile_mru.Put(icc_profile.id_, icc_profile); 78 cache.id_to_icc_profile_mru.Put(icc_profile.id_, icc_profile);
76 return icc_profile; 79 return icc_profile;
77 } 80 }
78 81
79 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11) 82 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11)
80 // static 83 // static
81 ICCProfile ICCProfile::FromBestMonitor() { 84 ICCProfile ICCProfile::FromBestMonitor() {
85 if (color_correct_rendering_)
86 return gfx::ICCProfile::FromColorSpace(gfx::ColorSpace::CreateSRGB());
82 return ICCProfile(); 87 return ICCProfile();
83 } 88 }
84 #endif 89 #endif
85 90
86 // static 91 // static
87 ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) { 92 ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) {
88 // Retrieve ICC profiles from the cache. 93 // Retrieve ICC profiles from the cache.
89 if (color_space.icc_profile_id_) { 94 if (color_space.icc_profile_id_) {
90 Cache& cache = g_cache.Get(); 95 Cache& cache = g_cache.Get();
91 base::AutoLock lock(cache.lock); 96 base::AutoLock lock(cache.lock);
92 97
93 auto found = cache.id_to_icc_profile_mru.Get(color_space.icc_profile_id_); 98 auto found = cache.id_to_icc_profile_mru.Get(color_space.icc_profile_id_);
94 if (found != cache.id_to_icc_profile_mru.end()) { 99 if (found != cache.id_to_icc_profile_mru.end()) {
95 return found->second; 100 return found->second;
96 } 101 }
97 } 102 }
98 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace 103 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace
99 // objects. 104 // objects.
ccameron 2016/11/11 20:00:44 This part, doing gfx::ColorSpace->ICCProfile is br
100 return ICCProfile(); 105 return ICCProfile();
101 } 106 }
102 107
103 const std::vector<char>& ICCProfile::GetData() const { 108 const std::vector<char>& ICCProfile::GetData() const {
104 return data_; 109 return data_;
105 } 110 }
106 111
107 ColorSpace ICCProfile::GetColorSpace() const { 112 ColorSpace ICCProfile::GetColorSpace() const {
108 if (!valid_) 113 if (!valid_) {
114 if (color_correct_rendering_)
115 return gfx::ColorSpace::CreateSRGB();
109 return gfx::ColorSpace(); 116 return gfx::ColorSpace();
117 }
110 118
111 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM, 119 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM,
112 ColorSpace::TransferID::CUSTOM, 120 ColorSpace::TransferID::CUSTOM,
113 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); 121 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL);
114 color_space.icc_profile_id_ = id_; 122 color_space.icc_profile_id_ = id_;
115 123
116 // Move this ICC profile to the most recently used end of the cache. 124 // Move this ICC profile to the most recently used end of the cache.
117 { 125 {
118 Cache& cache = g_cache.Get(); 126 Cache& cache = g_cache.Get();
119 base::AutoLock lock(cache.lock); 127 base::AutoLock lock(cache.lock);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 color_space.custom_primary_matrix_[11] = tmp[3].z(); 175 color_space.custom_primary_matrix_[11] = tmp[3].z();
168 176
169 return color_space; 177 return color_space;
170 } 178 }
171 179
172 // static 180 // static
173 bool ICCProfile::IsValidProfileLength(size_t length) { 181 bool ICCProfile::IsValidProfileLength(size_t length) {
174 return length >= kMinProfileLength && length <= kMaxProfileLength; 182 return length >= kMinProfileLength && length <= kMaxProfileLength;
175 } 183 }
176 184
185 void ICCProfile::SetColorCorrectRendering(bool color_correct_rendering) {
186 color_correct_rendering_ = color_correct_rendering;
187 }
188
177 } // namespace gfx 189 } // namespace gfx
OLDNEW
« ui/gfx/color_space.cc ('K') | « ui/gfx/icc_profile.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698