Skip to content

Conversation

@HeikoKlare
Copy link
Contributor

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.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 30, 2025

Test Results

   539 files   -  7     539 suites   - 7   33m 29s ⏱️ + 1m 57s
 4 372 tests  - 54   4 357 ✅  - 52   14 💤  - 3  0 ❌ ±0  1 🔥 +1 
16 696 runs   - 54  16 571 ✅  - 52  124 💤  - 3  0 ❌ ±0  1 🔥 +1 

For more details on these errors, see this check.

Results for commit c61529c. ± Comparison against base commit f6de513.

This pull request removes 54 tests.
AllWin32Tests ImageWin32Tests ‑ testDisposeDrawnImageBeforeRequestingTargetForOtherZoom
AllWin32Tests ImageWin32Tests ‑ testDrawImageAtDifferentZooms(boolean)[1] true
AllWin32Tests ImageWin32Tests ‑ testDrawImageAtDifferentZooms(boolean)[2] false
AllWin32Tests ImageWin32Tests ‑ testImageDataForDifferentFractionalZoomsShouldBeDifferent
AllWin32Tests ImageWin32Tests ‑ testImageShouldHaveDimesionAsPerZoomLevel
AllWin32Tests ImageWin32Tests ‑ testRetrieveImageDataAtDifferentZooms(boolean)[1] true
AllWin32Tests ImageWin32Tests ‑ testRetrieveImageDataAtDifferentZooms(boolean)[2] false
AllWin32Tests TestTreeColumn ‑ test_ColumnOrder
AllWin32Tests Test_org_eclipse_swt_dnd_DND ‑ testByteArrayTransfer
AllWin32Tests Test_org_eclipse_swt_dnd_DND ‑ testFileTransfer
…

♻️ 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.
@HeikoKlare HeikoKlare force-pushed the better-window-icon-calculation branch from 9f08c6b to c61529c Compare September 2, 2025 10:39
@HeikoKlare HeikoKlare marked this pull request as ready for review September 2, 2025 10:54
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim left a 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

@fedejeanne fedejeanne merged commit 8dce1f1 into eclipse-platform:master Sep 12, 2025
15 of 17 checks passed
@fedejeanne fedejeanne deleted the better-window-icon-calculation branch September 12, 2025 08:31
@fedejeanne
Copy link
Member

Test failure was unrelated: #2098

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer downscaling high-resolution shell images over upscaling smaller ones

3 participants