1// Copyright (c) 2006-2009 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 "webkit/glue/image_decoder.h"
6
7#include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h"
8#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
9#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
10#include "third_party/skia/include/core/SkBitmap.h"
11
12#if WEBKIT_USING_CG
13#include "skia/ext/skia_utils_mac.h"
14#endif
15
16using WebKit::WebData;
17using WebKit::WebImage;
18
19namespace webkit_glue {
20
21ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) {
22}
23
24ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size)
25    : desired_icon_size_(desired_icon_size) {
26}
27
28ImageDecoder::~ImageDecoder() {
29}
30
31SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const {
32  const WebImage& image = WebImage::fromData(
33      WebData(reinterpret_cast<const char*>(data), size), desired_icon_size_);
34#if WEBKIT_USING_SKIA
35  return image.getSkBitmap();
36#elif WEBKIT_USING_CG
37  return gfx::CGImageToSkBitmap(image.getCGImageRef());
38#endif
39}
40
41}  // namespace webkit_glue
42