From f5a589180fc5bffea49484f30b8f015d29e1fcd3 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 5 Sep 2019 23:55:11 +0200 Subject: [PATCH] Fix converting wxImage with mask to wxBitmap with alpha channel For wxImage having both mask and alpha channel (it is technically possible), mask cannot be converted to alpha values and in this case resulting wxBitmap will also have both mask and alpha channel. --- src/osx/core/bitmap.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 605548f033..741d41b22b 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -1203,19 +1203,20 @@ wxBitmap::wxBitmap(const wxImage& image, int depth, double scale) bool hasAlpha = false ; wxImage img; - if ( image.HasMask() ) + if ( image.HasMask() && !image.HasAlpha() ) { // takes precedence // Since we already use 32 bpp bitmap here, we can use alpha channel // directly and there is no reason to keep a separate mask. img = image.Copy(); img.InitAlpha(); + + wxASSERT( !img.HasMask() ); } else { img = image; } - wxASSERT( !img.HasMask() ); hasAlpha = img.HasAlpha() ; if ( hasAlpha ) @@ -1258,6 +1259,8 @@ wxBitmap::wxBitmap(const wxImage& image, int depth, double scale) GetBitmapData()->EndRawAccess() ; } + if ( img.HasMask() ) + SetMask(new wxMask(*this, wxColour(img.GetMaskRed(), img.GetMaskGreen(), img.GetMaskBlue()))); } }