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> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/strings/string_number_conversions.h" | |
| 15 #include "base/strings/stringprintf.h" | |
| 14 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "ui/gfx/color_palette.h" | 18 #include "ui/gfx/color_palette.h" |
| 17 #include "ui/gfx/geometry/safe_integer_conversions.h" | 19 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 18 | 20 |
| 19 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 20 #include <windows.h> | 22 #include <windows.h> |
| 21 #include "skia/ext/skia_utils_win.h" | 23 #include "skia/ext/skia_utils_win.h" |
| 22 #endif | 24 #endif |
| 23 | 25 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 if (IsDark(text_color)) { | 342 if (IsDark(text_color)) { |
| 341 // For black text, this comes out to kChromeIconGrey. | 343 // For black text, this comes out to kChromeIconGrey. |
| 342 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, | 344 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, |
| 343 SkColorGetR(gfx::kChromeIconGrey)); | 345 SkColorGetR(gfx::kChromeIconGrey)); |
| 344 } | 346 } |
| 345 // For a light color, just reduce opacity. | 347 // For a light color, just reduce opacity. |
| 346 return SkColorSetA(text_color, | 348 return SkColorSetA(text_color, |
| 347 static_cast<int>(0.8f * SkColorGetA(text_color))); | 349 static_cast<int>(0.8f * SkColorGetA(text_color))); |
| 348 } | 350 } |
| 349 | 351 |
| 352 std::string SkColorToRGBAString(SkColor color) { | |
| 353 // We convert the alpha using DoubleToString because StringPrintf will use | |
| 354 // locale specific formatters (e.g., use , instead of . in German). | |
| 355 return base::StringPrintf( | |
| 356 "rgba(%d,%d,%d,%s)", SkColorGetR(color), SkColorGetG(color), | |
|
msw
2017/02/28 22:43:15
optional nit: maybe it makes sense to compose SkCo
gonzalon
2017/03/02 15:43:08
Done.
| |
| 357 SkColorGetB(color), | |
| 358 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); | |
| 359 } | |
| 360 | |
| 361 std::string SkColorToRGBComponents(SkColor color) { | |
|
msw
2017/02/28 22:43:15
You'll need to update this (cq dry run or local co
gonzalon
2017/03/02 15:43:08
Done.
| |
| 362 return base::StringPrintf("%d,%d,%d", SkColorGetR(color), SkColorGetG(color), | |
| 363 SkColorGetB(color)); | |
| 364 } | |
| 365 | |
| 350 } // namespace color_utils | 366 } // namespace color_utils |
| OLD | NEW |