| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 SkColorGetG(background) * b_weight) / 255.0; | 277 SkColorGetG(background) * b_weight) / 255.0; |
| 278 double b = (SkColorGetB(foreground) * f_weight + | 278 double b = (SkColorGetB(foreground) * f_weight + |
| 279 SkColorGetB(background) * b_weight) / 255.0; | 279 SkColorGetB(background) * b_weight) / 255.0; |
| 280 | 280 |
| 281 return SkColorSetARGB(static_cast<int>(std::round(normalizer)), | 281 return SkColorSetARGB(static_cast<int>(std::round(normalizer)), |
| 282 static_cast<int>(std::round(r)), | 282 static_cast<int>(std::round(r)), |
| 283 static_cast<int>(std::round(g)), | 283 static_cast<int>(std::round(g)), |
| 284 static_cast<int>(std::round(b))); | 284 static_cast<int>(std::round(b))); |
| 285 } | 285 } |
| 286 | 286 |
| 287 SkColor ImplicitAlphaBlend(SkColor foreground, SkColor background) { |
| 288 return AlphaBlend(SkColorSetA(foreground, SK_AlphaOPAQUE), background, |
| 289 SkColorGetA(foreground)); |
| 290 } |
| 291 |
| 287 bool IsDark(SkColor color) { | 292 bool IsDark(SkColor color) { |
| 288 return GetLuma(color) < 128; | 293 return GetLuma(color) < 128; |
| 289 } | 294 } |
| 290 | 295 |
| 291 SkColor BlendTowardOppositeLuma(SkColor color, SkAlpha alpha) { | 296 SkColor BlendTowardOppositeLuma(SkColor color, SkAlpha alpha) { |
| 292 return AlphaBlend(IsDark(color) ? SK_ColorWHITE : SK_ColorBLACK, color, | 297 return AlphaBlend(IsDark(color) ? SK_ColorWHITE : SK_ColorBLACK, color, |
| 293 alpha); | 298 alpha); |
| 294 } | 299 } |
| 295 | 300 |
| 296 SkColor GetReadableColor(SkColor foreground, SkColor background) { | 301 SkColor GetReadableColor(SkColor foreground, SkColor background) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // For black text, this comes out to kChromeIconGrey. | 341 // For black text, this comes out to kChromeIconGrey. |
| 337 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, | 342 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, |
| 338 SkColorGetR(gfx::kChromeIconGrey)); | 343 SkColorGetR(gfx::kChromeIconGrey)); |
| 339 } | 344 } |
| 340 // For a light color, just reduce opacity. | 345 // For a light color, just reduce opacity. |
| 341 return SkColorSetA(text_color, | 346 return SkColorSetA(text_color, |
| 342 static_cast<int>(0.8f * SkColorGetA(text_color))); | 347 static_cast<int>(0.8f * SkColorGetA(text_color))); |
| 343 } | 348 } |
| 344 | 349 |
| 345 } // namespace color_utils | 350 } // namespace color_utils |
| OLD | NEW |