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

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

Issue 7328011: Introduce ui.dll / libui.so for the component build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include "third_party/skia/include/core/SkColor.h" 9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/ui_api.h"
10 11
11 class SkBitmap; 12 class SkBitmap;
12 13
13 namespace color_utils { 14 namespace color_utils {
14 15
15 // Represents an HSL color. 16 // Represents an HSL color.
16 struct HSL { 17 struct HSL {
17 double h; 18 double h;
18 double s; 19 double s;
19 double l; 20 double l;
20 }; 21 };
21 22
22 unsigned char GetLuminanceForColor(SkColor color); 23 unsigned char GetLuminanceForColor(SkColor color);
23 24
24 // Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef 25 // Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef
25 double RelativeLuminance(SkColor color); 26 UI_API double RelativeLuminance(SkColor color);
26 27
27 // Note: these transformations assume sRGB as the source color space 28 // Note: these transformations assume sRGB as the source color space
28 void SkColorToHSL(SkColor c, HSL* hsl); 29 UI_API void SkColorToHSL(SkColor c, HSL* hsl);
29 SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha); 30 UI_API SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha);
30 31
31 // 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
32 // 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:
33 // 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
34 // to 0 and 360 on the hue color wheel (red). 35 // to 0 and 360 on the hue color wheel (red).
35 // hsl_shift[1] (saturation): A saturation shift, with the 36 // hsl_shift[1] (saturation): A saturation shift, with the
36 // following key values: 37 // following key values:
37 // 0 = remove all color. 38 // 0 = remove all color.
38 // 0.5 = leave unchanged. 39 // 0.5 = leave unchanged.
39 // 1 = fully saturate the image. 40 // 1 = fully saturate the image.
40 // hsl_shift[2] (lightness): A lightness shift, with the 41 // hsl_shift[2] (lightness): A lightness shift, with the
41 // following key values: 42 // following key values:
42 // 0 = remove all lightness (make all pixels black). 43 // 0 = remove all lightness (make all pixels black).
43 // 0.5 = leave unchanged. 44 // 0.5 = leave unchanged.
44 // 1 = full lightness (make all pixels white). 45 // 1 = full lightness (make all pixels white).
45 SkColor HSLShift(SkColor color, const HSL& shift); 46 UI_API SkColor HSLShift(SkColor color, const HSL& shift);
46 47
47 // Determine if a given alpha value is nearly completely transparent. 48 // Determine if a given alpha value is nearly completely transparent.
48 bool IsColorCloseToTransparent(SkAlpha alpha); 49 bool IsColorCloseToTransparent(SkAlpha alpha);
49 50
50 // Determine if a color is near grey. 51 // Determine if a color is near grey.
51 bool IsColorCloseToGrey(int r, int g, int b); 52 bool IsColorCloseToGrey(int r, int g, int b);
52 53
53 // Gets a color representing a bitmap. The definition of "representing" is the 54 // Gets a color representing a bitmap. The definition of "representing" is the
54 // average color in the bitmap. The color returned is modified to have the 55 // average color in the bitmap. The color returned is modified to have the
55 // specified alpha. 56 // specified alpha.
56 SkColor GetAverageColorOfFavicon(SkBitmap* bitmap, SkAlpha alpha); 57 SkColor GetAverageColorOfFavicon(SkBitmap* bitmap, SkAlpha alpha);
57 58
58 // Builds a histogram based on the Y' of the Y'UV representation of 59 // Builds a histogram based on the Y' of the Y'UV representation of
59 // this image. 60 // this image.
60 void BuildLumaHistogram(SkBitmap* bitmap, int histogram[256]); 61 UI_API void BuildLumaHistogram(SkBitmap* bitmap, int histogram[256]);
61 62
62 // Returns a blend of the supplied colors, ranging from |background| (for 63 // Returns a blend of the supplied colors, ranging from |background| (for
63 // |alpha| == 0) to |foreground| (for |alpha| == 255). The alpha channels of 64 // |alpha| == 0) to |foreground| (for |alpha| == 255). The alpha channels of
64 // the supplied colors are also taken into account, so the returned color may 65 // the supplied colors are also taken into account, so the returned color may
65 // be partially transparent. 66 // be partially transparent.
66 SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha); 67 UI_API SkColor AlphaBlend(SkColor foreground, SkColor background,
68 SkAlpha alpha);
67 69
68 // Given a foreground and background color, try to return a foreground color 70 // Given a foreground and background color, try to return a foreground color
69 // that is "readable" over the background color by luma-inverting the foreground 71 // that is "readable" over the background color by luma-inverting the foreground
70 // color and then picking whichever foreground color has higher contrast against 72 // color and then picking whichever foreground color has higher contrast against
71 // the background color. 73 // the background color.
72 // 74 //
73 // NOTE: This won't do anything but waste time if the supplied foreground color 75 // NOTE: This won't do anything but waste time if the supplied foreground color
74 // has a luma value close to the midpoint (0.5 in the HSL representation). 76 // has a luma value close to the midpoint (0.5 in the HSL representation).
75 SkColor GetReadableColor(SkColor foreground, SkColor background); 77 UI_API SkColor GetReadableColor(SkColor foreground, SkColor background);
76 78
77 // Gets a Windows system color as a SkColor 79 // Gets a Windows system color as a SkColor
78 SkColor GetSysSkColor(int which); 80 UI_API SkColor GetSysSkColor(int which);
79 81
80 } // namespace color_utils 82 } // namespace color_utils
81 83
82 #endif // UI_GFX_COLOR_UTILS_H_ 84 #endif // UI_GFX_COLOR_UTILS_H_
OLDNEW
« no previous file with comments | « ui/gfx/color_analysis.h ('k') | ui/gfx/compositor/compositor.gyp » ('j') | ui/ui.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698