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

Unified Diff: components/user_manager/user_image/user_image.cc

Issue 1748423005: Crop the user-specified profile image for WebUI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 9 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
« no previous file with comments | « components/user_manager/user_image/user_image.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/user_manager/user_image/user_image.cc
diff --git a/components/user_manager/user_image/user_image.cc b/components/user_manager/user_image/user_image.cc
index af37983437abbc3b85fd616137dbcd279ebafbb3..10cd4482da504f2d3fae556b02ffe2d350fa0b7e 100644
--- a/components/user_manager/user_image/user_image.cc
+++ b/components/user_manager/user_image/user_image.cc
@@ -15,30 +15,35 @@ namespace {
// Default quality for encoding user images.
const int kDefaultEncodingQuality = 90;
-bool EncodeImageSkia(const gfx::ImageSkia& image,
- UserImage::Bytes* output) {
- TRACE_EVENT2("oobe", "EncodeImageSkia",
- "width", image.width(), "height", image.height());
- if (image.isNull())
- return false;
- const SkBitmap& bitmap = *image.bitmap();
- SkAutoLockPixels lock_image(bitmap);
- return gfx::JPEGCodec::Encode(
- reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
- gfx::JPEGCodec::FORMAT_SkBitmap,
- bitmap.width(),
- bitmap.height(),
- bitmap.width() * bitmap.bytesPerPixel(),
- kDefaultEncodingQuality, output);
-}
-
} // namespace
// static
+scoped_ptr<UserImage::Bytes> UserImage::Encode(const SkBitmap& bitmap) {
+ TRACE_EVENT2("oobe", "UserImage::Encode",
+ "width", bitmap.width(), "height", bitmap.height());
+ SkAutoLockPixels lock_bitmap(bitmap);
+ scoped_ptr<Bytes> output(new Bytes);
+ if (gfx::JPEGCodec::Encode(
+ reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
+ gfx::JPEGCodec::FORMAT_SkBitmap,
+ bitmap.width(),
+ bitmap.height(),
+ bitmap.width() * bitmap.bytesPerPixel(),
+ kDefaultEncodingQuality, output.get())) {
+ return output;
+ } else {
+ return nullptr;
+ }
+}
+
+// static
UserImage UserImage::CreateAndEncode(const gfx::ImageSkia& image) {
- Bytes image_bytes;
- if (EncodeImageSkia(image, &image_bytes)) {
- UserImage result(image, image_bytes);
+ if (image.isNull())
+ return UserImage();
+
+ scoped_ptr<Bytes> image_bytes = Encode(*image.bitmap());
+ if (image_bytes) {
+ UserImage result(image, *image_bytes);
result.MarkAsSafe();
return result;
}
« no previous file with comments | « components/user_manager/user_image/user_image.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698