OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/importer/reencode_favicon.h" | 5 #include "chrome/utility/importer/favicon_reencode.h" |
6 | 6 |
7 #include "content/public/child/image_decoder_utils.h" | 7 #include "content/public/child/image_decoder_utils.h" |
8 #include "skia/ext/image_operations.h" | 8 #include "skia/ext/image_operations.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "ui/gfx/codec/png_codec.h" | 10 #include "ui/gfx/codec/png_codec.h" |
11 #include "ui/gfx/favicon_size.h" | 11 #include "ui/gfx/favicon_size.h" |
12 #include "ui/gfx/size.h" | |
13 | 12 |
14 bool ReencodeFavicon(const uint8* src_data, | 13 namespace importer { |
| 14 |
| 15 bool ReencodeFavicon(const unsigned char* src_data, |
15 size_t src_len, | 16 size_t src_len, |
16 std::vector<uint8>* png_data) { | 17 std::vector<unsigned char>* png_data) { |
17 // Decode the favicon using WebKit's image decoder. | 18 // Decode the favicon using WebKit's image decoder. |
18 SkBitmap decoded = content::DecodeImage( | 19 SkBitmap decoded = content::DecodeImage( |
19 src_data, | 20 src_data, |
20 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), | 21 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
21 src_len); | 22 src_len); |
22 if (decoded.empty()) | 23 if (decoded.empty()) |
23 return false; // Unable to decode. | 24 return false; // Unable to decode. |
24 | 25 |
25 if (decoded.width() != gfx::kFaviconSize || | 26 if (decoded.width() != gfx::kFaviconSize || |
26 decoded.height() != gfx::kFaviconSize) { | 27 decoded.height() != gfx::kFaviconSize) { |
27 // The bitmap is not the correct size, re-sample. | 28 // The bitmap is not the correct size, re-sample. |
28 int new_width = decoded.width(); | 29 int new_width = decoded.width(); |
29 int new_height = decoded.height(); | 30 int new_height = decoded.height(); |
30 gfx::CalculateFaviconTargetSize(&new_width, &new_height); | 31 gfx::CalculateFaviconTargetSize(&new_width, &new_height); |
31 decoded = skia::ImageOperations::Resize( | 32 decoded = skia::ImageOperations::Resize( |
32 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); | 33 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); |
33 } | 34 } |
34 | 35 |
35 // Encode our bitmap as a PNG. | 36 // Encode our bitmap as a PNG. |
36 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); | 37 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); |
37 return true; | 38 return true; |
38 } | 39 } |
| 40 |
| 41 } // namespace importer |
OLD | NEW |