summaryrefslogtreecommitdiffstats
path: root/content/child/image_decoder.cc
blob: 333395eaeb31fdee3b6a072e07cfced9e52506d9 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2013 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 "content/child/image_decoder.h"

#include "content/public/child/image_decoder_utils.h"
#include "third_party/WebKit/public/platform/WebData.h"
#include "third_party/WebKit/public/platform/WebImage.h"
#include "third_party/WebKit/public/platform/WebSize.h"
#include "third_party/skia/include/core/SkBitmap.h"

using blink::WebData;
using blink::WebImage;

namespace content {

SkBitmap DecodeImage(const unsigned char* data,
                     const gfx::Size& desired_image_size,
                     size_t size) {
  ImageDecoder decoder(desired_image_size);
  return decoder.Decode(data, size);
}

ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) {
}

ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size)
    : desired_icon_size_(desired_icon_size) {
}

ImageDecoder::~ImageDecoder() {
}

SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const {
  const WebImage& image = WebImage::fromData(
      WebData(reinterpret_cast<const char*>(data), size), desired_icon_size_);
  return image.getSkBitmap();
}

// static
std::vector<SkBitmap> ImageDecoder::DecodeAll(
      const unsigned char* data, size_t size) {
  const blink::WebVector<WebImage>& images = WebImage::framesFromData(
      WebData(reinterpret_cast<const char*>(data), size));
  std::vector<SkBitmap> result;
  for (size_t i = 0; i < images.size(); ++i)
    result.push_back(images[i].getSkBitmap());
  return result;
}

}  // namespace content