| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |