Discard fully transparent alpha channel when loading bitmaps.

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
This commit is contained in:
Vadim Zeitlin 2010-04-09 13:15:25 +00:00
parent 90fbb09ae2
commit b513123062

View File

@ -684,6 +684,14 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
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-- )
{
@ -895,6 +903,9 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
{
temp = (unsigned char)((aDword & amask) >> ashift);
alpha[line * width + column] = temp;
if ( temp != wxALPHA_TRANSPARENT )
hasValidAlpha = true;
}
column++;
}
@ -910,6 +921,13 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
image->SetMask(false);
// 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;
}