| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/importer.h" | 5 #include "chrome/browser/importer/importer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/importer/importer_bridge.h" | 7 #include "chrome/browser/importer/importer_bridge.h" |
| 8 #include "chrome/browser/importer/importer_data_types.h" | 8 #include "chrome/browser/importer/importer_data_types.h" |
| 9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 Importer::~Importer() { | 25 Importer::~Importer() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 bool Importer::ReencodeFavicon(const unsigned char* src_data, | 29 bool Importer::ReencodeFavicon(const unsigned char* src_data, |
| 30 size_t src_len, | 30 size_t src_len, |
| 31 std::vector<unsigned char>* png_data) { | 31 std::vector<unsigned char>* png_data) { |
| 32 // Decode the favicon using WebKit's image decoder. | 32 // Decode the favicon using WebKit's image decoder. |
| 33 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); | 33 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); |
| 34 SkBitmap decoded = decoder.Decode(src_data, src_len); | 34 SkBitmap decoded = decoder.Decode(src_data, src_len); |
| 35 if (decoded.empty()) | 35 if (decoded.empty()) |
| 36 return false; // Unable to decode. | 36 return false; // Unable to decode. |
| 37 | 37 |
| 38 if (decoded.width() != kFavIconSize || decoded.height() != kFavIconSize) { | 38 if (decoded.width() != kFaviconSize || decoded.height() != kFaviconSize) { |
| 39 // The bitmap is not the correct size, re-sample. | 39 // The bitmap is not the correct size, re-sample. |
| 40 int new_width = decoded.width(); | 40 int new_width = decoded.width(); |
| 41 int new_height = decoded.height(); | 41 int new_height = decoded.height(); |
| 42 calc_favicon_target_size(&new_width, &new_height); | 42 calc_favicon_target_size(&new_width, &new_height); |
| 43 decoded = skia::ImageOperations::Resize( | 43 decoded = skia::ImageOperations::Resize( |
| 44 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); | 44 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Encode our bitmap as a PNG. | 47 // Encode our bitmap as a PNG. |
| 48 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); | 48 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| OLD | NEW |