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

Side by Side Diff: chrome/browser/ui/webui/ntp/favicon_webui_handler.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" 5 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 19 matching lines...) Expand all
30 base::StringValue* SkColorToCss(SkColor color) { 30 base::StringValue* SkColorToCss(SkColor color) {
31 return new base::StringValue(base::StringPrintf("rgb(%d, %d, %d)", 31 return new base::StringValue(base::StringPrintf("rgb(%d, %d, %d)",
32 SkColorGetR(color), 32 SkColorGetR(color),
33 SkColorGetG(color), 33 SkColorGetG(color),
34 SkColorGetB(color))); 34 SkColorGetB(color)));
35 } 35 }
36 36
37 base::StringValue* GetDominantColorCssString( 37 base::StringValue* GetDominantColorCssString(
38 scoped_refptr<base::RefCountedMemory> png) { 38 scoped_refptr<base::RefCountedMemory> png) {
39 color_utils::GridSampler sampler; 39 color_utils::GridSampler sampler;
40 SkColor color = 40 SkColor color = color_utils::CalculateKMeanColorOfPNG(png);
41 color_utils::CalculateKMeanColorOfPNG(png, 100, 665, &sampler);
42 return SkColorToCss(color); 41 return SkColorToCss(color);
43 } 42 }
44 43
45 } // namespace 44 } // namespace
46 45
47 // Thin inheritance-dependent trampoline to forward notification of app 46 // Thin inheritance-dependent trampoline to forward notification of app
48 // icon loads to the FaviconWebUIHandler. Base class does caching of icons. 47 // icon loads to the FaviconWebUIHandler. Base class does caching of icons.
49 class ExtensionIconColorManager : public ExtensionIconManager { 48 class ExtensionIconColorManager : public ExtensionIconManager {
50 public: 49 public:
51 explicit ExtensionIconColorManager(FaviconWebUIHandler* handler) 50 explicit ExtensionIconColorManager(FaviconWebUIHandler* handler)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) 158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits))
160 return; 159 return;
161 scoped_refptr<base::RefCountedStaticMemory> bits_mem( 160 scoped_refptr<base::RefCountedStaticMemory> bits_mem(
162 new base::RefCountedStaticMemory(&bits.front(), bits.size())); 161 new base::RefCountedStaticMemory(&bits.front(), bits.size()));
163 scoped_ptr<base::StringValue> color_value( 162 scoped_ptr<base::StringValue> color_value(
164 GetDominantColorCssString(bits_mem)); 163 GetDominantColorCssString(bits_mem));
165 base::StringValue id(extension_id); 164 base::StringValue id(extension_id);
166 web_ui()->CallJavascriptFunction( 165 web_ui()->CallJavascriptFunction(
167 "ntp.setFaviconDominantColor", id, *color_value); 166 "ntp.setFaviconDominantColor", id, *color_value);
168 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698