• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "components/enhanced_bookmarks/image_store_util.h"
6 
7 #include "ui/gfx/image/image_skia.h"
8 #include "ui/gfx/image/image_util.h"
9 
10 namespace {
11 const int kJpegEncodingQuality = 70;
12 }  // namespace
13 
14 namespace enhanced_bookmarks {
15 
BytesForImage(const gfx::Image & image)16 scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
17   DCHECK(image.AsImageSkia().image_reps().size() == 1);
18   DCHECK(image.AsImageSkia().image_reps().begin()->scale() == 1.0f);
19 
20   std::vector<unsigned char> data;
21   bool succeeded =
22       gfx::JPEG1xEncodedDataFromImage(image, kJpegEncodingQuality, &data);
23 
24   if (!succeeded)
25     return scoped_refptr<base::RefCountedMemory>();
26 
27   return scoped_refptr<base::RefCountedMemory>(new base::RefCountedBytes(data));
28 }
29 
ImageForBytes(const scoped_refptr<base::RefCountedMemory> & bytes)30 gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& bytes) {
31   return gfx::ImageFrom1xJPEGEncodedData(bytes->front(), bytes->size());
32 }
33 }
34