From b6ffe90ec4b53122446c9b1ada9e82677e9bfdde Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Wed, 16 Apr 2014 22:59:35 +0200 Subject: [PATCH] WINGs: Changed algorithm to resize a pixmap while keeping aspect ratio The original code would not provide correctly sized images in some cases of ratios on the original image and on the requested size. Signed-off-by: Christophe CURIS --- WINGs/wpixmap.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/WINGs/wpixmap.c b/WINGs/wpixmap.c index d5800a4d..272e56ac 100644 --- a/WINGs/wpixmap.c +++ b/WINGs/wpixmap.c @@ -134,14 +134,23 @@ WMPixmap *WMCreateScaledBlendedPixmapFromFile(WMScreen *scrPtr, const char *file /* scale it if needed to fit in the specified box */ if ((width > 0) && (height > 0) && ((image->width > width) || (image->height > height))) { - RImage *tmp; + int new_width, new_height; + RImage *new_image; - tmp = image; - if (image->width > image->height) - image = RScaleImage(tmp, width, image->height * height / image->width); - else - image = RScaleImage(tmp, image->width * width / image->height, height); - RReleaseImage(tmp); + new_width = image->width; + new_height = image->height; + if (new_width > width) { + new_width = width; + new_height = width * image->height / image->width; + } + if (new_height > height) { + new_width = height * image->width / image->height; + new_height = height; + } + + new_image = RScaleImage(image, new_width, new_height); + RReleaseImage(image); + image = new_image; } RCombineImageWithColor(image, color);