Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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); | |
|
Matt Giuca
2014/05/22 05:03:52
Your comment says this is inclusive, inclusive. Wh
Matt Giuca
2014/05/22 05:03:52
Should also DCHECK the hsl.s and hsl.l, as well as
calamity
2014/05/22 07:36:36
The comment says the bounds are inclusive, inclusi
calamity
2014/05/22 07:36:36
Values can be negative to specify ignore.
| |
| 158 | |
| 159 // If the upper hue is >1, the given hue bounds wrap around at 1. | |
| 160 bool matches_hue = upper_bound.h > 1 | |
| 161 ? hsl.h >= lower_bound.h || hsl.h <= upper_bound.h - 1 | |
| 162 : hsl.h >= lower_bound.h && hsl.h <= upper_bound.h; | |
| 163 return (upper_bound.h < 0 || lower_bound.h < 0 || matches_hue) && | |
| 164 (upper_bound.s < 0 || lower_bound.s < 0 || | |
| 165 (hsl.s >= lower_bound.s && hsl.s <= upper_bound.s)) && | |
| 166 (upper_bound.l < 0 || lower_bound.l < 0 || | |
| 167 (hsl.l >= lower_bound.l && hsl.l <= upper_bound.l)); | |
| 168 } | |
| 169 | |
| 154 SkColor HSLShift(SkColor color, const HSL& shift) { | 170 SkColor HSLShift(SkColor color, const HSL& shift) { |
| 155 HSL hsl; | 171 HSL hsl; |
| 156 int alpha = SkColorGetA(color); | 172 int alpha = SkColorGetA(color); |
| 157 SkColorToHSL(color, &hsl); | 173 SkColorToHSL(color, &hsl); |
| 158 | 174 |
| 159 // Replace the hue with the tint's hue. | 175 // Replace the hue with the tint's hue. |
| 160 if (shift.h >= 0) | 176 if (shift.h >= 0) |
| 161 hsl.h = shift.h; | 177 hsl.h = shift.h; |
| 162 | 178 |
| 163 // Change the saturation. | 179 // Change the saturation. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 SkColor GetSysSkColor(int which) { | 278 SkColor GetSysSkColor(int which) { |
| 263 #if defined(OS_WIN) | 279 #if defined(OS_WIN) |
| 264 return skia::COLORREFToSkColor(GetSysColor(which)); | 280 return skia::COLORREFToSkColor(GetSysColor(which)); |
| 265 #else | 281 #else |
| 266 NOTIMPLEMENTED(); | 282 NOTIMPLEMENTED(); |
| 267 return SK_ColorLTGRAY; | 283 return SK_ColorLTGRAY; |
| 268 #endif | 284 #endif |
| 269 } | 285 } |
| 270 | 286 |
| 271 } // namespace color_utils | 287 } // namespace color_utils |
| OLD | NEW |