texture-cache: Keep aspect ratio for content images
Images are loaded either with a supplied fixed size, or using the "native" dimensions of the file. When creating a content image from the loaded data, we currently simply apply this directly to the preferred size. This works usually fine: GdkPixbuf will always keep the aspect ratio, so if only one dimension is provided, the other will be adjusted accordingly: Loading a 200x200 image with a requested size of (100, -1) will result in a 100x100 content image. There is a catch though: GdkPixbuf will only scale *down* to the requested size, no up. That is, loading a 100x100 image with a requested size of (200, -1) will result in a 100x100 pixbuf. But as we assume that the pixbuf size matches the requested size, the image content ends up with 200x100. Fix this by explicitly handling the case where only one size was supplied, and make the other dimension take the aspect ratio into account https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/525
This commit is contained in:
parent
4e6b2eb72a
commit
5520bb3890
@ -496,15 +496,31 @@ pixbuf_to_st_content_image (GdkPixbuf *pixbuf,
|
|||||||
ClutterContent *image;
|
ClutterContent *image;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
if (width < 0)
|
float native_width, native_height;
|
||||||
width = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
|
|
||||||
else
|
|
||||||
width *= paint_scale;
|
|
||||||
|
|
||||||
if (height < 0)
|
native_width = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
|
||||||
height = ceilf (gdk_pixbuf_get_height (pixbuf) / resource_scale);
|
native_height = ceilf (gdk_pixbuf_get_height (pixbuf) / resource_scale);
|
||||||
|
|
||||||
|
if (width < 0 && height < 0)
|
||||||
|
{
|
||||||
|
width = native_width;
|
||||||
|
height = native_height;
|
||||||
|
}
|
||||||
|
else if (width < 0)
|
||||||
|
{
|
||||||
|
height *= paint_scale;
|
||||||
|
width = native_width * (height / native_height);
|
||||||
|
}
|
||||||
|
else if (height < 0)
|
||||||
|
{
|
||||||
|
width *= paint_scale;
|
||||||
|
height = native_height * (width / native_width);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
height *= paint_scale;
|
{
|
||||||
|
width *= paint_scale;
|
||||||
|
height *= paint_scale;
|
||||||
|
}
|
||||||
|
|
||||||
image = st_image_content_new_with_preferred_size (width, height);
|
image = st_image_content_new_with_preferred_size (width, height);
|
||||||
clutter_image_set_data (CLUTTER_IMAGE (image),
|
clutter_image_set_data (CLUTTER_IMAGE (image),
|
||||||
|
Loading…
Reference in New Issue
Block a user