Chromium Code Reviews| Index: ui/gfx/color_analysis.h |
| diff --git a/ui/gfx/color_analysis.h b/ui/gfx/color_analysis.h |
| index dcbfabc9d7757d20ee6e0cf8f26c986fe5fd843f..2f0d940916953751c11cc31239944e5d5f7500a9 100644 |
| --- a/ui/gfx/color_analysis.h |
| +++ b/ui/gfx/color_analysis.h |
| @@ -17,6 +17,8 @@ class SkBitmap; |
| namespace color_utils { |
| +struct HSL; |
| + |
| // This class exposes the sampling method to the caller, which allows |
| // stubbing out for things like unit tests. Might be useful to pass more |
| // arguments into the GetSample method in the future (such as which |
| @@ -56,10 +58,9 @@ GFX_EXPORT SkColor FindClosestColor(const uint8_t* image, int width, int height, |
| // This uses a KMean clustering algorithm to find clusters of pixel colors in |
| // RGB space. |
| // |png| represents the data of a png encoded image. |
| -// |darkness_limit| represents the minimum sum of the RGB components that is |
| -// acceptable as a color choice. This can be from 0 to 765. |
| -// |brightness_limit| represents the maximum sum of the RGB components that is |
| -// acceptable as a color choice. This can be from 0 to 765. |
| +// |lower_bound| represents the minimum bounding range of HSL values to allow. |
|
Matt Giuca
2014/05/22 05:03:52
"minimum bound of ..." (what is a "minimum boundin
calamity
2014/05/22 07:36:36
Done.
|
| +// |upper_bound| represents the maximum bounding range of HSL values to allow. |
| +// See color_utils::IsWithinHSLRange() for description of these bounds. |
| // |
| // RGB KMean Algorithm (N clusters, M iterations): |
| // 1.Pick N starting colors by randomly sampling the pixels. If you see a |
| @@ -82,21 +83,23 @@ GFX_EXPORT SkColor FindClosestColor(const uint8_t* image, int width, int height, |
| // the clusters by weight (where weight is the number of pixels that make up |
| // this cluster). |
| // 6.Going through the sorted list of clusters, pick the first cluster with the |
| -// largest weight that's centroid fulfills the equation |
| -// |darkness_limit| < SUM(R, G, B) < |brightness_limit|. Return that color. |
| +// largest weight that's centroid that falls between the given |lower_bound| |
|
Matt Giuca
2014/05/22 05:03:52
Remove "that" and "the given".
calamity
2014/05/22 07:36:36
Done.
|
| +// and |upper_bound|. Return that color. |
| // If no color fulfills that requirement return the color with the largest |
| // weight regardless of whether or not it fulfills the equation above. |
| -// |
| -// Note: Switching to HSV space did not improve the results of this algorithm |
| -// for typical favicon images. |
| -GFX_EXPORT SkColor CalculateKMeanColorOfPNG( |
| - scoped_refptr<base::RefCountedMemory> png, |
| - uint32_t darkness_limit, |
| - uint32_t brightness_limit, |
| - KMeanImageSampler* sampler); |
| +GFX_EXPORT SkColor |
| + CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png, |
| + const HSL& lower_bound, |
| + const HSL& upper_bound, |
| + KMeanImageSampler* sampler); |
| + |
| +// Computes a dominant color for a PNG using the above algorithm and |
| +// reasonable defaults for |lower_bound|, |upper_bound| and |sampler|. |
| +GFX_EXPORT SkColor |
| + CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png); |
| // Computes a dominant color for an SkBitmap using the above algorithm and |
| -// reasonable defaults for |darkness_limit|, |brightness_limit| and |sampler|. |
| +// reasonable defaults for |lower_bound|, |upper_bound| and |sampler|. |
| GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap); |
|
Matt Giuca
2014/05/22 05:03:52
Can you also add an overload to CalculateKMeanColo
calamity
2014/05/22 07:36:36
Done.
|
| // Compute color covariance matrix for the input bitmap. |