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. 4 5 #include "content/child/image_decoder.h" 6 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" 12 13 using WebKit::WebData; 14 using WebKit::WebImage; 15 16 namespace content { 17 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); 23 } 24 25 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) { 26 } 27 28 ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size) 29 : desired_icon_size_(desired_icon_size) { 30 } 31 32 ImageDecoder::~ImageDecoder() { 33 } 34 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(); 39 } 40 41 // static 42 std::vector<SkBitmap> ImageDecoder::DecodeAll( 43 const unsigned char* data, size_t size) { 44 const WebKit::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; 50 } 51 52 } // namespace content 53