Don't consider fully opaque bitmaps as having alpha in wxMSW.
Remove the alpha channel from the DIB we create not only if all of its pixels are fully transparent but also if they are all fully opaque. This prevents us from erroneously creating bitmaps with alpha channel when none is needed nor expected. Closes #13056. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67287 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -760,7 +760,14 @@ wxImage wxDIB::ConvertToImage() const
|
||||
}
|
||||
|
||||
const int bpp = GetDepth();
|
||||
|
||||
// Remember if we have any "real" transparency, i.e. either any partially
|
||||
// transparent pixels or not all pixels are fully opaque or fully
|
||||
// transparent.
|
||||
bool hasAlpha = false;
|
||||
bool hasOpaque = false;
|
||||
bool hasTransparent = false;
|
||||
|
||||
if ( bpp == 32 )
|
||||
{
|
||||
// 32 bit bitmaps may be either 0RGB or ARGB and we don't know in
|
||||
@@ -793,13 +800,30 @@ wxImage wxDIB::ConvertToImage() const
|
||||
// premultiplication done in Create() above
|
||||
const unsigned char a = *src;
|
||||
*alpha++ = a;
|
||||
|
||||
// Check what kind of alpha do we have.
|
||||
switch ( a )
|
||||
{
|
||||
case 0:
|
||||
hasTransparent = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Anything in between means we have real transparency
|
||||
// and must use alpha channel.
|
||||
hasAlpha = true;
|
||||
break;
|
||||
|
||||
case 255:
|
||||
hasOpaque = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( a > 0 )
|
||||
{
|
||||
dst[0] = (dst[0] * 255) / a;
|
||||
dst[1] = (dst[1] * 255) / a;
|
||||
dst[2] = (dst[2] * 255) / a;
|
||||
|
||||
hasAlpha = true;
|
||||
}
|
||||
|
||||
src++;
|
||||
@@ -817,6 +841,9 @@ wxImage wxDIB::ConvertToImage() const
|
||||
srcLineStart += srcBytesPerLine;
|
||||
}
|
||||
|
||||
if ( hasOpaque && hasTransparent )
|
||||
hasAlpha = true;
|
||||
|
||||
if ( !hasAlpha && image.HasAlpha() )
|
||||
image.ClearAlpha();
|
||||
|
||||
|
Reference in New Issue
Block a user