Commit 2f5c8ac1 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS Wallpaper] Fix 'My Image' thumbnail image distortion.

Currently, the thumbnail image for the current wallpaper is distorted
if the wallpaper image is the user's file (not provided by Google).
Instead of resizing the image to a distorted state for the current
wallpaper thumbnail, this CL ensures that the thumbnail image is scaled
properly and center cropped.

Before screenshot--
https://screenshot.googleplex.com/mBZziQFOf3W

After screenshot--
https://screenshot.googleplex.com/OjYfOhyfFSK

Fixed: 985542
Change-Id: Idf698141a7ac6b38e797d9bd91d256ce5ea02db4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1911229
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714729}
parent 05ed69db
......@@ -46,6 +46,21 @@ base::LazySequencedTaskRunner g_non_blocking_task_runner =
base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN));
// Returns an image of |size| that contains as much of |image| as possible
// without distorting the |image|. Unused areas are cropped away.
gfx::ImageSkia ScaleAspectRatioAndCropCenter(const gfx::Size& size,
const gfx::ImageSkia& image) {
float scale = std::min(float{image.width()} / float{size.width()},
float{image.height()} / float{size.height()});
gfx::Size scaled_size = {scale * size.width(), scale * size.height()};
gfx::Rect bounds{{0, 0}, image.size()};
bounds.ClampToCenteredSize(scaled_size);
auto scaled_and_cropped_image = gfx::ImageSkiaOperations::CreateTiledImage(
image, bounds.x(), bounds.y(), bounds.width(), bounds.height());
return gfx::ImageSkiaOperations::CreateResizedImage(
scaled_and_cropped_image, skia::ImageOperations::RESIZE_LANCZOS3, size);
}
} // namespace
const char kCancelWallpaperMessage[] = "Set wallpaper was canceled.";
......@@ -174,8 +189,7 @@ void WallpaperFunctionBase::GenerateThumbnail(
const gfx::Size& size,
scoped_refptr<base::RefCountedBytes>* thumbnail_data_out) {
*thumbnail_data_out = new base::RefCountedBytes();
gfx::ImageSkia thumbnail_image = gfx::ImageSkiaOperations::CreateResizedImage(
image, skia::ImageOperations::RESIZE_LANCZOS3, size);
gfx::JPEGCodec::Encode(*thumbnail_image.bitmap(), 90 /*quality=*/,
&(*thumbnail_data_out)->data());
gfx::JPEGCodec::Encode(
*wallpaper_api_util::ScaleAspectRatioAndCropCenter(size, image).bitmap(),
90 /*quality=*/, &(*thumbnail_data_out)->data());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment