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

Side by Side Diff: components/enhanced_bookmarks/image_store_util.cc

Issue 875463003: ★ Record the image dominant color in the image database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/enhanced_bookmarks/image_store_util.h" 5 #include "components/enhanced_bookmarks/image_store_util.h"
6 6
7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/gfx/color_analysis.h"
7 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
8 #include "ui/gfx/image/image_util.h" 10 #include "ui/gfx/image/image_util.h"
9 11
10 namespace { 12 namespace {
11 const int kJpegEncodingQuality = 70; 13 const int kJpegEncodingQuality = 70;
12 } // namespace 14 } // namespace
13 15
14 namespace enhanced_bookmarks { 16 namespace enhanced_bookmarks {
15 17
16 scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) { 18 scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
17 DCHECK(image.AsImageSkia().image_reps().size() == 1); 19 DCHECK(image.AsImageSkia().image_reps().size() == 1);
18 DCHECK(image.AsImageSkia().image_reps().begin()->scale() == 1.0f); 20 DCHECK(image.AsImageSkia().image_reps().begin()->scale() == 1.0f);
19 21
20 std::vector<unsigned char> data; 22 std::vector<unsigned char> data;
21 bool succeeded = 23 bool succeeded =
22 gfx::JPEG1xEncodedDataFromImage(image, kJpegEncodingQuality, &data); 24 gfx::JPEG1xEncodedDataFromImage(image, kJpegEncodingQuality, &data);
23 25
24 if (!succeeded) 26 if (!succeeded)
25 return scoped_refptr<base::RefCountedMemory>(); 27 return scoped_refptr<base::RefCountedMemory>();
26 28
27 return scoped_refptr<base::RefCountedMemory>(new base::RefCountedBytes(data)); 29 return scoped_refptr<base::RefCountedMemory>(new base::RefCountedBytes(data));
28 } 30 }
29 31
30 gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& bytes) { 32 gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& bytes) {
31 return gfx::ImageFrom1xJPEGEncodedData(bytes->front(), bytes->size()); 33 return gfx::ImageFrom1xJPEGEncodedData(bytes->front(), bytes->size());
32 } 34 }
35
36 SkColor DominantColorForImage(const gfx::Image& image) {
37 return color_utils::CalculateKMeanColorOfBitmap(*image.ToSkBitmap());
33 } 38 }
39 }
OLDNEW
« no previous file with comments | « components/enhanced_bookmarks/image_store_util.h ('k') | components/enhanced_bookmarks/image_store_util_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698