blob: ef3979d90902c104cfe03b47aecfde7d71201372 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/enhanced_bookmarks/image_store_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_util.h"
namespace {
const int kJpegEncodingQuality = 70;
} // namespace
namespace enhanced_bookmarks {
scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
DCHECK(image.AsImageSkia().image_reps().size() == 1);
DCHECK(image.AsImageSkia().image_reps().begin()->scale() == 1.0f);
std::vector<unsigned char> data;
bool succeeded =
gfx::JPEG1xEncodedDataFromImage(image, kJpegEncodingQuality, &data);
if (!succeeded)
return scoped_refptr<base::RefCountedMemory>();
return scoped_refptr<base::RefCountedMemory>(new base::RefCountedBytes(data));
}
gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& bytes) {
return gfx::ImageFrom1xJPEGEncodedData(bytes->front(), bytes->size());
}
SkColor DominantColorForImage(const gfx::Image& image) {
return color_utils::CalculateKMeanColorOfBitmap(*image.ToSkBitmap());
}
}
|