From c239160d33996c6f73d51c606cf35b52f7af78c9 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 6 Dec 2015 13:17:47 +0100 Subject: [PATCH] Optimize AlphaBlt() to reset the minimal amount of pixels Modify the loop fixing alpha channel value in order to increase speed when ARGB bitmap is drawn on 0RGB DIB bitmap or 32-bit DDB bitmap. Closes #16766. --- src/msw/dc.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 78f0fbb3f4..03f96e6955 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -2620,15 +2620,23 @@ static bool AlphaBlt(wxMSWDCImpl* dcDst, // Notice the extra block: we must destroy wxAlphaPixelData // before selecting the bitmap into the DC again. { + // Since drawn bitmap can only partially overlap + // with destination bitmap we need to calculate + // efective drawing area location. + const wxRect rectDst(bmpOld.GetSize()); + const wxRect rectDrawn(x, y, dstWidth, dstHeight); + const wxRect r = rectDrawn.Intersect(rectDst); + wxAlphaPixelData data(bmpOld); if ( data ) { wxAlphaPixelData::Iterator p(data); - for ( int old_y = 0; old_y < data.GetHeight(); old_y++ ) + + p.Offset(data, r.GetLeft(), r.GetTop()); + for ( int old_y = 0; old_y < r.GetHeight(); old_y++ ) { wxAlphaPixelData::Iterator rowStart = p; - - for ( int old_x = 0; old_x < data.GetWidth(); old_x++ ) + for ( int old_x = 0; old_x < r.GetWidth(); old_x++ ) { // We choose to use wxALPHA_TRANSPARENT instead // of perhaps more logical wxALPHA_OPAQUE here