Some bitmap files declare themselves to be 32bpp, normally indicating that
they have an alpha channel, but have only zeroes in their alpha data. Hence
loading them used to create fully transparent images which wasn't the desired
effect.
Fix this by simply discarding the alpha channel entirely if it turns out that
all pixels were fully transparent.
Closes #10915.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63923
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
int linesize = ((width * bpp + 31) / 32) * 4;
int linesize = ((width * bpp + 31) / 32) * 4;
+ // flag indicating if we have any not fully transparent alpha values: this
+ // is used to account for the bitmaps which use 32bpp format (normally
+ // meaning that they have alpha channel) but have only zeroes in it so that
+ // without this hack they appear fully transparent -- and as this is
+ // unlikely intentional, we consider that they don't have alpha at all in
+ // this case (see #10915)
+ bool hasValidAlpha = false;
+
/* BMPs are stored upside down */
for ( int line = (height - 1); line >= 0; line-- )
{
/* BMPs are stored upside down */
for ( int line = (height - 1); line >= 0; line-- )
{
{
temp = (unsigned char)((aDword & amask) >> ashift);
alpha[line * width + column] = temp;
{
temp = (unsigned char)((aDword & amask) >> ashift);
alpha[line * width + column] = temp;
+
+ if ( temp != wxALPHA_TRANSPARENT )
+ hasValidAlpha = true;
+ // check if we had any valid alpha values in this bitmap
+ if ( alpha && !hasValidAlpha )
+ {
+ // we didn't, so finally discard the alpha channel completely
+ image->ClearAlpha();
+ }
+
const wxStreamError err = stream.GetLastError();
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
}
const wxStreamError err = stream.GetLastError();
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
}