Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon_base/fallback_icon_style.h" | 5 #include "components/favicon_base/fallback_icon_style.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/gfx/color_analysis.h" | 9 #include "ui/gfx/color_analysis.h" |
| 10 #include "ui/gfx/color_utils.h" | 10 #include "ui/gfx/color_utils.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool ValidateFallbackIconStyle(const FallbackIconStyle& style) { | 58 bool ValidateFallbackIconStyle(const FallbackIconStyle& style) { |
| 59 return style.font_size_ratio >= 0.0 && style.font_size_ratio <= 1.0 && | 59 return style.font_size_ratio >= 0.0 && style.font_size_ratio <= 1.0 && |
| 60 style.roundness >= 0.0 && style.roundness <= 1.0; | 60 style.roundness >= 0.0 && style.roundness <= 1.0; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void SetDominantColorAsBackground( | 63 void SetDominantColorAsBackground( |
| 64 const scoped_refptr<base::RefCountedMemory>& bitmap_data, | 64 const scoped_refptr<base::RefCountedMemory>& bitmap_data, |
| 65 FallbackIconStyle* style) { | 65 FallbackIconStyle* style) { |
| 66 SkColor dominant_color = | 66 // Try to ensure color's luminance isn't too large so that light text is |
| 67 color_utils::CalculateKMeanColorOfPNG(bitmap_data); | 67 // visible. Set an upper bound for the dominant color. |
| 68 // Assumes |style.text_color| is light, and clamps luminance down to a | 68 const color_utils::HSL lower_bound{-1.0, -1.0, 0.15}; |
|
pkotwicz
2015/10/05 14:23:27
Is there a reason 0.15 is not a constant?
mpawlowski
2015/10/05 14:28:26
Not rally, it's just the same number as the one us
pkotwicz
2015/10/05 14:46:21
I don't have much of a preference because color_an
| |
| 69 // reasonable maximum value so text is readable. | 69 const color_utils::HSL upper_bound{-1.0, -1.0, kMaxBackgroundColorLuminance}; |
| 70 color_utils::GridSampler sampler; | |
| 71 SkColor dominant_color = color_utils::CalculateKMeanColorOfPNG( | |
| 72 bitmap_data, lower_bound, upper_bound, &sampler); | |
| 73 // |CalculateKMeanColorOfPNG| will try to return a color that lies within the | |
| 74 // specified bounds if one exists in the image. If there's no such color, it | |
| 75 // will return the dominant color which may be lighter than our upper bound. | |
| 76 // Clamp luminance down to a reasonable maximum value so text is readable. | |
| 70 color_utils::HSL color_hsl; | 77 color_utils::HSL color_hsl; |
| 71 color_utils::SkColorToHSL(dominant_color, &color_hsl); | 78 color_utils::SkColorToHSL(dominant_color, &color_hsl); |
| 72 color_hsl.l = std::min(color_hsl.l, kMaxBackgroundColorLuminance); | 79 color_hsl.l = std::min(color_hsl.l, kMaxBackgroundColorLuminance); |
| 73 style->background_color = | 80 style->background_color = |
| 74 color_utils::HSLToSkColor(color_hsl, SK_AlphaOPAQUE); | 81 color_utils::HSLToSkColor(color_hsl, SK_AlphaOPAQUE); |
| 75 } | 82 } |
| 76 | 83 |
| 77 } // namespace favicon_base | 84 } // namespace favicon_base |
| OLD | NEW |