diff options
author | satorux <satorux@chromium.org> | 2016-03-10 21:13:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-11 05:14:44 +0000 |
commit | 5820ae933247dc363ba3ae51220acd64ba3488b0 (patch) | |
tree | f8030a8e614e48293b59e3fd0d96aaf851fc18ad /components/user_manager/user_image/user_image.cc | |
parent | dbdf20c9eec45a535156daf94b94db89ace868f5 (diff) | |
download | chromium_src-5820ae933247dc363ba3ae51220acd64ba3488b0.zip chromium_src-5820ae933247dc363ba3ae51220acd64ba3488b0.tar.gz chromium_src-5820ae933247dc363ba3ae51220acd64ba3488b0.tar.bz2 |
Crop the user-specified profile image for WebUI
This patch fixes a bug where the user-specified profile image
wasn't cropped for WebUI thus the image was displayed weirdly
in the lock screen and the settings.
The root cause of the problem was that the original image data
bytes (not cropped, and can be big) were used for WebUI.
Along the way, get rid of UserImage.RecodedJpegSize UMA
because it's not defined in tools/metrics/histograms/histograms.xml
BUG=590630
TEST=follow steps in the bug
Review URL: https://codereview.chromium.org/1748423005
Cr-Commit-Position: refs/heads/master@{#380512}
Diffstat (limited to 'components/user_manager/user_image/user_image.cc')
-rw-r--r-- | components/user_manager/user_image/user_image.cc | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/components/user_manager/user_image/user_image.cc b/components/user_manager/user_image/user_image.cc index af37983..10cd448 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; } |