| 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(%s,%s)", SkColorToRgbString(color).c_str(), |
| 357 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); |
| 358 } |
| 359 |
| 360 std::string SkColorToRgbString(SkColor color) { |
| 361 return base::StringPrintf("%d,%d,%d", SkColorGetR(color), SkColorGetG(color), |
| 362 SkColorGetB(color)); |
| 363 } |
| 364 |
| 350 } // namespace color_utils | 365 } // namespace color_utils |
| OLD | NEW |