-
Notifications
You must be signed in to change notification settings - Fork 119
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
GC#drawIcon draws *.ico(for some icons) with black background on Windows 10 #185
Comments
@tmssngr :
|
This is reproducible with the latest SWT built from source (v4952r11). With bisecting I've found out that commit 22797d3 Revert "Revert "Bug 493455 - [win32] remove alpha and alphaData from Image"" introduced this bug. |
@jonathan.meier@outlook.com |
I don't see this problem happening in Eclipse. @SyntevoAlex @Phillipus |
I don't have those program icons on my system, so when I run the snippet the program icons I have render OK. @tmssngr Can we get an actual icon to test with? Also, is this Hi DPI? |
Please share a screen grab on how the icon looks for you. |
It seems to be only some Program icons that have this problem. Try running this modified snippet: Modified Snippetimport java.util.List;
import java.util.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.program.*;
import org.eclipse.swt.widgets.*;
public class ProgramImageTest {
public static void main(String[] args) {
final Display display = new Display();
final List<Image> images = createImages(display);
final Shell shell = new Shell(display);
shell.addListener(SWT.Paint, event -> {
int x = 0;
int y = 0;
for(Image image : images) {
event.gc.drawImage(image, x, y);
x += image.getImageData().width;
x += 10;
if(x > 400) {
x = 0;
y += 24;
}
}
});
shell.setSize(400, 300);
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) {
display.sleep();
}
}
for(Image image : images) {
image.dispose();
}
display.dispose();
}
private static List<Image> createImages(Display display) {
final List<Image> images = new ArrayList<>();
for(Program p : Program.getPrograms()) {
final ImageData data = p.getImageData();
if(data == null) {
continue;
}
images.add(new Image(display, data));
}
return images;
}
} |
Just for the records: my 4k monitor (main screen) has 175% scaling, the notebook display (second screen) 125% scaling. |
I tried to narrow it down to loading an icon from file, but couldn't reproduce it other than the icons returned from |
As an experiment I changed line 366 of
to:
And the icons are rendered OK. Might be a clue? |
Yes. I was just looking for a clue. It seems that the problem lies somewhere in the changes that were made as part of https://bugs.eclipse.org/bugs/show_bug.cgi?id=493455 Still seems to be some outstanding/unknown issues with this major change. |
I don't think it's related to HiDPI. I'm seeing it on normal 100% scaling all the time now. See #185 (comment) |
I've isolated the problem to some *.ico files. Nothing to do with Attached is a reproducible snippet and icon file. Here's how it should look running on Eclipse 4.23: Here's how it looks on Eclipse 4.24: |
GC#drawImage |
Thanks Phil for investigating and narrowing down the issue! |
The problem is here eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java Lines 1800 to 1803 in 6f2f07c
In commit 22797d3 I changed this from
enforcing that any alpha data for an image must be provided via the For such icons, retrieving their This becomes a problem for icons that do not use the color black for transparent pixels. Masked pixels colored in black become transparent, whereas masked pixels colored in any other color are XORed with their background color by GDI, which means that a masked pixel colored in white inverts its background color. This is exactly what happens in all examples provided above, where the white background is inverted to black by masked pixels colored in white. It happens only with a few icons, since most icons use the color black for transparent pixels. Using the following method, you can color all masked pixels black to work around this issue:
This still does not fix partially transparent pixels which are just drawn fully opaque when discarding the alpha channel, but this is much less visible and icons using partially transparent pixels are less common. I will provide a PR with a fix for this issue as soon as possible. Thanks everyone for providing insights helping debug this issue 👍 |
@jonathan-meier Hi, did you find some time to implement a PR? Happy to test it if required. 👍 |
@jonathan-meier Unfortunately, your |
I really would appreciate it if this obvious regression could be fixed soon. |
@jonathan-meier Hi Jonathan, do you think it is possible to fix this regression? |
Based on above input, I have a working fix for this issue:
|
Windows10 - Fixes eclipse-platform#185 Change-Id: Idec2ddb0086a58c8d28c7616a628e2802d06ce56 Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
@niraj-modi Hi Niraj, thanks for taking a look at this. I tested your patch with the example case in #185 (comment) and I can confirm it seems to fix the problem. |
Windows10 - Fixes #185 Change-Id: Idec2ddb0086a58c8d28c7616a628e2802d06ce56 Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
Thanks for the fix. |
Describe the bug
Please run the attached snippet on Windows 10 (default Windows mode: Dark, default app mode: light). It will get the icons for certain file types and render them. For some reason, the background of the images is rendered in black.
ProgramImageTest.java.txt
To Reproduce
See above.
Expected behavior
The background should be transparent.
Screenshots
Environment:
Windows 10, Version 21H1 (OS Build 19043.1706)
The text was updated successfully, but these errors were encountered: