From: Vadim Zeitlin Date: Fri, 9 Apr 2010 13:15:25 +0000 (+0000) Subject: Discard fully transparent alpha channel when loading bitmaps. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b5131230626e20bde4bf9936eb7e5cebc8f629dc 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 --- diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index 3e7a128d10..41edf784b4 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -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; }