From ca8f5eae936715c2e9db949f1f8ccddb74c40e58 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 3 Jan 2016 15:10:16 +0100 Subject: [PATCH] Optimize converting internal GDI+ bitmap to wxImage Write retrieved pixel data directly to the internal buffers of destination wxImage. --- src/msw/graphics.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index a164867c36..cfb7ad1acc 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -1118,16 +1118,18 @@ wxImage wxGDIPlusBitmapData::ConvertToImage() const Rect rect(0, 0, w, h); m_bitmap->LockBits(&rect, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData); + unsigned char *imgRGB = img.GetData(); // destination RGB buffer + unsigned char *imgAlpha = img.GetAlpha(); // destination alpha buffer const BYTE* pixels = static_cast(bitmapData.Scan0); for( UINT y = 0; y < h; y++ ) { for( UINT x = 0; x < w; x++ ) { ARGB c = reinterpret_cast(pixels)[x]; - img.SetRGB(x, y, (c >> 16) & 0xFF, - (c >> 8) & 0xFF, - (c >> 0) & 0xFF); - img.SetAlpha(x, y, (c >> 24) & 0xFF); + *imgRGB++ = (c >> 16) & 0xFF; // R + *imgRGB++ = (c >> 8) & 0xFF; // G + *imgRGB++ = (c >> 0) & 0xFF; // B + *imgAlpha++ = (c >> 24) & 0xFF; } pixels += bitmapData.Stride;