Skip to content
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

ColorPalette never setting PaletteFlagsHasAlpha (GDI+ regression) #702

Open
HinTak opened this issue Apr 12, 2021 · 2 comments
Open

ColorPalette never setting PaletteFlagsHasAlpha (GDI+ regression) #702

HinTak opened this issue Apr 12, 2021 · 2 comments

Comments

@HinTak
Copy link

HinTak commented Apr 12, 2021

( 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:

Robmaister/SharpFont#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:

libgdiplus/src/bitmap.c

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

@HinTak
Copy link
Author

HinTak commented Apr 12, 2021

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

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

@lukadt
Copy link

lukadt commented Jan 22, 2024

Are there any updates on this open issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants