Optimize converting internal GDI+ bitmap to wxImage
Write retrieved pixel data directly to the internal buffers of destination wxImage.
This commit is contained in:
@@ -1118,16 +1118,18 @@ wxImage wxGDIPlusBitmapData::ConvertToImage() const
|
|||||||
Rect rect(0, 0, w, h);
|
Rect rect(0, 0, w, h);
|
||||||
m_bitmap->LockBits(&rect, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);
|
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<const BYTE*>(bitmapData.Scan0);
|
const BYTE* pixels = static_cast<const BYTE*>(bitmapData.Scan0);
|
||||||
for( UINT y = 0; y < h; y++ )
|
for( UINT y = 0; y < h; y++ )
|
||||||
{
|
{
|
||||||
for( UINT x = 0; x < w; x++ )
|
for( UINT x = 0; x < w; x++ )
|
||||||
{
|
{
|
||||||
ARGB c = reinterpret_cast<const ARGB*>(pixels)[x];
|
ARGB c = reinterpret_cast<const ARGB*>(pixels)[x];
|
||||||
img.SetRGB(x, y, (c >> 16) & 0xFF,
|
*imgRGB++ = (c >> 16) & 0xFF; // R
|
||||||
(c >> 8) & 0xFF,
|
*imgRGB++ = (c >> 8) & 0xFF; // G
|
||||||
(c >> 0) & 0xFF);
|
*imgRGB++ = (c >> 0) & 0xFF; // B
|
||||||
img.SetAlpha(x, y, (c >> 24) & 0xFF);
|
*imgAlpha++ = (c >> 24) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixels += bitmapData.Stride;
|
pixels += bitmapData.Stride;
|
||||||
|
Reference in New Issue
Block a user