Skip to content

Commit 8dce1f1

Browse files
HeikoKlarefedejeanne
authored andcommitted
[Win32] Improve decorations/shell images size selection
The algorithm to identify the best fitting image set to a decorations/shell instance for a specific size required by the OS currently only considers the difference between the target size and the actual size of the image. Smaller and larger images with the same difference are treated equally. However, usually one wants to prefer downscaling a higher-resolution image than upscaling a lower-resolution one to improve the quality. This change ensures that larger images are preferred over smaller images if the difference is 1.5 times as high or less. One particular change is that on a 150% monitor now a 200% image will be downscaled instead of upscaling a 100% image.
1 parent 9164303 commit 8dce1f1

File tree

1 file changed

+16
-6
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+16
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,22 @@ private static int findIndexOfClosest(ImageData[] imageData, int targetWidth, in
945945
}
946946

947947
private static boolean isCloserThan(ImageData dataToTest, ImageData referenceData, int targetWidth, int targetDepth) {
948-
int diffWidthToTest = Math.abs(dataToTest.width - targetWidth);
949-
int diffReferenceWidth = Math.abs(referenceData.width - targetWidth);
950-
951-
// The closer the width the better
952-
if (diffWidthToTest != diffReferenceWidth)
953-
return diffWidthToTest < diffReferenceWidth;
948+
// image is considered best-sized if width is nearest to target
949+
// but scale down is better than scale up, thus count difference to target width
950+
// of scaled-up image as 1.5 times
951+
int widthDifferenceOfTestData = dataToTest.width - targetWidth;
952+
if (widthDifferenceOfTestData < 0) {
953+
widthDifferenceOfTestData *= -1.5;
954+
}
955+
int widthDifferenceOfReferenceData = referenceData.width - targetWidth;
956+
if (widthDifferenceOfReferenceData < 0) {
957+
widthDifferenceOfReferenceData *= -1.5;
958+
}
959+
if (widthDifferenceOfTestData < widthDifferenceOfReferenceData) {
960+
return true;
961+
} else if (widthDifferenceOfTestData > widthDifferenceOfReferenceData) {
962+
return false;
963+
}
954964

955965
int transparencyToTest = dataToTest.getTransparencyType();
956966
int referenceTransparency = referenceData.getTransparencyType();

0 commit comments

Comments
 (0)