summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoaquim Rocha <jrocha@endlessm.com>2017-11-10 18:06:28 +0100
committerRichard Hughes <richard@hughsie.com>2017-11-10 20:23:18 +0000
commit97402f4dce6e7c0a2e803521550e095cda4f5fb5 (patch)
treef7d6f32e5cd78c17b6faa2872dafb9a5bc361cdc
parent4dc16610ff41396391be4d8027f3d823af6621f0 (diff)
downloadappstream-glib-97402f4dce6e7c0a2e803521550e095cda4f5fb5.tar.gz
Fix the arithmetic when fitting an image in 16:9
When saving a 16:9 pixbuf and the image parameter is not 16:9 we create a transparent pixbuf with this ratio and fit the image in it. However, this calculation was not correctly done due to an integer division so the result is that the width/height of the pixbuf's area to be copied was bigger than what the dimensions of the pixbuf; so no image was copied and we'd be left with a trasnparent pixbuf. This patch fixes this problem by using multiplications instead of a division in the mentioned code (as they avoid imprecision problems).
-rw-r--r--libappstream-glib/as-image.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c
index 55067e5..f62aef5 100644
--- a/libappstream-glib/as-image.c
+++ b/libappstream-glib/as-image.c
@@ -766,7 +766,9 @@ as_image_save_pixbuf (AsImage *image,
(gint) width,
(gint) height);
gdk_pixbuf_fill (pixbuf, 0x00000000);
- if ((pixbuf_width / 16) * 9 > pixbuf_height) {
+ /* check the ratio to see which property needs to be fitted and which needs
+ * to be reduced */
+ if (pixbuf_width * 9 > pixbuf_height * 16) {
tmp_width = width;
tmp_height = width * pixbuf_height / pixbuf_width;
} else {