mono / libgdiplus

C-based implementation of the GDI+ API
http://www.mono-project.com/
MIT License
329 stars 171 forks source link

ColorPalette never setting PaletteFlagsHasAlpha (GDI+ regression) #702

Open HinTak opened 3 years ago

HinTak commented 3 years ago

( Copying from https://bugzilla.xamarin.com/show_bug.cgi?id=37608 / https://xamarin.github.io/bugzilla-archives/37/37608/bug.html )

Robert Rouhani 2016-01-12 11:35:41 UTC Created attachment 14551 [details] Screenshot of the bug in Ubuntu

I'm the developer of SharpFont and a user came to me with an issue that only existed when running my example program on Linux with Mono. That issue is available here:

https://github.com/Robmaister/SharpFont/issues/55

Essentially, on Linux, neither of us were seeing the same bitmap transparency that we did on Windows with GDI+.

I did a little more digging and found that gdip_convert_indexed_to_rgb sets all the alpha values to 0xFF if the bitmap's ColorPalette didn't have the PaletteFlagsHasAlpha flag set in this bit of code:

https://github.com/mono/libgdiplus/blob/79ae6cdb90163ba5eb601f8691ea9b7558d25371/src/bitmap.c#L2347-L2353

So the solution was to set the flag manually with reflection as so:

typeof(ColorPalette).GetField ("flags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue (palette, palette.Flags | 1);

And this temporarily fixed the issue. Taking a peek at the same code on Windows/GDI+, the Bitmap gives you a ColorPalette of 0x04 (PaletteFlagsHalftone) and this seems to be enough to convert with transparency. Note that this is all on a Bitmap created with PixelFormat.8bppIndexed.

Since I can only attach a single file, I chose a screenshot of the bug in Ubuntu. This bug should be reproducible by cloning SharpFont and running the example program, but please let me know if you need anything else to reproduce the bug or clarify anything.

Thanks, Robert

HinTak commented 3 years ago

It appears the workaround within mono has bit-rotten from corefx merge, and needed updating https://github.com/Robmaister/SharpFont/pull/136 , so the problem is still current.

Previous discussion at https://github.com/Robmaister/SharpFont/issues/55, and of course, https://bugzilla.xamarin.com/show_bug.cgi?id=37608 .

lukadt commented 5 months ago

Are there any updates on this open issue ?