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

Unified Diff: ui/gfx/color_utils.cc

Issue 1698083004: Use a more correct conversion to uint8_t. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply pkasting's suggestion. Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/color_utils.cc
diff --git a/ui/gfx/color_utils.cc b/ui/gfx/color_utils.cc
index 978283d29ab7a326781548940c448c104a57201b..2e3c96f86dc674824e2e8d998be1aae58831e951 100644
--- a/ui/gfx/color_utils.cc
+++ b/ui/gfx/color_utils.cc
@@ -14,6 +14,7 @@
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/color_palette.h"
+#include "ui/gfx/geometry/safe_integer_conversions.h"
#if defined(OS_WIN)
#include <windows.h>
@@ -134,15 +135,8 @@ SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha) {
// If there's no color, we don't care about hue and can do everything based on
// brightness.
if (!saturation) {
- uint8_t light;
-
- if (lightness < 0)
- light = 0;
- else if (lightness >= 1.0)
- light = 255;
- else
- light = static_cast<uint8_t>(SkDoubleToFixed(lightness) >> 8);
-
+ const uint8_t light =
+ base::saturated_cast<uint8_t>(gfx::ToRoundedInt(lightness * 255));
return SkColorSetARGB(alpha, light, light, light);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698