From: Christophe CURIS <christophe.cu...@free.fr>

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 <christophe.cu...@free.fr>
---
 WINGs/wpixmap.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/WINGs/wpixmap.c b/WINGs/wpixmap.c
index d5800a4..272e56a 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;
-
-               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);
+               int new_width, new_height;
+               RImage *new_image;
+
+               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);
-- 
1.9.1


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to