Transparency Issue with MultipassBitmap in GeUserArea
-
Hello,
I'm encountering an issue with transparency when drawing a MultipassBitmap over a background in a custom GeUserArea. The transparent areas appear black unless I save the bitmap before drawing it.
Code Snippet:
// ARGBfbuf is a Float32 image buffer with ARGB data // w = width, h = height auto Bmp = MultipassBitmap::Alloc(w, h, COLORMODE::ARGBf); if (!Bmp) { // Handle allocation failure return; } Bmp->SetColorProfile(ColorProfile::GetDefaultSRGB()); // Set parameters for the MultipassBitmap Bmp->SetParameter(MPBTYPE_NAME, "bitmap"); Bmp->SetParameter(MPBTYPE_SAVE, FALSE); Bmp->SetParameter(MPBTYPE_SHOW, TRUE); // Add root alpha channel to the MultipassBitmap auto rootAlpha = Bmp->AddAlpha(nullptr, COLORMODE::GRAYf); if (!rootAlpha) { // Handle error return; } // Set parameters for the root alpha rootAlpha->SetParameter(MPBTYPE_NAME, "rootAlpha"); rootAlpha->SetParameter(MPBTYPE_SAVE, FALSE); rootAlpha->SetParameter(MPBTYPE_SHOW, TRUE); auto layer = Bmp->GetLayerNum(0); if (!layer) { // Handle error return; } // Set parameters for the layer layer->SetParameter(MPBTYPE_NAME, "layer0"); layer->SetParameter(MPBTYPE_SAVE, FALSE); layer->SetParameter(MPBTYPE_SHOW, TRUE); // Add alpha channel to the layer auto alpha = layer->AddAlpha(nullptr, COLORMODE::GRAYf); if (!alpha) { // Handle error return; } // Set parameters for the alpha layer alpha->SetParameter(MPBTYPE_NAME, "alpha0"); alpha->SetParameter(MPBTYPE_SAVE, FALSE); alpha->SetParameter(MPBTYPE_SHOW, TRUE); for (Int32 y = 0; y < h; ++y) { Float32* ptr = ARGBfbuf + (y * w * 4); // Copy image line to the layer layer->SetPixelCnt(0, y, w, reinterpret_cast<UChar*>(ptr), COLORBYTES_ARGBf, COLORMODE::ARGBf, PIXELCNT_0); // Copy alpha line to the alpha layer alpha->SetPixelCnt(0, y, w, reinterpret_cast<UChar*>(ptr), COLORBYTES_ARGBf, COLORMODE::GRAYf, PIXELCNT_0); } // In the GeUserArea render function: // Draw background image DrawBitmap(Background, 0, 0, GetWidth(), GetHeight(), 0, 0, Background->GetBw(), Background->GetBh(), BMP_NORMAL); // Draw bitmap with transparency DrawBitmap(Bmp, 0, 0, GetWidth(), GetHeight(), 0, 0, Bmp->GetBw(), Bmp->GetBh(), BMP_NORMAL | BMP_APPLY_COLORPROFILE | BMP_TRANSPARENTALPHA);
Issue:
Transparent areas (where alpha = 0.0f) appear black instead of showing the background.
Workaround:Saving the bitmap before drawing fixes the issue:
// Save and delete the file String path = GeGetStartupWritePath() + "/temp.tga"; Bmp->Save(path, FILTER_TGA, nullptr, SAVEBIT_ALPHA); GeFKill(path); // Then draw as before DrawBitmap(Bmp, ...);
Additional Information:
- I tried using BaseBitmap instead of MultipassBitmap, but BaseBitmap does not support floating-point color modes (COLORMODE::ARGBf), which I need for my application.
- Even when using BaseBitmap and saving the image, the transparency issue persists.
Questions:
- Why does saving the MultipassBitmap make the transparency work?
- How can I achieve proper transparency without saving the bitmap?
- Is there a way to handle floating-point ARGB data with transparency using BaseBitmap, or is MultipassBitmap the only option?
- Do the SetParameter calls on the Bmp, Layer, root alpha, and alpha layers have any effect on this issue, and am I using them correctly?
Any insights or solutions would be greatly appreciated!