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

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

Issue 2502703002: Add more robust gfx::ColorSpace<->gfx::ICCProfile conversion (Closed)
Patch Set: Clean up includes 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
« no previous file with comments | « ui/gfx/icc_profile.h ('k') | ui/gfx/ipc/color/gfx_param_traits_macros.h » ('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 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 25 matching lines...) Expand all
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 bool ICCProfile::operator==(const ICCProfile& other) const { 45 bool ICCProfile::operator==(const ICCProfile& other) const {
46 return valid_ == other.valid_ && data_ == other.data_; 46 if (type_ != other.type_)
47 return false;
48 switch (type_) {
49 case Type::INVALID:
50 return true;
51 case Type::FROM_COLOR_SPACE:
52 return color_space_ == other.color_space_;
53 case Type::FROM_DATA:
54 return data_ == other.data_;
55 }
56 return false;
47 } 57 }
48 58
49 // static 59 // static
50 ICCProfile ICCProfile::FromData(const char* data, size_t size) { 60 ICCProfile ICCProfile::FromData(const char* data, size_t size) {
51 ICCProfile icc_profile; 61 ICCProfile icc_profile;
52 if (IsValidProfileLength(size)) { 62 if (IsValidProfileLength(size)) {
53 icc_profile.valid_ = true; 63 icc_profile.type_ = Type::FROM_DATA;
54 icc_profile.data_.insert(icc_profile.data_.begin(), data, data + size); 64 icc_profile.data_.insert(icc_profile.data_.begin(), data, data + size);
65 } else {
66 return ICCProfile();
55 } 67 }
56 if (!icc_profile.valid_)
57 return icc_profile;
58 68
59 Cache& cache = g_cache.Get(); 69 Cache& cache = g_cache.Get();
60 base::AutoLock lock(cache.lock); 70 base::AutoLock lock(cache.lock);
61 71
62 // Linearly search the cached ICC profiles to find one with the same data. 72 // Linearly search the cached ICC profiles to find one with the same data.
63 // If it exists, re-use its id and touch it in the cache. 73 // If it exists, re-use its id and touch it in the cache.
64 for (auto iter = cache.id_to_icc_profile_mru.begin(); 74 for (auto iter = cache.id_to_icc_profile_mru.begin();
65 iter != cache.id_to_icc_profile_mru.end(); ++iter) { 75 iter != cache.id_to_icc_profile_mru.end(); ++iter) {
66 if (icc_profile.data_ == iter->second.data_) { 76 if (icc_profile.data_ == iter->second.data_) {
67 icc_profile.id_ = iter->second.id_; 77 icc_profile.id_ = iter->second.id_;
(...skipping 10 matching lines...) Expand all
78 88
79 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11) 89 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11)
80 // static 90 // static
81 ICCProfile ICCProfile::FromBestMonitor() { 91 ICCProfile ICCProfile::FromBestMonitor() {
82 return ICCProfile(); 92 return ICCProfile();
83 } 93 }
84 #endif 94 #endif
85 95
86 // static 96 // static
87 ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) { 97 ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) {
88 // Retrieve ICC profiles from the cache. 98 if (color_space == gfx::ColorSpace())
99 return ICCProfile();
100
101 // If |color_space| was created from an ICC profile, retrieve that exact
102 // profile.
89 if (color_space.icc_profile_id_) { 103 if (color_space.icc_profile_id_) {
90 Cache& cache = g_cache.Get(); 104 Cache& cache = g_cache.Get();
91 base::AutoLock lock(cache.lock); 105 base::AutoLock lock(cache.lock);
92 106
93 auto found = cache.id_to_icc_profile_mru.Get(color_space.icc_profile_id_); 107 auto found = cache.id_to_icc_profile_mru.Get(color_space.icc_profile_id_);
94 if (found != cache.id_to_icc_profile_mru.end()) { 108 if (found != cache.id_to_icc_profile_mru.end()) {
95 return found->second; 109 return found->second;
96 } 110 }
97 } 111 }
112
98 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace 113 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace
99 // objects. 114 // objects.
100 return ICCProfile(); 115 ICCProfile icc_profile;
116 icc_profile.type_ = gfx::ICCProfile::Type::FROM_COLOR_SPACE;
117 icc_profile.color_space_ = color_space;
118 return icc_profile;
101 } 119 }
102 120
103 const std::vector<char>& ICCProfile::GetData() const { 121 const std::vector<char>& ICCProfile::GetData() const {
104 return data_; 122 return data_;
105 } 123 }
106 124
107 ColorSpace ICCProfile::GetColorSpace() const { 125 ColorSpace ICCProfile::GetColorSpace() const {
108 if (!valid_) 126 if (type_ == Type::INVALID)
109 return gfx::ColorSpace(); 127 return gfx::ColorSpace();
128 if (type_ == Type::FROM_COLOR_SPACE)
129 return color_space_;
110 130
111 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM, 131 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM,
112 ColorSpace::TransferID::CUSTOM, 132 ColorSpace::TransferID::CUSTOM,
113 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); 133 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL);
114 color_space.icc_profile_id_ = id_; 134 color_space.icc_profile_id_ = id_;
115 135
116 // Move this ICC profile to the most recently used end of the cache. 136 // Move this ICC profile to the most recently used end of the cache.
117 { 137 {
118 Cache& cache = g_cache.Get(); 138 Cache& cache = g_cache.Get();
119 base::AutoLock lock(cache.lock); 139 base::AutoLock lock(cache.lock);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 188
169 return color_space; 189 return color_space;
170 } 190 }
171 191
172 // static 192 // static
173 bool ICCProfile::IsValidProfileLength(size_t length) { 193 bool ICCProfile::IsValidProfileLength(size_t length) {
174 return length >= kMinProfileLength && length <= kMaxProfileLength; 194 return length >= kMinProfileLength && length <= kMaxProfileLength;
175 } 195 }
176 196
177 } // namespace gfx 197 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/icc_profile.h ('k') | ui/gfx/ipc/color/gfx_param_traits_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698