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

Side by Side Diff: ui/gfx/color_utils.cc

Issue 1543183002: Switch to standard integer types in ui/gfx/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/color_utils.h ('k') | ui/gfx/display.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <math.h> 7 #include <math.h>
8 #if defined(OS_WIN) 8 #include <stdint.h>
9 #include <windows.h>
10 #endif
11 9
12 #include <algorithm> 10 #include <algorithm>
13 11
14 #include "base/basictypes.h"
15 #include "base/logging.h" 12 #include "base/logging.h"
16 #include "base/numerics/safe_conversions.h" 13 #include "base/numerics/safe_conversions.h"
17 #include "build/build_config.h" 14 #include "build/build_config.h"
18 #if defined(OS_WIN)
19 #include "skia/ext/skia_utils_win.h"
20 #endif
21 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/color_palette.h" 16 #include "ui/gfx/color_palette.h"
23 17
18 #if defined(OS_WIN)
19 #include <windows.h>
20 #include "skia/ext/skia_utils_win.h"
21 #endif
22
24 namespace color_utils { 23 namespace color_utils {
25 24
26 25
27 // Helper functions ----------------------------------------------------------- 26 // Helper functions -----------------------------------------------------------
28 27
29 namespace { 28 namespace {
30 29
31 int calcHue(double temp1, double temp2, double hue) { 30 int calcHue(double temp1, double temp2, double hue) {
32 if (hue < 0.0) 31 if (hue < 0.0)
33 ++hue; 32 ++hue;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 127 }
129 128
130 SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha) { 129 SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha) {
131 double hue = hsl.h; 130 double hue = hsl.h;
132 double saturation = hsl.s; 131 double saturation = hsl.s;
133 double lightness = hsl.l; 132 double lightness = hsl.l;
134 133
135 // If there's no color, we don't care about hue and can do everything based on 134 // If there's no color, we don't care about hue and can do everything based on
136 // brightness. 135 // brightness.
137 if (!saturation) { 136 if (!saturation) {
138 uint8 light; 137 uint8_t light;
139 138
140 if (lightness < 0) 139 if (lightness < 0)
141 light = 0; 140 light = 0;
142 else if (lightness >= 1.0) 141 else if (lightness >= 1.0)
143 light = 255; 142 light = 255;
144 else 143 else
145 light = static_cast<uint8>(SkDoubleToFixed(lightness) >> 8); 144 light = static_cast<uint8_t>(SkDoubleToFixed(lightness) >> 8);
146 145
147 return SkColorSetARGB(alpha, light, light, light); 146 return SkColorSetARGB(alpha, light, light, light);
148 } 147 }
149 148
150 double temp2 = (lightness < 0.5) ? 149 double temp2 = (lightness < 0.5) ?
151 (lightness * (1.0 + saturation)) : 150 (lightness * (1.0 + saturation)) :
152 (lightness + saturation - (lightness * saturation)); 151 (lightness + saturation - (lightness * saturation));
153 double temp1 = 2.0 * lightness - temp2; 152 double temp1 = 2.0 * lightness - temp2;
154 return SkColorSetARGB(alpha, 153 return SkColorSetARGB(alpha,
155 calcHue(temp1, temp2, hue + 1.0 / 3.0), 154 calcHue(temp1, temp2, hue + 1.0 / 3.0),
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (IsDark(text_color)) { 337 if (IsDark(text_color)) {
339 // For black text, this comes out to kChromeIconGrey. 338 // For black text, this comes out to kChromeIconGrey.
340 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, 339 return color_utils::AlphaBlend(SK_ColorWHITE, text_color,
341 SkColorGetR(gfx::kChromeIconGrey)); 340 SkColorGetR(gfx::kChromeIconGrey));
342 } 341 }
343 // The dimming is less dramatic when darkening a light color. 342 // The dimming is less dramatic when darkening a light color.
344 return color_utils::AlphaBlend(SK_ColorBLACK, text_color, 0x33); 343 return color_utils::AlphaBlend(SK_ColorBLACK, text_color, 0x33);
345 } 344 }
346 345
347 } // namespace color_utils 346 } // namespace color_utils
OLDNEW
« no previous file with comments | « ui/gfx/color_utils.h ('k') | ui/gfx/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698