diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 0d8e35e7e0..658480e5ff 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -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(out), width, height))); + delete[] out; + } + return true; } #endif diff --git a/tests/graphics/bitmap.cpp b/tests/graphics/bitmap.cpp index ef2127067a..432f45cd95 100644 --- a/tests/graphics/bitmap.cpp +++ b/tests/graphics/bitmap.cpp @@ -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]")