From: Vadim Zeitlin Date: Sun, 13 Apr 2003 16:23:40 +0000 (+0000) Subject: don't crash in UngetRawData() if it is invalid; fixed rounding errors in alpha premul... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7af64aace1813c851c7cb8366fb4ba4be0b68f7f don't crash in UngetRawData() if it is invalid; fixed rounding errors in alpha premultiplying git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20200 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 797f755a14..25af362a2e 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -1209,6 +1209,14 @@ void wxBitmap::UngetRawData(wxRawBitmapData *data) { wxCHECK_RET( data, _T("NULL pointer in wxBitmap::UngetRawData()") ); + if ( !*data ) + { + // invalid data, don't crash -- but don't assert neither as we're + // called automatically from wxRawBitmapData dtor and so there is no + // way to prevent this from happening + return; + } + // AlphaBlend() wants to have premultiplied source alpha but wxRawBitmap // API uses normal, not premultiplied, colours, so adjust them here now wxRawBitmapIterator p(*data); @@ -1224,9 +1232,9 @@ void wxBitmap::UngetRawData(wxRawBitmapData *data) { const unsigned alpha = p.Alpha(); - p.Red() = (p.Red() * alpha) / 255; - p.Blue() = (p.Blue() * alpha) / 255; - p.Green() = (p.Green() * alpha) / 255; + p.Red() = (p.Red() * alpha + 127) / 255; + p.Blue() = (p.Blue() * alpha + 127) / 255; + p.Green() = (p.Green() * alpha + 127) / 255; ++p; }