Skip to content

Conversation

ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Oct 10, 2025

Description

Previously, indexed images that used a transparentPixel (e.g. GIFs) could be implicitly promoted to an 8-bit alpha representation when the image was scaled (for example when switching to a 150% DPI monitor). That meant an image created eagerly at 100% would look correct, but after a zoom/monitor change it would be converted to alpha-based transparency; moving back to 100% then revealed a gray background because the transparency semantics had changed.

This change normalizes indexed images that advertise a transparentPixel during initialization: when no alpha is present we convert the indexed image to a direct 32-bit representation (preserving the mask/transparent semantics) rather than leaving conversion to happen lazily during scaling. By doing this in init(Device, ImageData) the transparency model remains consistent across zoom levels and monitor transitions.

Notes:

  • Images that already contain true alpha (alpha/alphaData) are not changed and continue to be handled as 32-bit ARGB.
  • Direct images (palette.isDirect) are not affected by this change.
  • The Windows mask/icon creation path (TRANSPARENCY_MASK) is preserved.

How to test

  1. Run the following snippet on 100% zoom monitor
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;


public class ButtonWithGifImage {
    public static void main(String[] args) {
    	System.setProperty("swt.autoScale.updateOnRuntime", "true");
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("SWT Button with GIF Image");
        shell.setSize(300, 200);

        Button button = new Button(shell, SWT.PUSH);
        button.setBounds(80, 60, 140, 60);
        button.setText("Click Me");

        Image image = new Image(display,
            ButtonWithGifImage.class.getResourceAsStream("sample.gif"));
        button.setImage(image);

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }

        image.dispose();
        display.dispose();
    }
}

  1. Move the window to a 150% DPI monitor (causing scaling) — verify the image still renders correctly (no jagged/incorrect background).
  2. Move back to 100% — verify the image still renders correctly and no gray background appears.

Result

Here's the preview how it looked before and after this PR change. 100 -> 150 -> 100

Before:
image

After
image

Fixes: #2494

Previously, indexed images (like GIFs) using transparentPixel were
converted to 8-bit alpha during scaling (e.g., when moving between 100%
and 150% DPI), causing gray backgrounds on return to 100%.
Now, such images are converted to direct format with alpha upfront,
ensuring consistent transparency across zoom levels.
@merks
Copy link
Contributor

merks commented Oct 10, 2025

Yeah! 🥳

Copy link
Contributor

Test Results

  108 files   -  7    108 suites   - 7   11m 43s ⏱️ +32s
4 490 tests  - 56  4 476 ✅  - 54  13 💤  - 3  1 ❌ +1 
  255 runs   - 56    255 ✅  - 53   0 💤  - 3  0 ❌ ±0 

For more details on these failures, see this check.

Results for commit 587627a. ± Comparison against base commit 6fa4ee7.

This pull request removes 56 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 ImageWin32Tests ‑ test_getImageData_fromCopiedImage
AllWin32Tests ImageWin32Tests ‑ test_getImageData_fromImageForImageDataFromImage
AllWin32Tests TestTreeColumn ‑ test_ColumnOrder
…

@ShahzaibIbrahim ShahzaibIbrahim marked this pull request as draft October 10, 2025 15:01
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.

Eclipse 2025-06: UI rendering issues on Windows with monitors using different scale factors Gif images sometimes have black backgrounds

2 participants