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

Side by Side Diff: chrome/browser/gears_integration.cc

Issue 18347: Add a PNGEncoder helper function that takes an SkBitmap, (Closed)
Patch Set: Test2 Created 11 years, 11 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/fav_icon_helper.cc ('k') | chrome/browser/importer/importer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/gears_integration.h" 5 #include "chrome/browser/gears_integration.h"
6 6
7 #include "base/gfx/png_encoder.h" 7 #include "base/gfx/png_encoder.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 }; 110 };
111 111
112 // Helper function to convert a 16x16 favicon to a data: URL with the icon 112 // Helper function to convert a 16x16 favicon to a data: URL with the icon
113 // encoded as a PNG. 113 // encoded as a PNG.
114 static GURL ConvertSkBitmapToDataURL(const SkBitmap& icon) { 114 static GURL ConvertSkBitmapToDataURL(const SkBitmap& icon) {
115 DCHECK(!icon.isNull()); 115 DCHECK(!icon.isNull());
116 DCHECK(icon.width() == 16 && icon.height() == 16); 116 DCHECK(icon.width() == 16 && icon.height() == 16);
117 117
118 // Get the FavIcon data. 118 // Get the FavIcon data.
119 std::vector<unsigned char> icon_data; 119 std::vector<unsigned char> icon_data;
120 { 120 PNGEncoder::EncodeBGRASkBitmap(icon, false, &icon_data);
121 SkAutoLockPixels icon_lock(icon);
122 PNGEncoder::Encode(static_cast<unsigned char*>(icon.getPixels()),
123 PNGEncoder::FORMAT_BGRA, icon.width(),
124 icon.height(), icon.width()* 4, false,
125 &icon_data);
126 }
127 121
128 // Base64-encode it (to make it a data URL). 122 // Base64-encode it (to make it a data URL).
129 std::string icon_data_str(reinterpret_cast<char*>(&icon_data[0]), 123 std::string icon_data_str(reinterpret_cast<char*>(&icon_data[0]),
130 icon_data.size()); 124 icon_data.size());
131 std::string icon_base64_encoded; 125 std::string icon_base64_encoded;
132 net::Base64Encode(icon_data_str, &icon_base64_encoded); 126 net::Base64Encode(icon_data_str, &icon_base64_encoded);
133 GURL icon_url("data:image/png;base64," + icon_base64_encoded); 127 GURL icon_url("data:image/png;base64," + icon_base64_encoded);
134 128
135 return icon_url; 129 return icon_url;
136 } 130 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 void RunnableMethodTraits<QueryShortcutsCommand>::ReleaseCallee( 305 void RunnableMethodTraits<QueryShortcutsCommand>::ReleaseCallee(
312 QueryShortcutsCommand* remover) { 306 QueryShortcutsCommand* remover) {
313 } 307 }
314 308
315 void GearsQueryShortcuts(GearsQueryShortcutsCallback* callback) { 309 void GearsQueryShortcuts(GearsQueryShortcutsCallback* callback) {
316 CPHandleCommand(GEARSPLUGINCOMMAND_GET_SHORTCUT_LIST, 310 CPHandleCommand(GEARSPLUGINCOMMAND_GET_SHORTCUT_LIST,
317 new QueryShortcutsCommand(callback), 311 new QueryShortcutsCommand(callback),
318 NULL); 312 NULL);
319 } 313 }
320 314
OLDNEW
« no previous file with comments | « chrome/browser/fav_icon_helper.cc ('k') | chrome/browser/importer/importer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698