Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / utility / importer / favicon_reencode.cc
blobf20555b0861af2c40d210df18411376c99b2a993
1 // Copyright 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 "chrome/utility/importer/favicon_reencode.h"
7 #include "content/public/child/image_decoder_utils.h"
8 #include "skia/ext/image_operations.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "ui/gfx/codec/png_codec.h"
11 #include "ui/gfx/favicon_size.h"
12 #include "ui/gfx/geometry/size.h"
14 namespace importer {
16 bool ReencodeFavicon(const unsigned char* src_data,
17 size_t src_len,
18 std::vector<unsigned char>* png_data) {
19 // Decode the favicon using WebKit's image decoder.
20 SkBitmap decoded = content::DecodeImage(
21 src_data,
22 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize),
23 src_len);
24 if (decoded.empty())
25 return false; // Unable to decode.
27 if (decoded.width() != gfx::kFaviconSize ||
28 decoded.height() != gfx::kFaviconSize) {
29 // The bitmap is not the correct size, re-sample.
30 int new_width = decoded.width();
31 int new_height = decoded.height();
32 gfx::CalculateFaviconTargetSize(&new_width, &new_height);
33 decoded = skia::ImageOperations::Resize(
34 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height);
37 // Encode our bitmap as a PNG.
38 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data);
39 return true;
42 } // namespace importer