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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 // If there's no color, we don't care about hue and can do everything based on | 134 // If there's no color, we don't care about hue and can do everything based on |
| 135 // brightness. | 135 // brightness. |
| 136 if (!saturation) { | 136 if (!saturation) { |
| 137 uint8_t light; | 137 uint8_t light; |
| 138 | 138 |
| 139 if (lightness < 0) | 139 if (lightness < 0) |
| 140 light = 0; | 140 light = 0; |
| 141 else if (lightness >= 1.0) | 141 else if (lightness >= 1.0) |
| 142 light = 255; | 142 light = 255; |
| 143 else | 143 else |
| 144 light = static_cast<uint8_t>(SkDoubleToFixed(lightness) >> 8); | 144 // Scale from 0 - 255 and round off the value. |
| 145 light = static_cast<uint8_t>(lightness * 255 + .5); | |
|
Peter Kasting
2016/02/18 23:54:03
Seems like we could replace this entire conditiona
dogben
2016/02/22 17:30:30
SGTM, thanks!
| |
| 145 | 146 |
| 146 return SkColorSetARGB(alpha, light, light, light); | 147 return SkColorSetARGB(alpha, light, light, light); |
| 147 } | 148 } |
| 148 | 149 |
| 149 double temp2 = (lightness < 0.5) ? | 150 double temp2 = (lightness < 0.5) ? |
| 150 (lightness * (1.0 + saturation)) : | 151 (lightness * (1.0 + saturation)) : |
| 151 (lightness + saturation - (lightness * saturation)); | 152 (lightness + saturation - (lightness * saturation)); |
| 152 double temp1 = 2.0 * lightness - temp2; | 153 double temp1 = 2.0 * lightness - temp2; |
| 153 return SkColorSetARGB(alpha, calcHue(temp1, temp2, hue + 1.0 / 3.0), | 154 return SkColorSetARGB(alpha, calcHue(temp1, temp2, hue + 1.0 / 3.0), |
| 154 calcHue(temp1, temp2, hue), | 155 calcHue(temp1, temp2, hue), |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 if (IsDark(text_color)) { | 337 if (IsDark(text_color)) { |
| 337 // For black text, this comes out to kChromeIconGrey. | 338 // For black text, this comes out to kChromeIconGrey. |
| 338 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, | 339 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, |
| 339 SkColorGetR(gfx::kChromeIconGrey)); | 340 SkColorGetR(gfx::kChromeIconGrey)); |
| 340 } | 341 } |
| 341 // The dimming is less dramatic when darkening a light color. | 342 // The dimming is less dramatic when darkening a light color. |
| 342 return color_utils::AlphaBlend(SK_ColorBLACK, text_color, 0x33); | 343 return color_utils::AlphaBlend(SK_ColorBLACK, text_color, 0x33); |
| 343 } | 344 } |
| 344 | 345 |
| 345 } // namespace color_utils | 346 } // namespace color_utils |
| OLD | NEW |