-
Notifications
You must be signed in to change notification settings - Fork 187
[Win32] Improve decorations/shell images size selection #2468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Win32] Improve decorations/shell images size selection #2468
Conversation
Test Results 539 files - 7 539 suites - 7 33m 29s ⏱️ + 1m 57s For more details on these errors, see this check. Results for commit c61529c. ± Comparison against base commit f6de513. This pull request removes 54 tests.♻️ This comment has been updated with latest results. |
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.
9f08c6b to
c61529c
Compare
ShahzaibIbrahim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested your changes with following snippet, where I created two images (1. 40x40, 2. 60x60) and targeted the width of 50. So your method should naturally prefer downscaling high-resolution shell images over upscaling smaller ones.
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class ImageComparisonTest {
// The isCloserThan method, updated as per your selection
private static boolean isCloserThan(ImageData dataToTest, ImageData referenceData, int targetWidth, int targetDepth) {
// image is considered best-sized if width is nearest to target
// but scale down is better than scale up, thus count difference to target width
// of scaled-up image as 1.5 times
int widthDifferenceOfTestData = dataToTest.width - targetWidth;
if (widthDifferenceOfTestData < 0) {
widthDifferenceOfTestData *= -1.5;
}
int widthDifferenceOfReferenceData = referenceData.width - targetWidth;
if (widthDifferenceOfReferenceData < 0) {
widthDifferenceOfReferenceData *= -1.5;
}
if (widthDifferenceOfTestData < widthDifferenceOfReferenceData) {
return true;
} else if (widthDifferenceOfTestData > widthDifferenceOfReferenceData) {
return false;
}
// If widths are equally close, fallback to something else (e.g., transparency)
return false;
}
public static void main(String[] args) {
System.setProperty("swt.autoScale.updateOnRuntime", "true");
Display display = new Display();
// Create two test images in memory
Image img1 = new Image(display, 40, 40); // Will need to scale up to reach target of 50
Image img2 = new Image(display, 60, 60); // Will need to scale down to reach target of 50
ImageData data1 = img1.getImageData();
ImageData data2 = img2.getImageData();
int targetWidth = 50;
int targetDepth = 32; // Not used in this particular logic, but included for completeness
boolean result = isCloserThan(data1, data2, targetWidth, targetDepth);
System.out.println("Is img1 (" + data1.width + "px) closer to target (" + targetWidth +
"px) than img2 (" + data2.width + "px)? " + result);
img1.dispose();
img2.dispose();
display.dispose();
}
}
Result
Is img1 (40px) closer to target (50px) than img2 (60px)? false
Before it would be return the value based on transparencyToTest since the difference to target for both image would be same i.e. 10 == 10
|
Test failure was unrelated: #2098 |
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.