1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-10 10:35:46 +01:00

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 <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-04-16 22:59:35 +02:00
committed by Carlos R. Mafra
parent 36159c614f
commit b6ffe90ec4

View File

@@ -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);