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

Side by Side Diff: components/enhanced_bookmarks/image_store_util_ios.mm

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 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/mac/scoped_cftyperef.h" 9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/gfx/color_analysis.h"
11 13
12 namespace { 14 namespace {
13 // An implementation of RefCountedMemory, where the bytes are stored in a 15 // An implementation of RefCountedMemory, where the bytes are stored in a
14 // NSData. This class assumes the NSData is non mutable to avoid a copy. 16 // NSData. This class assumes the NSData is non mutable to avoid a copy.
15 class RefCountedNSDataMemory : public base::RefCountedMemory { 17 class RefCountedNSDataMemory : public base::RefCountedMemory {
16 public: 18 public:
17 explicit RefCountedNSDataMemory(NSData* memory) : data_([memory retain]) {} 19 explicit RefCountedNSDataMemory(NSData* memory) : data_([memory retain]) {}
18 20
19 const unsigned char* front() const override { 21 const unsigned char* front() const override {
20 return reinterpret_cast<const unsigned char*>([data_ bytes]); 22 return reinterpret_cast<const unsigned char*>([data_ bytes]);
(...skipping 17 matching lines...) Expand all
38 return scoped_refptr<RefCountedNSDataMemory>(new RefCountedNSDataMemory( 40 return scoped_refptr<RefCountedNSDataMemory>(new RefCountedNSDataMemory(
39 [NSKeyedArchiver archivedDataWithRootObject:image.ToUIImage()])); 41 [NSKeyedArchiver archivedDataWithRootObject:image.ToUIImage()]));
40 } 42 }
41 43
42 // Decodes the UIImage in the bytes and returns a gfx::Image. 44 // Decodes the UIImage in the bytes and returns a gfx::Image.
43 gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& data) { 45 gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& data) {
44 return gfx::Image([[NSKeyedUnarchiver unarchiveObjectWithData: 46 return gfx::Image([[NSKeyedUnarchiver unarchiveObjectWithData:
45 [NSData dataWithBytes:data->front() length:data->size()]] retain]); 47 [NSData dataWithBytes:data->front() length:data->size()]] retain]);
46 } 48 }
47 49
50 SkColor DominantColorForImage(const gfx::Image& image) {
51 return color_utils::CalculateKMeanColorOfBitmap(*image.ToSkBitmap());
52 }
53
48 } // namespace enhanced_bookmarks 54 } // namespace enhanced_bookmarks
OLDNEW
« no previous file with comments | « components/enhanced_bookmarks/image_store_util.cc ('k') | components/enhanced_bookmarks/persistent_image_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698