Roll src/third_party/WebKit bbcd5f6:83d0ae8 (svn 201827:201828)
[chromium-blink-merge.git] / content / child / image_decoder.cc
blob333395eaeb31fdee3b6a072e07cfced9e52506d9
1 // Copyright (c) 2013 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.
5 #include "content/child/image_decoder.h"
7 #include "content/public/child/image_decoder_utils.h"
8 #include "third_party/WebKit/public/platform/WebData.h"
9 #include "third_party/WebKit/public/platform/WebImage.h"
10 #include "third_party/WebKit/public/platform/WebSize.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
13 using blink::WebData;
14 using blink::WebImage;
16 namespace content {
18 SkBitmap DecodeImage(const unsigned char* data,
19 const gfx::Size& desired_image_size,
20 size_t size) {
21 ImageDecoder decoder(desired_image_size);
22 return decoder.Decode(data, size);
25 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) {
28 ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size)
29 : desired_icon_size_(desired_icon_size) {
32 ImageDecoder::~ImageDecoder() {
35 SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const {
36 const WebImage& image = WebImage::fromData(
37 WebData(reinterpret_cast<const char*>(data), size), desired_icon_size_);
38 return image.getSkBitmap();
41 // static
42 std::vector<SkBitmap> ImageDecoder::DecodeAll(
43 const unsigned char* data, size_t size) {
44 const blink::WebVector<WebImage>& images = WebImage::framesFromData(
45 WebData(reinterpret_cast<const char*>(data), size));
46 std::vector<SkBitmap> result;
47 for (size_t i = 0; i < images.size(); ++i)
48 result.push_back(images[i].getSkBitmap());
49 return result;
52 } // namespace content