Ignore undefined all-zero alpha data for 32-bit icons without mask#2986
Ignore undefined all-zero alpha data for 32-bit icons without mask#2986HeikoKlare merged 1 commit intoeclipse-platform:masterfrom
Conversation
|
Drafted because I need suggestion here in the case where, what if the image was made completely transparent by choice? Meaning user define the image to be completely transparent (all 0 alpha pixels). Is this a viable/possible case here? Or that this fix is enough? as we can't know for sure if GetDIBits() is returning 0 as un-defined alpha-byte or was it really 0. Documentation for GetDIBits -> https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibits#return-value |
|
Changes look good to me. I have tested the snippet, and it fixes the problem mentioned in the issue. However, there are some CI failures, which I don’t think are related. @ShahzaibIbrahim, could you please rerun the CI? |
8ff599c to
5b8c337
Compare
5b8c337 to
27d013b
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Turns out that OS.GetDIBits does not guarantee to return alpha data when not having mask data and requesting for 32 bits. Taken a look at all the documentations and asking Copilot, there does not seem to be a proper way to retrieve an alpha-aware image in this way (i.e., with this DPI) at all. It might be that all this special case handling for alpha data could just be removed, but since the original issue that was solved with this can currently not be reproduced, there is no chance to see if we can fix it in any other way and that removing this code that not produce any regression. On the other hand, assuming that empty alpha data is invalid (as the image would be completely transparent otherwise), seems reasonable. Thus I am in favor of merging this.
27d013b to
c2fbe40
Compare
On Windows, GetDIBits() may return undefined alpha bytes for 32-bit BI_RGB bitmaps, commonly resulting in all-zero alpha even for fully opaque images. When icon mask data is missing, this caused opaque icons to be incorrectly treated as fully transparent. Reject all-zero alpha data and only replace empty mask data when the alpha channel contains meaningful (non-opaque, non-zero) values.
c2fbe40 to
cc3b6e7
Compare
I have a png image (icon), which has no maskData and no alpha pixels (that means it is fully opaque):

On Windows, GetDIBits() may return undefined alpha bytes for 32-bit BI_RGB bitmaps, commonly resulting in all-zero alpha even for fully opaque images.
When icon mask data is missing, this caused opaque icons to be incorrectly treated as fully transparent.
Reject all-zero alpha data and only replace empty mask data when the alpha channel contains meaningful (non-opaque, non-zero) values.
How to test
Note: Add the attached image on the same folder as snippet
After fix