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

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: Created 4 years, 10 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: 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..7c91f61029d6fd73a17d43bb16faa225687914af 100644
--- a/components/user_manager/user_image/user_image.cc
+++ b/components/user_manager/user_image/user_image.cc
@@ -15,29 +15,34 @@ 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
+UserImage::Bytes UserImage::Encode(const SkBitmap& bitmap) {
+ TRACE_EVENT2("oobe", "Encode",
hashimoto 2016/03/02 07:33:58 nit: s/Encode/UserImage::Encode/ might be more hel
satorux1 2016/03/02 08:23:51 Done.
+ "width", bitmap.width(), "height", bitmap.height());
+ SkAutoLockPixels lock_bitmap(bitmap);
+ Bytes output;
+ 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)) {
+ return output;
hashimoto 2016/03/02 07:33:58 This line may enjoy NRVO or implicit move so there
satorux1 2016/03/02 08:23:51 Good point. Changed it to scoped_ptr<Bytes>
+ } else {
+ return UserImage::Bytes();
+ }
+}
+
+// static
UserImage UserImage::CreateAndEncode(const gfx::ImageSkia& image) {
- Bytes image_bytes;
- if (EncodeImageSkia(image, &image_bytes)) {
+ if (image.isNull())
+ return UserImage(image);
hashimoto 2016/03/02 07:33:58 Just UserImage()?
satorux1 2016/03/02 08:23:51 Done.
+
+ Bytes image_bytes = Encode(*image.bitmap());
+ if (!image_bytes.empty()) {
UserImage result(image, image_bytes);
result.MarkAsSafe();
return result;

Powered by Google App Engine
This is Rietveld 408576698