[email protected] | 174a621 | 2014-05-11 14:19:52 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_UTIL_H_ |
| 6 | #define COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_UTIL_H_ |
| 7 | |
| 8 | #include "base/memory/ref_counted_memory.h" |
lpromero | a110f52 | 2015-01-23 20:17:36 | [diff] [blame] | 9 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 174a621 | 2014-05-11 14:19:52 | [diff] [blame] | 10 | #include "ui/gfx/geometry/size.h" |
| 11 | #include "ui/gfx/image/image.h" |
| 12 | |
| 13 | namespace enhanced_bookmarks { |
| 14 | // The two methods below archive and unarchive an image to and from a bag of |
| 15 | // bytes. There is no API on gfx::Image capable of doing it while preserving the |
| 16 | // scale of the image. |
| 17 | |
| 18 | // Encode |image| to bytes, that can be decoded using the below |ImageForBytes| |
| 19 | // function. If encoding fails, then returned scoped_refptr has NULL. |
| 20 | scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image); |
| 21 | |
| 22 | // Decode the image bytes encoded by the above |BytesForImage| function and |
| 23 | // returns a gfx::Image. If decoding fails, returns an empty image. |
| 24 | gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& data); |
| 25 | |
lpromero | a110f52 | 2015-01-23 20:17:36 | [diff] [blame] | 26 | // Returns the dominant color for |image|. This method can be slow on very large |
| 27 | // images. |
| 28 | SkColor DominantColorForImage(const gfx::Image& image); |
[email protected] | 174a621 | 2014-05-11 14:19:52 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | #endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_UTIL_H_ |