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

Unified Diff: ui/gfx/color_analysis.cc

Issue 2797033002: ChromeOS color extraction - only look at a maximum of 10k pixels in the (Closed)
Patch Set: oops Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/color_analysis.cc
diff --git a/ui/gfx/color_analysis.cc b/ui/gfx/color_analysis.cc
index 301b6b9fae1ab78f1154fd78ef81d5b0834f7c2d..d3e8998266dc654e5162ba1d4cef7031861becfa 100644
--- a/ui/gfx/color_analysis.cc
+++ b/ui/gfx/color_analysis.cc
@@ -368,15 +368,16 @@ SkColor CalculateProminentColor(const SkBitmap& bitmap,
const uint32_t* pixels = static_cast<uint32_t*>(bitmap.getPixels());
const int pixel_count = bitmap.width() * bitmap.height();
- // We don't know exactly how many distinct colors there will be, so just
- // reserve enough space to keep the maximum number of table resizes low.
- // In our testing set, 2/3 of wallpapers have <200k unique colors and 1/4
- // have <100k. Thus 200k is picked as a number that usually amounts to zero
- // resizes but usually doesn't waste a lot of space.
- std::unordered_map<SkColor, int> color_counts(200000);
+ // For better performance, only consider at most 10k pixels (evenly
+ // distributed throughout the image). This has a very minor impact on the
+ // outcome but improves runtime substantially for large images. 10,007 is a
+ // prime number to reduce the chance of picking an unrepresentative sample.
James Cook 2017/04/07 14:05:47 Good idea.
Nico 2017/04/07 15:33:22 I'm too dense to understand why the divisor being
+ constexpr int kMaxConsideredPixels = 10007;
+ const int pixel_increment = std::max(1, pixel_count / kMaxConsideredPixels);
+ std::unordered_map<SkColor, int> color_counts(kMaxConsideredPixels);
// First extract all colors into counts.
- for (int i = 0; i < pixel_count; ++i) {
+ for (int i = 0; i < pixel_count; i += pixel_increment) {
// SkBitmap uses pre-multiplied alpha but the prominent color algorithm
// needs non-pre-multiplied alpha.
const SkColor pixel = SkUnPreMultiply::PMColorToColor(pixels[i]);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698