Fix alpha channel values when using wxGCDC with wxMemoryDC in wxMSW.
Ensure that 32bpp bitmaps selected in wxMemoryDC use DIB for their internal representation as GDI+ functions don't seem to work correctly with DDBs with alpha channel. Closes #13328. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75648 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -68,8 +68,15 @@ public:
|
||||
|
||||
virtual void Free();
|
||||
|
||||
// Creates a new bitmap (DDB or DIB) from the contents of the given DIB.
|
||||
void CopyFromDIB(const wxDIB& dib);
|
||||
|
||||
#ifndef NEVER_USE_DIB
|
||||
// Takes ownership of the given DIB.
|
||||
bool AssignDIB(wxDIB& dib);
|
||||
#endif // !NEVER_USE_DIB
|
||||
|
||||
|
||||
// set the mask object to use as the mask, we take ownership of it
|
||||
void SetMask(wxMask *mask)
|
||||
{
|
||||
@@ -118,6 +125,11 @@ public:
|
||||
private:
|
||||
void Init();
|
||||
|
||||
// Use the given bitmap handle and take the rest of the characteristics
|
||||
// (size, depth, ...) from the given DIB.
|
||||
void InitFromDIB(const wxDIB& dib, HBITMAP hbitmap);
|
||||
|
||||
|
||||
// optional mask for transparent drawing
|
||||
wxMask *m_bitmapMask;
|
||||
|
||||
@@ -249,6 +261,22 @@ void wxBitmapRefData::Free()
|
||||
wxDELETE(m_bitmapMask);
|
||||
}
|
||||
|
||||
void wxBitmapRefData::InitFromDIB(const wxDIB& dib, HBITMAP hbitmap)
|
||||
{
|
||||
m_width = dib.GetWidth();
|
||||
m_height = dib.GetHeight();
|
||||
m_depth = dib.GetDepth();
|
||||
|
||||
m_hBitmap = (WXHBITMAP)hbitmap;
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
wxPalette *palette = dib.CreatePalette();
|
||||
if ( palette )
|
||||
m_bitmapPalette = *palette;
|
||||
delete palette;
|
||||
#endif // wxUSE_PALETTE
|
||||
}
|
||||
|
||||
void wxBitmapRefData::CopyFromDIB(const wxDIB& dib)
|
||||
{
|
||||
wxCHECK_RET( !IsOk(), "bitmap already initialized" );
|
||||
@@ -264,20 +292,26 @@ void wxBitmapRefData::CopyFromDIB(const wxDIB& dib)
|
||||
m_isDIB = true;
|
||||
#endif // SOMETIMES_USE_DIB/ALWAYS_USE_DIB
|
||||
|
||||
m_width = dib.GetWidth();
|
||||
m_height = dib.GetHeight();
|
||||
m_depth = dib.GetDepth();
|
||||
|
||||
m_hBitmap = (WXHBITMAP)hbitmap;
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
wxPalette *palette = dib.CreatePalette();
|
||||
if ( palette )
|
||||
m_bitmapPalette = *palette;
|
||||
delete palette;
|
||||
#endif // wxUSE_PALETTE
|
||||
InitFromDIB(dib, hbitmap);
|
||||
}
|
||||
|
||||
#ifndef NEVER_USE_DIB
|
||||
|
||||
bool wxBitmapRefData::AssignDIB(wxDIB& dib)
|
||||
{
|
||||
if ( !dib.IsOk() )
|
||||
return false;
|
||||
|
||||
Free();
|
||||
|
||||
m_isDIB = true;
|
||||
InitFromDIB(dib, dib.Detach());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // !NEVER_USE_DIB
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmap creation
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -457,6 +491,26 @@ bool wxBitmap::CopyFromDIB(const wxDIB& dib)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxBitmap::IsDIB() const
|
||||
{
|
||||
return GetBitmapData() && GetBitmapData()->m_isDIB;
|
||||
}
|
||||
|
||||
bool wxBitmap::ConvertToDIB()
|
||||
{
|
||||
if ( IsDIB() )
|
||||
return true;
|
||||
|
||||
wxDIB dib(*this);
|
||||
if ( !dib.IsOk() )
|
||||
return false;
|
||||
|
||||
// It is important to reuse the current GetBitmapData() instead of creating
|
||||
// a new one, as our object identity shouldn't change just because our
|
||||
// internal representation did, but IsSameAs() compares data pointers.
|
||||
return GetBitmapData()->AssignDIB(dib);
|
||||
}
|
||||
|
||||
#endif // NEVER_USE_DIB
|
||||
|
||||
wxBitmap::~wxBitmap()
|
||||
|
Reference in New Issue
Block a user