Fix converting wxImage with alpha channel and mask to wxBitmap (wxGTK2)
Sincef7247086c2
("Fix storing wxBitmap data in GdkPixbuf", 2019-09-18),919a4ec702
("Fix drawing wxBitmap with mask", 2019-09-18) and other commits (see #18498, #18508) RGBA wxBitmaps with masks are drawn properly under wxGTK2 so if source wxImage has both alpha channel and a mask the target wxBitmap also should have both components.
This commit is contained in:
@@ -756,6 +756,27 @@ bool wxBitmap::CreateFromImageAsPixbuf(const wxImage& image)
|
||||
}
|
||||
}
|
||||
|
||||
if ( image.HasMask() )
|
||||
{
|
||||
const size_t out_size = size_t((width + 7) / 8) * unsigned(height);
|
||||
wxByte* out = new wxByte[out_size];
|
||||
memset(out, 0xff, out_size);
|
||||
const wxByte r_mask = image.GetMaskRed();
|
||||
const wxByte g_mask = image.GetMaskGreen();
|
||||
const wxByte b_mask = image.GetMaskBlue();
|
||||
const wxByte* in = image.GetData();
|
||||
unsigned bit_index = 0;
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++, in += 3, bit_index++)
|
||||
if (in[0] == r_mask && in[1] == g_mask && in[2] == b_mask)
|
||||
out[bit_index >> 3] ^= 1 << (bit_index & 7);
|
||||
bit_index = (bit_index + 7) & ~7u;
|
||||
}
|
||||
SetMask(new wxMask(gdk_bitmap_create_from_data(wxGetTopLevelGDK(), reinterpret_cast<char*>(out), width, height)));
|
||||
delete[] out;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
@@ -557,7 +557,6 @@ TEST_CASE("BitmapTestCase::FromImage", "[bitmap][image][convertfrom]")
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(__WXGTK20__) || defined(__WXGTK3__)
|
||||
SECTION("RGBA image with mask")
|
||||
{
|
||||
wxImage img(2, 2);
|
||||
@@ -619,7 +618,6 @@ TEST_CASE("BitmapTestCase::FromImage", "[bitmap][image][convertfrom]")
|
||||
rowStartMask.OffsetY(dataMask, 1);
|
||||
}
|
||||
}
|
||||
#endif // !defined(__WXGTK20__) || defined(__WXGTK3__)
|
||||
}
|
||||
|
||||
TEST_CASE("BitmapTestCase::OverlappingBlit", "[bitmap][blit]")
|
||||
|
Reference in New Issue
Block a user