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

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

Issue 23498059: Remove last dependencies on ui/base from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: last rebase Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/color_profile.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 #ifndef UI_GFX_COLOR_UTILS_H_ 5 #ifndef UI_GFX_COLOR_UTILS_H_
6 #define UI_GFX_COLOR_UTILS_H_ 6 #define UI_GFX_COLOR_UTILS_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "third_party/skia/include/core/SkColor.h" 9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/gfx/gfx_export.h" 10 #include "ui/gfx/gfx_export.h"
11 11
12 class SkBitmap; 12 class SkBitmap;
13 13
14 namespace color_utils { 14 namespace color_utils {
15 15
16 // Represents an HSL color. 16 // Represents an HSL color.
17 struct HSL { 17 struct HSL {
18 double h; 18 double h;
19 double s; 19 double s;
20 double l; 20 double l;
21 }; 21 };
22 22
23 UI_EXPORT unsigned char GetLuminanceForColor(SkColor color); 23 GFX_EXPORT unsigned char GetLuminanceForColor(SkColor color);
24 24
25 // Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef 25 // Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef
26 UI_EXPORT double RelativeLuminance(SkColor color); 26 GFX_EXPORT double RelativeLuminance(SkColor color);
27 27
28 // Note: these transformations assume sRGB as the source color space 28 // Note: these transformations assume sRGB as the source color space
29 UI_EXPORT void SkColorToHSL(SkColor c, HSL* hsl); 29 GFX_EXPORT void SkColorToHSL(SkColor c, HSL* hsl);
30 UI_EXPORT SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha); 30 GFX_EXPORT SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha);
31 31
32 // HSL-Shift an SkColor. The shift values are in the range of 0-1, with the 32 // HSL-Shift an SkColor. The shift values are in the range of 0-1, with the
33 // option to specify -1 for 'no change'. The shift values are defined as: 33 // option to specify -1 for 'no change'. The shift values are defined as:
34 // hsl_shift[0] (hue): The absolute hue value - 0 and 1 map 34 // hsl_shift[0] (hue): The absolute hue value - 0 and 1 map
35 // to 0 and 360 on the hue color wheel (red). 35 // to 0 and 360 on the hue color wheel (red).
36 // hsl_shift[1] (saturation): A saturation shift, with the 36 // hsl_shift[1] (saturation): A saturation shift, with the
37 // following key values: 37 // following key values:
38 // 0 = remove all color. 38 // 0 = remove all color.
39 // 0.5 = leave unchanged. 39 // 0.5 = leave unchanged.
40 // 1 = fully saturate the image. 40 // 1 = fully saturate the image.
41 // hsl_shift[2] (lightness): A lightness shift, with the 41 // hsl_shift[2] (lightness): A lightness shift, with the
42 // following key values: 42 // following key values:
43 // 0 = remove all lightness (make all pixels black). 43 // 0 = remove all lightness (make all pixels black).
44 // 0.5 = leave unchanged. 44 // 0.5 = leave unchanged.
45 // 1 = full lightness (make all pixels white). 45 // 1 = full lightness (make all pixels white).
46 UI_EXPORT SkColor HSLShift(SkColor color, const HSL& shift); 46 GFX_EXPORT SkColor HSLShift(SkColor color, const HSL& shift);
47 47
48 // Determine if a given alpha value is nearly completely transparent. 48 // Determine if a given alpha value is nearly completely transparent.
49 bool IsColorCloseToTransparent(SkAlpha alpha); 49 bool IsColorCloseToTransparent(SkAlpha alpha);
50 50
51 // Determine if a color is near grey. 51 // Determine if a color is near grey.
52 bool IsColorCloseToGrey(int r, int g, int b); 52 bool IsColorCloseToGrey(int r, int g, int b);
53 53
54 // Builds a histogram based on the Y' of the Y'UV representation of 54 // Builds a histogram based on the Y' of the Y'UV representation of
55 // this image. 55 // this image.
56 UI_EXPORT void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]); 56 GFX_EXPORT void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]);
57 57
58 // Returns a blend of the supplied colors, ranging from |background| (for 58 // Returns a blend of the supplied colors, ranging from |background| (for
59 // |alpha| == 0) to |foreground| (for |alpha| == 255). The alpha channels of 59 // |alpha| == 0) to |foreground| (for |alpha| == 255). The alpha channels of
60 // the supplied colors are also taken into account, so the returned color may 60 // the supplied colors are also taken into account, so the returned color may
61 // be partially transparent. 61 // be partially transparent.
62 UI_EXPORT SkColor AlphaBlend(SkColor foreground, SkColor background, 62 GFX_EXPORT SkColor AlphaBlend(SkColor foreground, SkColor background,
63 SkAlpha alpha); 63 SkAlpha alpha);
64 64
65 // Makes a dark color lighter or a light color darker by blending |color| with 65 // Makes a dark color lighter or a light color darker by blending |color| with
66 // white or black depending on its current luminance. |alpha| controls the 66 // white or black depending on its current luminance. |alpha| controls the
67 // amount of white or black that will be alpha-blended into |color|. 67 // amount of white or black that will be alpha-blended into |color|.
68 UI_EXPORT SkColor BlendTowardOppositeLuminance(SkColor color, SkAlpha alpha); 68 GFX_EXPORT SkColor BlendTowardOppositeLuminance(SkColor color, SkAlpha alpha);
69 69
70 // Given an opaque foreground and background color, try to return a foreground 70 // Given an opaque foreground and background color, try to return a foreground
71 // color that is "readable" over the background color by luma-inverting the 71 // color that is "readable" over the background color by luma-inverting the
72 // foreground color and then picking whichever foreground color has higher 72 // foreground color and then picking whichever foreground color has higher
73 // contrast against the background color. You should not pass colors with 73 // contrast against the background color. You should not pass colors with
74 // non-255 alpha to this routine, since determining the correct behavior in such 74 // non-255 alpha to this routine, since determining the correct behavior in such
75 // cases can be impossible. 75 // cases can be impossible.
76 // 76 //
77 // NOTE: This won't do anything but waste time if the supplied foreground color 77 // NOTE: This won't do anything but waste time if the supplied foreground color
78 // has a luma value close to the midpoint (0.5 in the HSL representation). 78 // has a luma value close to the midpoint (0.5 in the HSL representation).
79 UI_EXPORT SkColor GetReadableColor(SkColor foreground, SkColor background); 79 GFX_EXPORT SkColor GetReadableColor(SkColor foreground, SkColor background);
80 80
81 // Invert a color. 81 // Invert a color.
82 UI_EXPORT SkColor InvertColor(SkColor color); 82 GFX_EXPORT SkColor InvertColor(SkColor color);
83 83
84 // Gets a Windows system color as a SkColor 84 // Gets a Windows system color as a SkColor
85 UI_EXPORT SkColor GetSysSkColor(int which); 85 GFX_EXPORT SkColor GetSysSkColor(int which);
86 86
87 } // namespace color_utils 87 } // namespace color_utils
88 88
89 #endif // UI_GFX_COLOR_UTILS_H_ 89 #endif // UI_GFX_COLOR_UTILS_H_
OLDNEW
« no previous file with comments | « ui/gfx/color_profile.h ('k') | ui/gfx/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698