Adds the ability for BubbleGtk widgets to specify both input and popup attributes.
[chromium-blink-merge.git] / ui / gfx / color_utils.h
blob0627d34a8ee19779232292cc99942b19f290ee44
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
3 // found in the LICENSE file.
5 #ifndef UI_GFX_COLOR_UTILS_H_
6 #define UI_GFX_COLOR_UTILS_H_
7 #pragma once
9 #include "base/basictypes.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/base/ui_export.h"
13 class SkBitmap;
15 namespace color_utils {
17 // Represents an HSL color.
18 struct HSL {
19 double h;
20 double s;
21 double l;
24 UI_EXPORT unsigned char GetLuminanceForColor(SkColor color);
26 // Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef
27 UI_EXPORT double RelativeLuminance(SkColor color);
29 // Note: these transformations assume sRGB as the source color space
30 UI_EXPORT void SkColorToHSL(SkColor c, HSL* hsl);
31 UI_EXPORT SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha);
33 // HSL-Shift an SkColor. The shift values are in the range of 0-1, with the
34 // option to specify -1 for 'no change'. The shift values are defined as:
35 // hsl_shift[0] (hue): The absolute hue value - 0 and 1 map
36 // to 0 and 360 on the hue color wheel (red).
37 // hsl_shift[1] (saturation): A saturation shift, with the
38 // following key values:
39 // 0 = remove all color.
40 // 0.5 = leave unchanged.
41 // 1 = fully saturate the image.
42 // hsl_shift[2] (lightness): A lightness shift, with the
43 // following key values:
44 // 0 = remove all lightness (make all pixels black).
45 // 0.5 = leave unchanged.
46 // 1 = full lightness (make all pixels white).
47 UI_EXPORT SkColor HSLShift(SkColor color, const HSL& shift);
49 // Determine if a given alpha value is nearly completely transparent.
50 bool IsColorCloseToTransparent(SkAlpha alpha);
52 // Determine if a color is near grey.
53 bool IsColorCloseToGrey(int r, int g, int b);
55 // Gets a color representing a bitmap. The definition of "representing" is the
56 // average color in the bitmap. The color returned is modified to have the
57 // specified alpha.
58 SkColor GetAverageColorOfFavicon(SkBitmap* bitmap, SkAlpha alpha);
60 // Builds a histogram based on the Y' of the Y'UV representation of
61 // this image.
62 UI_EXPORT void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]);
64 // Returns a blend of the supplied colors, ranging from |background| (for
65 // |alpha| == 0) to |foreground| (for |alpha| == 255). The alpha channels of
66 // the supplied colors are also taken into account, so the returned color may
67 // be partially transparent.
68 UI_EXPORT SkColor AlphaBlend(SkColor foreground, SkColor background,
69 SkAlpha alpha);
71 // Given a foreground and background color, try to return a foreground color
72 // that is "readable" over the background color by luma-inverting the foreground
73 // color and then picking whichever foreground color has higher contrast against
74 // the background color.
76 // NOTE: This won't do anything but waste time if the supplied foreground color
77 // has a luma value close to the midpoint (0.5 in the HSL representation).
78 UI_EXPORT SkColor GetReadableColor(SkColor foreground, SkColor background);
80 // Invert a color.
81 UI_EXPORT SkColor InvertColor(SkColor color);
83 // Gets a Windows system color as a SkColor
84 UI_EXPORT SkColor GetSysSkColor(int which);
86 } // namespace color_utils
88 #endif // UI_GFX_COLOR_UTILS_H_