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

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

Issue 2271683004: Revert of Support for custom primaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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/icc_profile.h ('k') | ui/gfx/ipc/color/gfx_param_traits.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 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"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "ui/gfx/color_transform.h"
13 12
14 namespace gfx { 13 namespace gfx {
15 14
16 namespace { 15 namespace {
17 const size_t kMinProfileLength = 128; 16 const size_t kMinProfileLength = 128;
18 const size_t kMaxProfileLength = 4 * 1024 * 1024; 17 const size_t kMaxProfileLength = 4 * 1024 * 1024;
19 18
20 // Allow keeping around a maximum of 8 cached ICC profiles. Beware that 19 // Allow keeping around a maximum of 8 cached ICC profiles. Beware that
21 // we will do a linear search thorugh currently-cached ICC profiles, 20 // we will do a linear search thorugh currently-cached ICC profiles,
22 // when creating a new ICC profile. 21 // when creating a new ICC profile.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 #endif 83 #endif
85 84
86 // static 85 // static
87 ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) { 86 ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) {
88 // Retrieve ICC profiles from the cache. 87 // Retrieve ICC profiles from the cache.
89 if (color_space.icc_profile_id_) { 88 if (color_space.icc_profile_id_) {
90 Cache& cache = g_cache.Get(); 89 Cache& cache = g_cache.Get();
91 base::AutoLock lock(cache.lock); 90 base::AutoLock lock(cache.lock);
92 91
93 auto found = cache.id_to_icc_profile_mru.Get(color_space.icc_profile_id_); 92 auto found = cache.id_to_icc_profile_mru.Get(color_space.icc_profile_id_);
94 if (found != cache.id_to_icc_profile_mru.end()) { 93 if (found != cache.id_to_icc_profile_mru.end())
95 return found->second; 94 return found->second;
96 }
97 } 95 }
98 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace 96 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace
99 // objects. 97 // objects.
100 return ICCProfile(); 98 return ICCProfile();
101 } 99 }
102 100
103 const std::vector<char>& ICCProfile::GetData() const { 101 const std::vector<char>& ICCProfile::GetData() const {
104 return data_; 102 return data_;
105 } 103 }
106 104
107 ColorSpace ICCProfile::GetColorSpace() const { 105 ColorSpace ICCProfile::GetColorSpace() const {
108 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM, 106 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM,
109 ColorSpace::TransferID::CUSTOM, 107 ColorSpace::TransferID::CUSTOM,
110 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); 108 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL);
111 color_space.icc_profile_id_ = id_; 109 color_space.icc_profile_id_ = id_;
112 110
113 // Move this ICC profile to the most recently used end of the cache. 111 // Move this ICC profile to the most recently used end of the cache.
114 { 112 {
115 Cache& cache = g_cache.Get(); 113 Cache& cache = g_cache.Get();
116 base::AutoLock lock(cache.lock); 114 base::AutoLock lock(cache.lock);
117 115
118 auto found = cache.id_to_icc_profile_mru.Get(id_); 116 auto found = cache.id_to_icc_profile_mru.Get(id_);
119 if (found == cache.id_to_icc_profile_mru.end()) 117 if (found == cache.id_to_icc_profile_mru.end())
120 cache.id_to_icc_profile_mru.Put(id_, *this); 118 cache.id_to_icc_profile_mru.Put(id_, *this);
121 } 119 }
122
123 ColorSpace unity_colorspace(
124 ColorSpace::PrimaryID::CUSTOM, ColorSpace::TransferID::LINEAR,
125 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL);
126 unity_colorspace.custom_primary_matrix_[0] = 1.0f;
127 unity_colorspace.custom_primary_matrix_[1] = 0.0f;
128 unity_colorspace.custom_primary_matrix_[2] = 0.0f;
129 unity_colorspace.custom_primary_matrix_[3] = 0.0f;
130
131 unity_colorspace.custom_primary_matrix_[4] = 0.0f;
132 unity_colorspace.custom_primary_matrix_[5] = 1.0f;
133 unity_colorspace.custom_primary_matrix_[6] = 0.0f;
134 unity_colorspace.custom_primary_matrix_[7] = 0.0f;
135
136 unity_colorspace.custom_primary_matrix_[8] = 0.0f;
137 unity_colorspace.custom_primary_matrix_[9] = 0.0f;
138 unity_colorspace.custom_primary_matrix_[10] = 1.0f;
139 unity_colorspace.custom_primary_matrix_[11] = 0.0f;
140
141 // This will look up and use the ICC profile.
142 std::unique_ptr<ColorTransform> transform(ColorTransform::NewColorTransform(
143 color_space, unity_colorspace, ColorTransform::Intent::INTENT_ABSOLUTE));
144
145 ColorTransform::TriStim tmp[4];
146 tmp[0].set_x(1.0f);
147 tmp[1].set_y(1.0f);
148 tmp[2].set_z(1.0f);
149 transform->transform(tmp, arraysize(tmp));
150
151 color_space.custom_primary_matrix_[0] = tmp[0].x() - tmp[3].x();
152 color_space.custom_primary_matrix_[1] = tmp[1].x() - tmp[3].x();
153 color_space.custom_primary_matrix_[2] = tmp[2].x() - tmp[3].x();
154 color_space.custom_primary_matrix_[3] = tmp[3].x();
155
156 color_space.custom_primary_matrix_[4] = tmp[0].y() - tmp[3].y();
157 color_space.custom_primary_matrix_[5] = tmp[1].y() - tmp[3].y();
158 color_space.custom_primary_matrix_[6] = tmp[2].y() - tmp[3].y();
159 color_space.custom_primary_matrix_[7] = tmp[3].y();
160
161 color_space.custom_primary_matrix_[8] = tmp[0].z() - tmp[3].z();
162 color_space.custom_primary_matrix_[9] = tmp[1].z() - tmp[3].z();
163 color_space.custom_primary_matrix_[10] = tmp[2].z() - tmp[3].z();
164 color_space.custom_primary_matrix_[11] = tmp[3].z();
165
166 return color_space; 120 return color_space;
167 } 121 }
168 122
169 // static 123 // static
170 bool ICCProfile::IsValidProfileLength(size_t length) { 124 bool ICCProfile::IsValidProfileLength(size_t length) {
171 return length >= kMinProfileLength && length <= kMaxProfileLength; 125 return length >= kMinProfileLength && length <= kMaxProfileLength;
172 } 126 }
173 127
174 } // namespace gfx 128 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/icc_profile.h ('k') | ui/gfx/ipc/color/gfx_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698