Chromium Code Reviews| 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; |