Index: ui/gfx/color_utils.cc |
diff --git a/ui/gfx/color_utils.cc b/ui/gfx/color_utils.cc |
index de429495990ae13bcfaaac696953599f87c788ce..39e8e351869a59a1fa4791ba291911327b2aca2e 100644 |
--- a/ui/gfx/color_utils.cc |
+++ b/ui/gfx/color_utils.cc |
@@ -151,6 +151,31 @@ SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha) { |
calcHue(temp1, temp2, hue - 1.0 / 3.0)); |
} |
+bool IsWithinHSLRange(const HSL& hsl, |
+ const HSL& lower_bound, |
+ const HSL& upper_bound) { |
+ DCHECK(hsl.h >= 0 && hsl.h <= 1); |
Alexei Svitkine (slow)
2014/05/30 14:56:39
Nit: DCHECK(hsl.h >= 0 && hsl.h <= 1) << hsl.h;
S
calamity
2014/06/02 03:53:17
Done.
|
+ DCHECK(hsl.s >= 0 && hsl.s <= 1); |
+ DCHECK(hsl.l >= 0 && hsl.l <= 1); |
+ DCHECK(lower_bound.h <= 1); |
Alexei Svitkine (slow)
2014/05/30 14:56:39
Nit: DCHECK_LE
calamity
2014/06/02 03:53:17
Removed.
|
+ DCHECK(lower_bound.s <= 1); |
+ DCHECK(lower_bound.l <= 1); |
+ DCHECK(lower_bound.h < 0 || |
+ (upper_bound.h >= 0 && upper_bound.h <= lower_bound.h + 1)); |
Alexei Svitkine (slow)
2014/05/30 14:56:39
Don't these three checks not match what's document
calamity
2014/06/02 03:53:17
They were a subset. Changed to exactly match comme
|
+ DCHECK(lower_bound.s < 0 || (upper_bound.s >= 0 && upper_bound.s <= 1)); |
+ DCHECK(lower_bound.l < 0 || (upper_bound.l >= 0 && upper_bound.l <= 1)); |
+ |
+ // If the upper hue is >1, the given hue bounds wrap around at 1. |
+ bool matches_hue = upper_bound.h > 1 |
+ ? hsl.h >= lower_bound.h || hsl.h <= upper_bound.h - 1 |
+ : hsl.h >= lower_bound.h && hsl.h <= upper_bound.h; |
+ return (upper_bound.h < 0 || lower_bound.h < 0 || matches_hue) && |
+ (upper_bound.s < 0 || lower_bound.s < 0 || |
+ (hsl.s >= lower_bound.s && hsl.s <= upper_bound.s)) && |
+ (upper_bound.l < 0 || lower_bound.l < 0 || |
+ (hsl.l >= lower_bound.l && hsl.l <= upper_bound.l)); |
+} |
+ |
SkColor HSLShift(SkColor color, const HSL& shift) { |
HSL hsl; |
int alpha = SkColorGetA(color); |