From 79be42122f82b36900fe8d99668a843fd31b0967 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 18 Jan 2021 22:29:40 +0100 Subject: [PATCH] Don't convert mask to alpha values while converting wxImage to wxBitmap (wxOSX) wxImage with mask should be converted to wxBitmap with mask and not to wxBitmap with alpha channel values. Converting wxImage mask to wxBitmap alpha is not implemented under wxMSW and wxGTK and wxOSX implementation should adhere to this convention. --- src/osx/core/bitmap.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 8a10cc4f93..a4a0ac70b8 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -1131,10 +1131,9 @@ wxBitmap::wxBitmap(const wxImage& image, int depth, double scale) { bool hasMask = image.HasMask(); bool hasAlpha = image.HasAlpha(); - bool wantsAlpha = hasMask || hasAlpha ; // convert this bitmap to use its alpha channel - if ( wantsAlpha ) + if ( hasAlpha ) UseAlpha(); const unsigned char *sourcePixels = image.GetData(); @@ -1169,22 +1168,15 @@ wxBitmap::wxBitmap(const wxImage& image, int depth, double scale) unsigned char * destinationMask = destinationMaskRowStart; for (int x = 0; x < width; x++) { - bool isMasked = false; - if ( hasMask ) { - if ( sourcePixels[0] == mr && sourcePixels[1] == mg && sourcePixels[2] == mb ) - isMasked = true; + bool isMasked = sourcePixels[0] == mr && sourcePixels[1] == mg && sourcePixels[2] == mb; *destinationMask++ = isMasked ? wxIMAGE_ALPHA_TRANSPARENT : wxIMAGE_ALPHA_OPAQUE ; } - if ( wantsAlpha ) + if ( hasAlpha ) { - unsigned char a; - if ( hasAlpha ) - a = *sourceAlpha++; - else - a = isMasked ? wxIMAGE_ALPHA_TRANSPARENT : wxIMAGE_ALPHA_OPAQUE; + unsigned char a = *sourceAlpha++; *destination++ = a ; #if wxOSX_USE_PREMULTIPLIED_ALPHA