From: Vadim Zeitlin Date: Sun, 19 Nov 2006 12:35:16 +0000 (+0000) Subject: unmultiply by alpha when converting from wxDIB to wxImage as the former uses premulti... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/0deb5fab34f3cc90d717347b7335297ff67cc1b3 unmultiply by alpha when converting from wxDIB to wxImage as the former uses premultiplied alpha but the latter does not (patch 1597063) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43511 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 7b0d6dbc25..7e54a29355 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -98,6 +98,7 @@ wxMSW: - Fixed version script problems when using configure with cygwin/mingw32. - Use system default paper size for printing instead of A4 +- Fix colours when converting wxBitmap with alpha to wxImage (nusi) 2.7.2 ----- diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index ee17d5d2b1..0c89e7e5ad 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -775,14 +775,26 @@ wxImage wxDIB::ConvertToImage() const dst[1] = *src++; dst[0] = *src++; - dst += 3; - if ( is32bit ) { if ( alpha ) - *alpha++ = *src; + { + // wxImage uses non premultiplied alpha so undo + // premultiplication done in Create() above + const unsigned char a = *src; + *alpha++ = a; + if ( a > 0 ) + { + dst[0] = (dst[0] * 255 - 127) / a; + dst[1] = (dst[1] * 255 - 127) / a; + dst[2] = (dst[2] * 255 - 127) / a; + } + } + src++; } + + dst += 3; } // pass to the previous line in the image