Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: ui/gfx/color_utils.cc

Issue 649203003: Type conversion fixes, ui/gfx/ edition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/color_utils.cc
diff --git a/ui/gfx/color_utils.cc b/ui/gfx/color_utils.cc
index 37cfe302d5a3c8b72df24b052acbaa1c50d78e44..f0642810c72343a7e80526eac2db9c1c32712d44 100644
--- a/ui/gfx/color_utils.cc
+++ b/ui/gfx/color_utils.cc
@@ -13,6 +13,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include "skia/ext/skia_utils_win.h"
@@ -77,10 +78,10 @@ double ContrastRatio(double foreground_luminance, double background_luminance) {
// ----------------------------------------------------------------------------
unsigned char GetLuminanceForColor(SkColor color) {
- int luma = static_cast<int>((0.3 * SkColorGetR(color)) +
- (0.59 * SkColorGetG(color)) +
- (0.11 * SkColorGetB(color)));
- return std::max(std::min(luma, 255), 0);
+ return base::saturated_cast<unsigned char>(
+ (0.3 * SkColorGetR(color)) +
+ (0.59 * SkColorGetG(color)) +
+ (0.11 * SkColorGetB(color)));
}
double RelativeLuminance(SkColor color) {
@@ -136,7 +137,7 @@ SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha) {
else if (lightness >= 1.0)
light = 255;
else
- light = SkDoubleToFixed(lightness) >> 8;
+ light = static_cast<uint8>(SkDoubleToFixed(lightness) >> 8);
return SkColorSetARGB(alpha, light, light, light);
}
@@ -198,7 +199,7 @@ bool IsWithinHSLRange(const HSL& hsl,
SkColor HSLShift(SkColor color, const HSL& shift) {
HSL hsl;
- int alpha = SkColorGetA(color);
+ SkAlpha alpha = SkColorGetA(color);
SkColorToHSL(color, &hsl);
// Replace the hue with the tint's hue.

Powered by Google App Engine
This is Rietveld 408576698