Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Unified Diff: chrome/browser/favicon/favicon_util.cc

Issue 14575004: Extract BookmarksFileImporter from Firefox2Importer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test cleanup Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/favicon/favicon_util.cc
diff --git a/chrome/browser/favicon/favicon_util.cc b/chrome/browser/favicon/favicon_util.cc
index 46b3bd68955f424d4ff3940be18d8cca0914d259..50ff94e505e7d9fa274cee392afe17d31cf26299 100644
--- a/chrome/browser/favicon/favicon_util.cc
+++ b/chrome/browser/favicon/favicon_util.cc
@@ -8,9 +8,13 @@
#include "chrome/browser/history/select_favicon_frames.h"
#include "content/public/browser/render_view_host.h"
#include "googleurl/src/gurl.h"
+#include "skia/ext/image_operations.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image_png_rep.h"
#include "ui/gfx/image/image_skia.h"
+#include "webkit/glue/image_decoder.h"
namespace {
@@ -184,3 +188,29 @@ size_t FaviconUtil::SelectBestFaviconFromBitmaps(
DCHECK_EQ(1u, selected_bitmap_indices.size());
return selected_bitmap_indices[0];
}
+
+// static
+bool FaviconUtil::ReencodeFavicon(const unsigned char* src_data,
+ size_t src_len,
+ std::vector<unsigned char>* png_data) {
+ // Decode the favicon using WebKit's image decoder.
+ webkit_glue::ImageDecoder decoder(
+ gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize));
+ SkBitmap decoded = decoder.Decode(src_data, src_len);
+ if (decoded.empty())
+ return false; // Unable to decode.
+
+ if (decoded.width() != gfx::kFaviconSize ||
+ decoded.height() != gfx::kFaviconSize) {
+ // The bitmap is not the correct size, re-sample.
+ int new_width = decoded.width();
+ int new_height = decoded.height();
+ gfx::CalculateFaviconTargetSize(&new_width, &new_height);
+ decoded = skia::ImageOperations::Resize(
+ decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height);
+ }
+
+ // Encode our bitmap as a PNG.
+ gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data);
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698