Skip to content

GC#drawIcon draws *.ico(for some icons) with black background on Windows 10 #185

Closed

Description

@tmssngr

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
Screenshot-Win10

Environment:
Windows 10, Version 21H1 (OS Build 19043.1706)

Activity

  1. iloveeclipse commented on Jun 1, 2022

    @iloveeclipse
    Member

    @tmssngr :

    • which Eclipse / SWT version is this?
    • is this a regression? If yes, which version was OK?
  2. tmssngr commented on Jun 1, 2022

    @tmssngr
    ContributorAuthor

    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.

  3. niraj-modi commented on Jun 1, 2022

    @niraj-modi
    Member

    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
    Please have a look.

  4. niraj-modi commented on Jun 1, 2022

    @niraj-modi
    Member

    I don't see this problem happening in Eclipse.

    @SyntevoAlex @Phillipus
    Do you see this problem in any of you Eclipse based applications ?
    We are just trying to understand how severe is this problem.

  5. Phillipus commented on Jun 1, 2022

    @Phillipus
    Contributor

    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?

  6. niraj-modi commented on Jun 1, 2022

    @niraj-modi
    Member

    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.

  7. Phillipus commented on Jun 1, 2022

    @Phillipus
    Contributor

    Please share a screen grab on how the icon looks for you.

    icons

  8. Phillipus commented on Jun 1, 2022

    @Phillipus
    Contributor

    Found it.

    I had to set Windows custom scaling to 200 or run the snippet with the argument -Dswt.autoScale=200

    icons2

  9. changed the title [-]Program.getImageData returns images with black background on Windows 10[/-] [+][HiDPI] Program.getImageData returns images with black background on Windows 10[/+] on Jun 1, 2022
  10. niraj-modi commented on Jun 1, 2022

    @niraj-modi
    Member

    Eclipse at HiDPI is working fine for External Program Icons:
    Eclipse_ExternalProgram_Icons

    So problem seems specific to this test-snippet only.

  11. Phillipus commented on Jun 1, 2022

    @Phillipus
    Contributor

    It seems to be only some Program icons that have this problem.

    Try running this modified snippet:

    Modified Snippet
    import 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;
        }
    }
  12. Phillipus commented on Jun 1, 2022

    @Phillipus
    Contributor

    Strange, now I am able to reproduce this with scaling at 100%:

    icons3

  13. niraj-modi commented on Jun 1, 2022

    @niraj-modi
    Member

    Interestingly problem is seen only with second run onward irrespective of zoom.
    Even got it working with 200% as well:
    Snippet_200Zoom

    Revised steps to reproduce the issue with test-snippet:

    1. Switch the Windows Display zoom 100% to 200%(or visa versa)
    2. Run the test-snippet, it will works on either zoom.
    3. Close it and relaunch, problem is seen.
  14. 14 remaining items

  15. Phillipus commented on Jun 16, 2022

    @Phillipus
    Contributor

    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. 👍

  16. tmssngr commented on Jul 1, 2022

    @tmssngr
    ContributorAuthor

    @jonathan-meier Unfortunately, your maskColor method doesn't resolve the problem for me (Windows 10).

  17. Phillipus commented on Jul 5, 2022

    @Phillipus
    Contributor

    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.

    @tmssngr Do you think if we reverted this, it would solve the regression?

  18. tmssngr commented on Jul 5, 2022

    @tmssngr
    ContributorAuthor

    I've tried reverting e891658, 819a24e, def5c63 and 22797d3, but then it did not compile any more because of a missing hDC in Image. Because I'm not an expert in the internals, I've aborted my tests.

  19. tmssngr commented on Jul 7, 2022

    @tmssngr
    ContributorAuthor

    I really would appreciate it if this obvious regression could be fixed soon.

  20. Phillipus commented on Jul 7, 2022

    @Phillipus
    Contributor

    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?

  21. niraj-modi commented on Jul 7, 2022

    @niraj-modi
    Member

    The problem is here

    case 32:
    newDepth = 24;
    newPalette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
    break;

    In commit 22797d3 I changed this from

    case 32:
    	if (!(redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000)) {
    		newPalette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
    	}
    	break;
    

    Based on above input, I have a working fix for this issue:

    • Will share a PR for testing shortly.
  22. added a commit that references this issue on Jul 7, 2022
    1bf6b79
  23. Phillipus commented on Jul 7, 2022

    @Phillipus
    Contributor

    @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.

  24. added a commit that references this issue on Jul 11, 2022
    8def011
  25. self-assigned this
    on Jul 11, 2022
  26. added this to the 4.25 M2 milestone on Jul 11, 2022
  27. tmssngr commented on Jul 11, 2022

    @tmssngr
    ContributorAuthor

    Thanks for the fix.

  28. added
    fix verifiedThe implemented fix has been verified with an I-build
    on Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

WindowsHappens on Windows OSfix verifiedThe implemented fix has been verified with an I-buildregressionSomething that used to work

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions