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

Unified Diff: chrome/utility/importer/favicon_reencode.cc

Issue 18501013: Move most importer code to chrome/utility/importer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CanImport Created 7 years, 5 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/utility/importer/favicon_reencode.cc
diff --git a/chrome/utility/importer/favicon_reencode.cc b/chrome/utility/importer/favicon_reencode.cc
new file mode 100644
index 0000000000000000000000000000000000000000..37439370949dbd833c9d7932461962a838d8b544
--- /dev/null
+++ b/chrome/utility/importer/favicon_reencode.cc
@@ -0,0 +1,41 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/utility/importer/favicon_reencode.h"
+
+#include "content/public/child/image_decoder_utils.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"
gab 2013/07/10 13:40:44 Need to add DEPS on ui/gfx and third_party/skia
+
+namespace importer {
+
+bool ReencodeFavicon(const unsigned char* src_data,
+ size_t src_len,
+ std::vector<unsigned char>* png_data) {
+ // Decode the favicon using WebKit's image decoder.
+ SkBitmap decoded = content::DecodeImage(
+ src_data,
+ gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize),
+ 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;
+}
+
+} // namespace importer

Powered by Google App Engine
This is Rietveld 408576698