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

Unified Diff: ui/gfx/color_utils.cc

Issue 289283004: Add ability to constrain dominant color selection to a HSL range. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make bounds inclusive, add saturation test Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/color_utils.cc
diff --git a/ui/gfx/color_utils.cc b/ui/gfx/color_utils.cc
index de429495990ae13bcfaaac696953599f87c788ce..25f072f2ef723f5c9e2808c5aa20f32835ba7339 100644
--- a/ui/gfx/color_utils.cc
+++ b/ui/gfx/color_utils.cc
@@ -151,6 +151,22 @@ 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);
Matt Giuca 2014/05/22 05:03:52 Your comment says this is inclusive, inclusive. Wh
Matt Giuca 2014/05/22 05:03:52 Should also DCHECK the hsl.s and hsl.l, as well as
calamity 2014/05/22 07:36:36 The comment says the bounds are inclusive, inclusi
calamity 2014/05/22 07:36:36 Values can be negative to specify ignore.
+
+ // 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);
« ui/gfx/color_utils.h ('K') | « ui/gfx/color_utils.h ('k') | ui/gfx/color_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698