summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/ui/views/app_window_frame_view.cc6
-rw-r--r--ash/frame/default_header_painter.cc7
-rw-r--r--chrome/browser/extensions/bookmark_app_helper.cc8
-rw-r--r--chrome/browser/themes/theme_service.cc2
-rw-r--r--chrome/browser/ui/libgtk2ui/gtk2_ui.cc2
-rw-r--r--chrome/browser/ui/sync/profile_signin_confirmation_helper.cc2
-rw-r--r--chrome/browser/ui/views/download/download_item_view.cc49
-rw-r--r--components/favicon_base/fallback_icon_style.cc28
-rw-r--r--mash/wm/frame/default_header_painter.cc5
-rw-r--r--ui/gfx/color_utils.cc77
-rw-r--r--ui/gfx/color_utils.h50
-rw-r--r--ui/gfx/sys_color_change_listener.cc10
12 files changed, 124 insertions, 122 deletions
diff --git a/apps/ui/views/app_window_frame_view.cc b/apps/ui/views/app_window_frame_view.cc
index 4b6246b..728e038 100644
--- a/apps/ui/views/app_window_frame_view.cc
+++ b/apps/ui/views/app_window_frame_view.cc
@@ -374,10 +374,8 @@ void AppWindowFrameView::SetButtonImagesForFrame() {
// If the frame is dark, we should use the light images so they have
// some contrast.
- unsigned char frame_luma =
- color_utils::GetLuminanceForColor(CurrentFrameColor());
- const unsigned char kLuminanceThreshold = 100;
- bool use_light = frame_luma < kLuminanceThreshold;
+ const uint8_t kLumaThreshold = 100;
+ bool use_light = color_utils::GetLuma(CurrentFrameColor()) < kLumaThreshold;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (use_light) {
diff --git a/ash/frame/default_header_painter.cc b/ash/frame/default_header_painter.cc
index 432764b..18086ac 100644
--- a/ash/frame/default_header_painter.cc
+++ b/ash/frame/default_header_painter.cc
@@ -42,8 +42,6 @@ const SkColor kHeaderContentSeparatorInactiveColor =
const SkColor kDefaultFrameColor = SkColorSetRGB(242, 242, 242);
// Duration of crossfade animation for activating and deactivating frame.
const int kActivationCrossfadeDurationMs = 200;
-// Luminance below which to use white caption buttons.
-const int kMaxLuminanceForLightButtons = 125;
// Tiles an image into an area, rounding the top corners.
void TileRoundRect(gfx::Canvas* canvas,
@@ -279,9 +277,8 @@ void DefaultHeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas) {
}
bool DefaultHeaderPainter::ShouldUseLightImages() {
- int luminance = color_utils::GetLuminanceForColor(
- mode_ == MODE_INACTIVE ? inactive_frame_color_ : active_frame_color_);
- return luminance < kMaxLuminanceForLightButtons;
+ return color_utils::IsDark(mode_ == MODE_INACTIVE ? inactive_frame_color_
+ : active_frame_color_);
}
void DefaultHeaderPainter::UpdateAllButtonImages() {
diff --git a/chrome/browser/extensions/bookmark_app_helper.cc b/chrome/browser/extensions/bookmark_app_helper.cc
index ccae49f..0c9f822 100644
--- a/chrome/browser/extensions/bookmark_app_helper.cc
+++ b/chrome/browser/extensions/bookmark_app_helper.cc
@@ -93,7 +93,7 @@ class GeneratedIconImageSource : public gfx::CanvasImageSource {
private:
// gfx::CanvasImageSource overrides:
void Draw(gfx::Canvas* canvas) override {
- const unsigned char kLuminanceThreshold = 190;
+ const uint8_t kLumaThreshold = 190;
const int icon_size = output_size_ * 3 / 4;
const int icon_inset = output_size_ / 8;
const size_t border_radius = output_size_ / 16;
@@ -117,12 +117,12 @@ class GeneratedIconImageSource : public gfx::CanvasImageSource {
// The text rect's size needs to be odd to center the text correctly.
gfx::Rect text_rect(icon_inset, icon_inset, icon_size + 1, icon_size + 1);
// Draw the letter onto the rounded rect. The letter's color depends on the
- // luminance of |color|.
- unsigned char luminance = color_utils::GetLuminanceForColor(color_);
+ // luma of |color|.
+ const uint8_t luma = color_utils::GetLuma(color_);
canvas->DrawStringRectWithFlags(
base::string16(1, std::toupper(letter_)),
gfx::FontList(gfx::Font(font_name, font_size)),
- luminance > kLuminanceThreshold ? SK_ColorBLACK : SK_ColorWHITE,
+ (luma > kLumaThreshold) ? SK_ColorBLACK : SK_ColorWHITE,
text_rect,
gfx::Canvas::TEXT_ALIGN_CENTER);
}
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index 54003bd..e4d5461 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -600,7 +600,7 @@ SkColor ThemeService::GetColor(int id, bool incognito) const {
return color_utils::GetReadableColor(
SK_ColorWHITE, GetColor(kLabelBackground, incognito));
case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND:
- return color_utils::BlendTowardOppositeLuminance(
+ return color_utils::BlendTowardOppositeLuma(
GetColor(ThemeProperties::COLOR_FRAME, incognito), 0x80);
case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BORDER:
return color_utils::AlphaBlend(GetColor(kLabelBackground, incognito),
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
index f25d8a9..e22761f 100644
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
@@ -903,7 +903,7 @@ void Gtk2UI::LoadGtkValues() {
if (ui::MaterialDesignController::IsModeMaterial()) {
colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
- color_utils::BlendTowardOppositeLuminance(label_color, 50);
+ color_utils::BlendTowardOppositeLuma(label_color, 50);
} else {
// The inactive frame color never occurs naturally in the theme, as it is a
// tinted version of |frame_color|. We generate another color based on the
diff --git a/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc b/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc
index 33adf23..8d3818b 100644
--- a/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc
+++ b/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc
@@ -48,7 +48,7 @@ SkColor GetSigninConfirmationPromptBarColor(ui::NativeTheme* theme,
SkAlpha alpha) {
static const SkColor kBackgroundColor =
theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
- return color_utils::BlendTowardOppositeLuminance(kBackgroundColor, alpha);
+ return color_utils::BlendTowardOppositeLuma(kBackgroundColor, alpha);
}
bool HasBeenShutdown(Profile* profile) {
diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc
index c14f2b9..37e1d3f 100644
--- a/chrome/browser/ui/views/download/download_item_view.cc
+++ b/chrome/browser/ui/views/download/download_item_view.cc
@@ -61,45 +61,44 @@
using content::DownloadItem;
using extensions::ExperienceSamplingEvent;
+namespace {
+
// TODO(paulg): These may need to be adjusted when download progress
// animation is added, and also possibly to take into account
// different screen resolutions.
-static const int kTextWidth = 140; // Pixels
-static const int kDangerousTextWidth = 200; // Pixels
-static const int kVerticalPadding = 3; // Pixels
-static const int kVerticalTextPadding = 2; // Pixels
-static const int kTooltipMaxWidth = 800; // Pixels
+const int kTextWidth = 140; // Pixels
+const int kDangerousTextWidth = 200; // Pixels
+const int kVerticalPadding = 3; // Pixels
+const int kVerticalTextPadding = 2; // Pixels
+const int kTooltipMaxWidth = 800; // Pixels
// Padding around progress indicator, on all sides.
-static const int kProgressPadding = 7;
+const int kProgressPadding = 7;
// We add some padding before the left image so that the progress animation icon
// hides the corners of the left image.
-static const int kLeftPadding = 0; // Pixels.
+const int kLeftPadding = 0; // Pixels.
// The space between the Save and Discard buttons when prompting for a dangerous
// download.
-static const int kButtonPadding = 5; // Pixels.
+const int kButtonPadding = 5; // Pixels.
// The space on the left and right side of the dangerous download label.
-static const int kLabelPadding = 4; // Pixels.
+const int kLabelPadding = 4; // Pixels.
-static const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212);
+const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212);
// How long the 'download complete' animation should last for.
-static const int kCompleteAnimationDurationMs = 2500;
+const int kCompleteAnimationDurationMs = 2500;
// How long the 'download interrupted' animation should last for.
-static const int kInterruptedAnimationDurationMs = 2500;
+const int kInterruptedAnimationDurationMs = 2500;
// How long we keep the item disabled after the user clicked it to open the
// downloaded item.
-static const int kDisabledOnOpenDuration = 3000;
+const int kDisabledOnOpenDuration = 3000;
-// Darken light-on-dark download status text by 20% before drawing, thus
-// creating a "muted" version of title text for both dark-on-light and
-// light-on-dark themes.
-static const double kDownloadItemLuminanceMod = 0.8;
+} // namespace
DownloadItemView::DownloadItemView(DownloadItem* download_item,
DownloadShelfView* parent)
@@ -699,16 +698,12 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) {
kVerticalTextPadding;
SkColor file_name_color = GetThemeProvider()->GetColor(
ThemeProperties::COLOR_BOOKMARK_TEXT);
- // If text is light-on-dark, lightening it alone will do nothing.
- // Therefore we mute luminance a wee bit before drawing in this case.
- if (color_utils::RelativeLuminance(file_name_color) > 0.5)
- file_name_color = SkColorSetRGB(
- static_cast<int>(kDownloadItemLuminanceMod *
- SkColorGetR(file_name_color)),
- static_cast<int>(kDownloadItemLuminanceMod *
- SkColorGetG(file_name_color)),
- static_cast<int>(kDownloadItemLuminanceMod *
- SkColorGetB(file_name_color)));
+ // If text is light-on-dark, lightening it alone will do nothing. In this
+ // case we multiply color components by 80% before drawing.
+ if (!color_utils::IsDark(file_name_color)) {
+ file_name_color =
+ color_utils::AlphaBlend(SK_ColorBLACK, file_name_color, 255 / 5);
+ }
canvas->DrawStringRect(status_text_, font_list_, file_name_color,
gfx::Rect(mirrored_x, y, kTextWidth,
font_list_.GetHeight()));
diff --git a/components/favicon_base/fallback_icon_style.cc b/components/favicon_base/fallback_icon_style.cc
index 83305f7..66ee5997 100644
--- a/components/favicon_base/fallback_icon_style.cc
+++ b/components/favicon_base/fallback_icon_style.cc
@@ -13,14 +13,14 @@ namespace favicon_base {
namespace {
-// Luminance threshold for background color determine whether to use dark or
-// light text color.
-const int kDarkTextLuminanceThreshold = 190;
+// Luma threshold for background color determine whether to use dark or light
+// text color.
+const uint8_t kDarkTextLumaThreshold = 190;
-// The maximum luminance of the background color to ensure light text is
+// The maximum lightness of the background color to ensure light text is
// readable.
-const double kMaxBackgroundColorLuminance = 0.67;
-const double kMinBackgroundColorLuminance = 0.15;
+const double kMaxBackgroundColorLightness = 0.67;
+const double kMinBackgroundColorLightness = 0.15;
// Default values for FallbackIconStyle.
const SkColor kDefaultBackgroundColor = SkColorSetRGB(0x78, 0x78, 0x78);
@@ -51,9 +51,9 @@ bool FallbackIconStyle::operator==(const FallbackIconStyle& other) const {
void MatchFallbackIconTextColorAgainstBackgroundColor(
FallbackIconStyle* style) {
- int luminance = color_utils::GetLuminanceForColor(style->background_color);
- style->text_color = (luminance >= kDarkTextLuminanceThreshold ?
- kDefaultTextColorDark : kDefaultTextColorLight);
+ const uint8_t luma = color_utils::GetLuma(style->background_color);
+ style->text_color = (luma >= kDarkTextLumaThreshold) ?
+ kDefaultTextColorDark : kDefaultTextColorLight;
}
bool ValidateFallbackIconStyle(const FallbackIconStyle& style) {
@@ -64,20 +64,20 @@ bool ValidateFallbackIconStyle(const FallbackIconStyle& style) {
void SetDominantColorAsBackground(
const scoped_refptr<base::RefCountedMemory>& bitmap_data,
FallbackIconStyle* style) {
- // Try to ensure color's luminance isn't too large so that light text is
+ // Try to ensure color's lightness isn't too large so that light text is
// visible. Set an upper bound for the dominant color.
- const color_utils::HSL lower_bound{-1.0, -1.0, kMinBackgroundColorLuminance};
- const color_utils::HSL upper_bound{-1.0, -1.0, kMaxBackgroundColorLuminance};
+ const color_utils::HSL lower_bound{-1.0, -1.0, kMinBackgroundColorLightness};
+ const color_utils::HSL upper_bound{-1.0, -1.0, kMaxBackgroundColorLightness};
color_utils::GridSampler sampler;
SkColor dominant_color = color_utils::CalculateKMeanColorOfPNG(
bitmap_data, lower_bound, upper_bound, &sampler);
// |CalculateKMeanColorOfPNG| will try to return a color that lies within the
// specified bounds if one exists in the image. If there's no such color, it
// will return the dominant color which may be lighter than our upper bound.
- // Clamp luminance down to a reasonable maximum value so text is readable.
+ // Clamp lightness down to a reasonable maximum value so text is readable.
color_utils::HSL color_hsl;
color_utils::SkColorToHSL(dominant_color, &color_hsl);
- color_hsl.l = std::min(color_hsl.l, kMaxBackgroundColorLuminance);
+ color_hsl.l = std::min(color_hsl.l, kMaxBackgroundColorLightness);
style->background_color =
color_utils::HSLToSkColor(color_hsl, SK_AlphaOPAQUE);
}
diff --git a/mash/wm/frame/default_header_painter.cc b/mash/wm/frame/default_header_painter.cc
index ed2a66d..dfc1ed1 100644
--- a/mash/wm/frame/default_header_painter.cc
+++ b/mash/wm/frame/default_header_painter.cc
@@ -40,8 +40,6 @@ const SkColor kHeaderContentSeparatorInactiveColor =
const SkColor kDefaultFrameColor = SkColorSetRGB(242, 242, 242);
// Duration of crossfade animation for activating and deactivating frame.
const int kActivationCrossfadeDurationMs = 200;
-// Luminance below which to use white caption buttons.
-const int kMaxLuminanceForLightButtons = 125;
// Tiles an image into an area, rounding the top corners.
void TileRoundRect(gfx::Canvas* canvas,
@@ -269,9 +267,8 @@ void DefaultHeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas) {
}
bool DefaultHeaderPainter::ShouldUseLightImages() {
- int luminance = color_utils::GetLuminanceForColor(
+ return color_utils::IsDark(
mode_ == MODE_INACTIVE ? inactive_frame_color_ : active_frame_color_);
- return luminance < kMaxLuminanceForLightButtons;
}
void DefaultHeaderPainter::UpdateAllButtonImages() {
diff --git a/ui/gfx/color_utils.cc b/ui/gfx/color_utils.cc
index 2e3c96f..a4618f2 100644
--- a/ui/gfx/color_utils.cc
+++ b/ui/gfx/color_utils.cc
@@ -42,35 +42,21 @@ int calcHue(double temp1, double temp2, double hue) {
else if (hue * 3.0 < 2.0)
result = temp1 + (temp2 - temp1) * (2.0 / 3.0 - hue) * 6.0;
- // Scale the result from 0 - 255 and round off the value.
- return static_cast<int>(result * 255 + .5);
+ return static_cast<int>(std::round(result * 255));
}
-// Next two functions' formulas from:
-// http://www.w3.org/TR/WCAG20/#relativeluminancedef
-// http://www.w3.org/TR/WCAG20/#contrast-ratiodef
-
-double ConvertSRGB(double eight_bit_component) {
+// Assumes sRGB.
+double Linearize(double eight_bit_component) {
const double component = eight_bit_component / 255.0;
return (component <= 0.03928) ?
(component / 12.92) : pow((component + 0.055) / 1.055, 2.4);
}
-SkColor LumaInvertColor(SkColor color) {
+SkColor LightnessInvertColor(SkColor color) {
HSL hsl;
SkColorToHSL(color, &hsl);
hsl.l = 1.0 - hsl.l;
- return HSLToSkColor(hsl, 255);
-}
-
-double ContrastRatio(double foreground_luminance, double background_luminance) {
- DCHECK_GE(foreground_luminance, 0.0);
- DCHECK_GE(background_luminance, 0.0);
- foreground_luminance += 0.05;
- background_luminance += 0.05;
- return (foreground_luminance > background_luminance) ?
- (foreground_luminance / background_luminance) :
- (background_luminance / foreground_luminance);
+ return HSLToSkColor(hsl, SkColorGetA(color));
}
} // namespace
@@ -79,20 +65,29 @@ double ContrastRatio(double foreground_luminance, double background_luminance) {
// ----------------------------------------------------------------------------
double GetContrastRatio(SkColor color_a, SkColor color_b) {
- return ContrastRatio(RelativeLuminance(color_a), RelativeLuminance(color_b));
+ return GetContrastRatio(GetRelativeLuminance(color_a),
+ GetRelativeLuminance(color_b));
}
-unsigned char GetLuminanceForColor(SkColor color) {
- return base::saturated_cast<unsigned char>(
- (0.3 * SkColorGetR(color)) +
- (0.59 * SkColorGetG(color)) +
- (0.11 * SkColorGetB(color)));
+double GetContrastRatio(double luminance_a, double luminance_b) {
+ DCHECK_GE(luminance_a, 0.0);
+ DCHECK_GE(luminance_b, 0.0);
+ luminance_a += 0.05;
+ luminance_b += 0.05;
+ return (luminance_a > luminance_b) ? (luminance_a / luminance_b)
+ : (luminance_b / luminance_a);
}
-double RelativeLuminance(SkColor color) {
- return (0.2126 * ConvertSRGB(SkColorGetR(color))) +
- (0.7152 * ConvertSRGB(SkColorGetG(color))) +
- (0.0722 * ConvertSRGB(SkColorGetB(color)));
+double GetRelativeLuminance(SkColor color) {
+ return (0.2126 * Linearize(SkColorGetR(color))) +
+ (0.7152 * Linearize(SkColorGetG(color))) +
+ (0.0722 * Linearize(SkColorGetB(color)));
+}
+
+uint8_t GetLuma(SkColor color) {
+ return static_cast<uint8_t>(std::round((0.299 * SkColorGetR(color)) +
+ (0.587 * SkColorGetG(color)) +
+ (0.114 * SkColorGetB(color))));
}
void SkColorToHSL(SkColor c, HSL* hsl) {
@@ -242,7 +237,7 @@ void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]) {
int pixel_height = bitmap.height();
for (int y = 0; y < pixel_height; ++y) {
for (int x = 0; x < pixel_width; ++x)
- ++histogram[GetLuminanceForColor(bitmap.getColor(x, y))];
+ ++histogram[GetLuma(bitmap.getColor(x, y))];
}
}
@@ -287,20 +282,28 @@ SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha) {
}
bool IsDark(SkColor color) {
- return GetLuminanceForColor(color) < 128;
+ return GetLuma(color) < 128;
}
-SkColor BlendTowardOppositeLuminance(SkColor color, SkAlpha alpha) {
+SkColor BlendTowardOppositeLuma(SkColor color, SkAlpha alpha) {
return AlphaBlend(IsDark(color) ? SK_ColorWHITE : SK_ColorBLACK, color,
alpha);
}
SkColor GetReadableColor(SkColor foreground, SkColor background) {
- const SkColor foreground2 = LumaInvertColor(foreground);
- const double background_luminance = RelativeLuminance(background);
- return (ContrastRatio(RelativeLuminance(foreground), background_luminance) >=
- ContrastRatio(RelativeLuminance(foreground2), background_luminance)) ?
- foreground : foreground2;
+ return PickContrastingColor(foreground, LightnessInvertColor(foreground),
+ background);
+}
+
+SkColor PickContrastingColor(SkColor foreground1,
+ SkColor foreground2,
+ SkColor background) {
+ const double background_luminance = GetRelativeLuminance(background);
+ return (GetContrastRatio(GetRelativeLuminance(foreground1),
+ background_luminance) >=
+ GetContrastRatio(GetRelativeLuminance(foreground2),
+ background_luminance)) ?
+ foreground1 : foreground2;
}
SkColor InvertColor(SkColor color) {
diff --git a/ui/gfx/color_utils.h b/ui/gfx/color_utils.h
index 44302c8..fc8b446 100644
--- a/ui/gfx/color_utils.h
+++ b/ui/gfx/color_utils.h
@@ -23,13 +23,21 @@ struct HSL {
// This value is taken from w3c accessibility guidelines.
const double kMinimumReadableContrastRatio = 4.5f;
-// Determines the contrast ratio of two colors.
+// Determines the contrast ratio of two colors or two relative luminance values
+// (as computed by RelativeLuminance()), calculated according to
+// http://www.w3.org/TR/WCAG20/#contrast-ratiodef .
GFX_EXPORT double GetContrastRatio(SkColor color_a, SkColor color_b);
+GFX_EXPORT double GetContrastRatio(double luminance_a, double luminance_b);
-GFX_EXPORT unsigned char GetLuminanceForColor(SkColor color);
+// The relative luminance of |color|, that is, the weighted sum of the
+// linearized RGB components, normalized to 0..1, per BT.709. See
+// http://www.w3.org/TR/WCAG20/#relativeluminancedef .
+GFX_EXPORT double GetRelativeLuminance(SkColor color);
-// Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef
-GFX_EXPORT double RelativeLuminance(SkColor color);
+// The luma of |color|, that is, the weighted sum of the gamma-compressed R'G'B'
+// components, per BT.601, a.k.a. the Y' in Y'UV. See
+// https://en.wikipedia.org/wiki/Luma_(video).
+GFX_EXPORT uint8_t GetLuma(SkColor color);
// Note: these transformations assume sRGB as the source color space
GFX_EXPORT void SkColorToHSL(SkColor c, HSL* hsl);
@@ -50,8 +58,8 @@ GFX_EXPORT bool IsWithinHSLRange(const HSL& hsl,
const HSL& upper_bound);
// Makes |hsl| valid input for HSLShift(). Sets values of hue, saturation
-// and luminosity which are outside of the valid range [0, 1] to -1.
-// -1 is a special value which indicates 'no change'.
+// and lightness which are outside of the valid range [0, 1] to -1. -1 is a
+// special value which indicates 'no change'.
GFX_EXPORT void MakeHSLShiftValid(HSL* hsl);
// HSL-Shift an SkColor. The shift values are in the range of 0-1, with the
@@ -70,8 +78,7 @@ GFX_EXPORT void MakeHSLShiftValid(HSL* hsl);
// 1 = full lightness (make all pixels white).
GFX_EXPORT SkColor HSLShift(SkColor color, const HSL& shift);
-// Builds a histogram based on the Y' of the Y'UV representation of
-// this image.
+// Builds a histogram based on the Y' of the Y'UV representation of this image.
GFX_EXPORT void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]);
// Calculates how "boring" an image is. The boring score is the
@@ -87,25 +94,30 @@ GFX_EXPORT double CalculateBoringScore(const SkBitmap& bitmap);
GFX_EXPORT SkColor AlphaBlend(SkColor foreground, SkColor background,
SkAlpha alpha);
-// Returns true if the luminance of |color| is closer to black than white.
+// Returns true if the luma of |color| is closer to black than white.
GFX_EXPORT bool IsDark(SkColor color);
// Makes a dark color lighter or a light color darker by blending |color| with
-// white or black depending on its current luminance. |alpha| controls the
-// amount of white or black that will be alpha-blended into |color|.
-GFX_EXPORT SkColor BlendTowardOppositeLuminance(SkColor color, SkAlpha alpha);
-
-// Given an opaque foreground and background color, try to return a foreground
-// color that is "readable" over the background color by luma-inverting the
-// foreground color and then picking whichever foreground color has higher
-// contrast against the background color. You should not pass colors with
-// non-255 alpha to this routine, since determining the correct behavior in such
-// cases can be impossible.
+// white or black depending on its current luma. |alpha| controls the amount of
+// white or black that will be alpha-blended into |color|.
+GFX_EXPORT SkColor BlendTowardOppositeLuma(SkColor color, SkAlpha alpha);
+
+// Given a foreground and background color, try to return a foreground color
+// that is "readable" over the background color by luma-inverting the foreground
+// color and then using PickContrastingColor() to pick the one with greater
+// contrast. During this process, alpha values will be ignored; the returned
+// color will have the same alpha as |foreground|.
//
// NOTE: This won't do anything but waste time if the supplied foreground color
// has a luma value close to the midpoint (0.5 in the HSL representation).
GFX_EXPORT SkColor GetReadableColor(SkColor foreground, SkColor background);
+// Returns whichever of |foreground1| or |foreground2| has higher contrast with
+// |background|.
+GFX_EXPORT SkColor PickContrastingColor(SkColor foreground1,
+ SkColor foreground2,
+ SkColor background);
+
// Invert a color.
GFX_EXPORT SkColor InvertColor(SkColor color);
diff --git a/ui/gfx/sys_color_change_listener.cc b/ui/gfx/sys_color_change_listener.cc
index a814096..fcda189 100644
--- a/ui/gfx/sys_color_change_listener.cc
+++ b/ui/gfx/sys_color_change_listener.cc
@@ -20,16 +20,16 @@ bool g_is_inverted_color_scheme = false;
bool g_is_inverted_color_scheme_initialized = false;
void UpdateInvertedColorScheme() {
- int foreground_luminance = color_utils::GetLuminanceForColor(
- color_utils::GetSysSkColor(COLOR_WINDOWTEXT));
- int background_luminance = color_utils::GetLuminanceForColor(
- color_utils::GetSysSkColor(COLOR_WINDOW));
+ const uint8_t foreground_luma =
+ color_utils::GetLuma(color_utils::GetSysSkColor(COLOR_WINDOWTEXT));
+ const uint8_t background_luma =
+ color_utils::GetLuma(color_utils::GetSysSkColor(COLOR_WINDOW));
HIGHCONTRAST high_contrast = {0};
high_contrast.cbSize = sizeof(HIGHCONTRAST);
g_is_inverted_color_scheme =
SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &high_contrast, 0) &&
((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0) &&
- foreground_luminance > background_luminance;
+ foreground_luma > background_luma;
g_is_inverted_color_scheme_initialized = true;
}