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

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

Issue 289283004: Add ability to constrain dominant color selection to a HSL range. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix DCHECKS Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/color_utils.h ('k') | ui/gfx/color_utils_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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_utils.h" 5 #include "ui/gfx/color_utils.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 double temp2 = (lightness < 0.5) ? 144 double temp2 = (lightness < 0.5) ?
145 (lightness * (1.0 + saturation)) : 145 (lightness * (1.0 + saturation)) :
146 (lightness + saturation - (lightness * saturation)); 146 (lightness + saturation - (lightness * saturation));
147 double temp1 = 2.0 * lightness - temp2; 147 double temp1 = 2.0 * lightness - temp2;
148 return SkColorSetARGB(alpha, 148 return SkColorSetARGB(alpha,
149 calcHue(temp1, temp2, hue + 1.0 / 3.0), 149 calcHue(temp1, temp2, hue + 1.0 / 3.0),
150 calcHue(temp1, temp2, hue), 150 calcHue(temp1, temp2, hue),
151 calcHue(temp1, temp2, hue - 1.0 / 3.0)); 151 calcHue(temp1, temp2, hue - 1.0 / 3.0));
152 } 152 }
153 153
154 bool IsWithinHSLRange(const HSL& hsl,
155 const HSL& lower_bound,
156 const HSL& upper_bound) {
157 DCHECK(hsl.h >= 0 && hsl.h <= 1) << hsl.h;
158 DCHECK(hsl.s >= 0 && hsl.s <= 1) << hsl.s;
159 DCHECK(hsl.l >= 0 && hsl.l <= 1) << hsl.l;
160 DCHECK(lower_bound.h < 0 || upper_bound.h < 0 ||
161 (lower_bound.h <= 1 && upper_bound.h <= lower_bound.h + 1))
162 << "lower_bound.h:" << lower_bound.h
Matt Giuca 2014/06/02 04:12:23 nit: Can you put spaces after the ':' and commas a
calamity 2014/06/03 02:49:50 Done.
163 << " upper_bound.h:" << upper_bound.h;
164 DCHECK(lower_bound.s < 0 || upper_bound.s < 0 ||
165 (lower_bound.s <= upper_bound.s && upper_bound.s <= 1))
166 << "lower_bound.s:" << lower_bound.s
167 << " upper_bound.s:" << upper_bound.s;
168 DCHECK(lower_bound.l < 0 || upper_bound.l < 0 ||
169 (lower_bound.l <= upper_bound.l && upper_bound.l <= 1))
170 << "lower_bound.l:" << lower_bound.l
171 << " upper_bound.l:" << upper_bound.l;
172
173 // If the upper hue is >1, the given hue bounds wrap around at 1.
174 bool matches_hue = upper_bound.h > 1
175 ? hsl.h >= lower_bound.h || hsl.h <= upper_bound.h - 1
176 : hsl.h >= lower_bound.h && hsl.h <= upper_bound.h;
177 return (upper_bound.h < 0 || lower_bound.h < 0 || matches_hue) &&
178 (upper_bound.s < 0 || lower_bound.s < 0 ||
179 (hsl.s >= lower_bound.s && hsl.s <= upper_bound.s)) &&
180 (upper_bound.l < 0 || lower_bound.l < 0 ||
181 (hsl.l >= lower_bound.l && hsl.l <= upper_bound.l));
182 }
183
154 SkColor HSLShift(SkColor color, const HSL& shift) { 184 SkColor HSLShift(SkColor color, const HSL& shift) {
155 HSL hsl; 185 HSL hsl;
156 int alpha = SkColorGetA(color); 186 int alpha = SkColorGetA(color);
157 SkColorToHSL(color, &hsl); 187 SkColorToHSL(color, &hsl);
158 188
159 // Replace the hue with the tint's hue. 189 // Replace the hue with the tint's hue.
160 if (shift.h >= 0) 190 if (shift.h >= 0)
161 hsl.h = shift.h; 191 hsl.h = shift.h;
162 192
163 // Change the saturation. 193 // Change the saturation.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 SkColor GetSysSkColor(int which) { 292 SkColor GetSysSkColor(int which) {
263 #if defined(OS_WIN) 293 #if defined(OS_WIN)
264 return skia::COLORREFToSkColor(GetSysColor(which)); 294 return skia::COLORREFToSkColor(GetSysColor(which));
265 #else 295 #else
266 NOTIMPLEMENTED(); 296 NOTIMPLEMENTED();
267 return SK_ColorLTGRAY; 297 return SK_ColorLTGRAY;
268 #endif 298 #endif
269 } 299 }
270 300
271 } // namespace color_utils 301 } // namespace color_utils
OLDNEW
« no previous file with comments | « ui/gfx/color_utils.h ('k') | ui/gfx/color_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698