-
Notifications
You must be signed in to change notification settings - Fork 174
ColorPalette never setting PaletteFlagsHasAlpha (GDI+ regression) #702
Description
( 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:
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:
Lines 2347 to 2353 in 79ae6cd
| if ((palette->Flags & PaletteFlagsHasAlpha) == 0) { | |
| format = PixelFormat32bppRGB; | |
| set_pixel_bgra (&force_alpha, 0, 0, 0, 0, 0xFF); /* full alpha bits set */ | |
| } else { | |
| format = PixelFormat32bppARGB; | |
| force_alpha = 0; | |
| } |
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