Skip to content

texture-cache: Keep aspect ratio for content images

Florian Müllner requested to merge fmuellner/gnome-shell:content-ratio into master

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

Merge request reports