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.
This commit is contained in:
Artur Wieczorek
2019-09-05 23:55:11 +02:00
parent c12b0e8509
commit f5a589180f

View File

@@ -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())));
}
}