OLD | NEW |
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 #if defined(OS_WIN) |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return (foreground_luminance > background_luminance) ? | 71 return (foreground_luminance > background_luminance) ? |
72 (foreground_luminance / background_luminance) : | 72 (foreground_luminance / background_luminance) : |
73 (background_luminance / foreground_luminance); | 73 (background_luminance / foreground_luminance); |
74 } | 74 } |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 | 78 |
79 // ---------------------------------------------------------------------------- | 79 // ---------------------------------------------------------------------------- |
80 | 80 |
| 81 double GetContrastRatio(SkColor color_a, SkColor color_b) { |
| 82 return ContrastRatio(RelativeLuminance(color_a), RelativeLuminance(color_b)); |
| 83 } |
| 84 |
81 unsigned char GetLuminanceForColor(SkColor color) { | 85 unsigned char GetLuminanceForColor(SkColor color) { |
82 return base::saturated_cast<unsigned char>( | 86 return base::saturated_cast<unsigned char>( |
83 (0.3 * SkColorGetR(color)) + | 87 (0.3 * SkColorGetR(color)) + |
84 (0.59 * SkColorGetG(color)) + | 88 (0.59 * SkColorGetG(color)) + |
85 (0.11 * SkColorGetB(color))); | 89 (0.11 * SkColorGetB(color))); |
86 } | 90 } |
87 | 91 |
88 double RelativeLuminance(SkColor color) { | 92 double RelativeLuminance(SkColor color) { |
89 return (0.2126 * ConvertSRGB(SkColorGetR(color))) + | 93 return (0.2126 * ConvertSRGB(SkColorGetR(color))) + |
90 (0.7152 * ConvertSRGB(SkColorGetG(color))) + | 94 (0.7152 * ConvertSRGB(SkColorGetG(color))) + |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 #endif // !defined(OS_WIN) | 332 #endif // !defined(OS_WIN) |
329 | 333 |
330 SkColor DeriveDefaultIconColor(SkColor text_color) { | 334 SkColor DeriveDefaultIconColor(SkColor text_color) { |
331 // For black text, this comes out to gfx::kChromeIconGrey. | 335 // For black text, this comes out to gfx::kChromeIconGrey. |
332 SkColor color = BlendTowardOppositeLuminance( | 336 SkColor color = BlendTowardOppositeLuminance( |
333 text_color, SkColorGetR(gfx::kChromeIconGrey)); | 337 text_color, SkColorGetR(gfx::kChromeIconGrey)); |
334 return color; | 338 return color; |
335 } | 339 } |
336 | 340 |
337 } // namespace color_utils | 341 } // namespace color_utils |
OLD | NEW |