Ensure that a copy of a DIB wxBitmap remains a DIB in wxMSW

Creating a DDB from DIB with alpha doesn't work correctly due to using
premultiplied alpha for the latter, but not for the former, and while we
could convert it, it seems to be even better to just preserve the type
of the original bitmap, as this would seem to be expected when making a
copy, after all.

This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
Vadim Zeitlin
2022-02-02 22:36:00 +00:00
parent 2ae80673ff
commit d4c83e1cbc

View File

@@ -232,24 +232,40 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data)
if ( data.m_hBitmap ) if ( data.m_hBitmap )
{ {
wxDIB dib((HBITMAP)(data.m_hBitmap)); wxDIB dib((HBITMAP)(data.m_hBitmap));
// DDB obtained from CopyFromDIB() can have different
// colour depth than source DIB so we need to check it. // Cloning a DIB should create a DIB, while cloning a DDB should create
CopyFromDIB(dib); // a DDB, so check what do we have.
if ( m_depth != dib.GetDepth() ) if ( data.m_isDIB )
{ {
// We got DDB with a different colour depth than we wanted, so we const int w = dib.GetWidth();
// can't use it and need to continue using the DIB instead. const int h = dib.GetHeight();
wxDIB dibDst(m_width, m_height, dib.GetDepth()); const int d = dib.GetDepth();
if ( dibDst.IsOk() )
wxDIB dibDst(w, h, d);
memcpy(dibDst.GetData(), dib.GetData(), wxDIB::GetLineSize(w, d)*h);
InitFromDIB(dibDst);
}
else
{
// DDB obtained from CopyFromDIB() can have different
// colour depth than source DIB so we need to check it.
CopyFromDIB(dib);
if ( m_depth != dib.GetDepth() )
{ {
m_depth = dib.GetDepth(); // We got DDB with a different colour depth than we wanted, so we
memcpy(dibDst.GetData(), dib.GetData(), // can't use it and need to continue using the DIB instead.
wxDIB::GetLineSize(m_width, m_depth)*m_height); wxDIB dibDst(m_width, m_height, dib.GetDepth());
AssignDIB(dibDst); if ( dibDst.IsOk() )
} {
else m_depth = dib.GetDepth();
{ memcpy(dibDst.GetData(), dib.GetData(),
// Nothing else left to do... wxDIB::GetLineSize(m_width, m_depth)*m_height);
AssignDIB(dibDst);
}
else
{
// Nothing else left to do...
}
} }
} }
} }