1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-13 20:35:54 +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 */ /* scale it if needed to fit in the specified box */
if ((width > 0) && (height > 0) && ((image->width > width) || (image->height > height))) { if ((width > 0) && (height > 0) && ((image->width > width) || (image->height > height))) {
RImage *tmp; int new_width, new_height;
RImage *new_image;
tmp = image; new_width = image->width;
if (image->width > image->height) new_height = image->height;
image = RScaleImage(tmp, width, image->height * height / image->width); if (new_width > width) {
else new_width = width;
image = RScaleImage(tmp, image->width * width / image->height, height); new_height = width * image->height / image->width;
RReleaseImage(tmp); }
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); RCombineImageWithColor(image, color);