From 13c13ecbbf6a920c737ec0d3604278f544b83192 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 13 Apr 2003 14:02:17 +0000 Subject: [PATCH] premultiply the colours by the alpha value git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20192 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/bitmap.h | 2 +- src/msw/bitmap.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index cd67008e6b..75efef8d65 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -133,7 +133,7 @@ public: // raw bitmap access support functions bool GetRawData(wxRawBitmapData *data); - void UngetRawData(wxRawBitmapData *) { /* nothing to do here */ } + void UngetRawData(wxRawBitmapData *); #if wxUSE_PALETTE wxPalette* GetPalette() const; diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 564f1f33f1..ca244ccda0 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -1198,6 +1198,33 @@ bool wxBitmap::GetRawData(wxRawBitmapData *data) return TRUE; } +void wxBitmap::UngetRawData(wxRawBitmapData *data) +{ + wxCHECK_RET( data, _T("NULL pointer in wxBitmap::UngetRawData()") ); + + // AlphaBlend() wants to have premultiplied source alpha but wxRawBitmap + // API uses normal, not premultiplied, colours, so adjust them here now + wxRawBitmapIterator p(data); + unsigned char *pixels = data->GetPixels(); + + const int w = data->GetWidth(); + const int h = data->GetHeight(); + + for ( int y = 0; y < h; y++ ) + { + for ( int x = 0; x < w; x++ ) + { + const unsigned alpha = p.Alpha(); + p.Red() *= alpha; + p.Red() /= 255 + p.Blue() *= alpha; + p.Blue() /= 255 + p.Green() *= alpha; + p.Green() /= 255 + } + } +} + // ---------------------------------------------------------------------------- // wxMask // ---------------------------------------------------------------------------- -- 2.47.2