wxDIB::Create(wxBitmap) shouldn't do any conversions if the bitmap is already a DIB section
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19785 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -151,30 +151,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init()
|
void Init();
|
||||||
{
|
|
||||||
m_handle = 0;
|
|
||||||
|
|
||||||
m_data = NULL;
|
|
||||||
|
|
||||||
m_width =
|
|
||||||
m_height =
|
|
||||||
m_depth = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// free resources
|
// free resources
|
||||||
void Free()
|
void Free();
|
||||||
{
|
|
||||||
if ( m_handle )
|
|
||||||
{
|
|
||||||
if ( !::DeleteObject(m_handle) )
|
|
||||||
{
|
|
||||||
wxLogLastError(wxT("DeleteObject(hDIB)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the DIB section handle, 0 if invalid
|
// the DIB section handle, 0 if invalid
|
||||||
HBITMAP m_handle;
|
HBITMAP m_handle;
|
||||||
@@ -198,6 +178,11 @@ private:
|
|||||||
m_height,
|
m_height,
|
||||||
m_depth;
|
m_depth;
|
||||||
|
|
||||||
|
// in some cases we could be using a handle which we didn't create and in
|
||||||
|
// this case we shouldn't free it neither -- this flag tell us if this is
|
||||||
|
// the case
|
||||||
|
bool m_ownsHandle;
|
||||||
|
|
||||||
|
|
||||||
// DIBs can't be copied
|
// DIBs can't be copied
|
||||||
wxDIB(const wxDIB&);
|
wxDIB(const wxDIB&);
|
||||||
@@ -208,6 +193,33 @@ private:
|
|||||||
// inline functions implementation
|
// inline functions implementation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
inline
|
||||||
|
void wxDIB::Init()
|
||||||
|
{
|
||||||
|
m_handle = 0;
|
||||||
|
m_ownsHandle = true;
|
||||||
|
|
||||||
|
m_data = NULL;
|
||||||
|
|
||||||
|
m_width =
|
||||||
|
m_height =
|
||||||
|
m_depth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void wxDIB::Free()
|
||||||
|
{
|
||||||
|
if ( m_handle && m_ownsHandle )
|
||||||
|
{
|
||||||
|
if ( !::DeleteObject(m_handle) )
|
||||||
|
{
|
||||||
|
wxLogLastError(wxT("DeleteObject(hDIB)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline wxDIB::~wxDIB()
|
inline wxDIB::~wxDIB()
|
||||||
{
|
{
|
||||||
Free();
|
Free();
|
||||||
|
@@ -132,26 +132,48 @@ bool wxDIB::Create(const wxBitmap& bmp)
|
|||||||
{
|
{
|
||||||
wxCHECK_MSG( bmp.Ok(), false, _T("wxDIB::Create(): invalid bitmap") );
|
wxCHECK_MSG( bmp.Ok(), false, _T("wxDIB::Create(): invalid bitmap") );
|
||||||
|
|
||||||
const int w = bmp.GetWidth();
|
// this bitmap could already be a DIB section in which case we don't need
|
||||||
const int h = bmp.GetHeight();
|
// to convert it to DIB
|
||||||
int d = bmp.GetDepth();
|
HBITMAP hbmp = GetHbitmapOf(bmp);
|
||||||
if ( d == -1 )
|
|
||||||
d = wxDisplayDepth();
|
|
||||||
|
|
||||||
if ( !Create(w, h, d) )
|
DIBSECTION ds;
|
||||||
return false;
|
if ( ::GetObject(hbmp, sizeof(ds), &ds) == sizeof(ds) )
|
||||||
|
|
||||||
// we could have used GetDIBits() too but GetBitmapBits() is simpler
|
|
||||||
if ( !::GetBitmapBits
|
|
||||||
(
|
|
||||||
GetHbitmapOf(bmp), // the source DDB
|
|
||||||
GetLineSize(w, d)*h, // the number of bytes to copy
|
|
||||||
m_data // the pixels will be copied here
|
|
||||||
) )
|
|
||||||
{
|
{
|
||||||
wxLogLastError(wxT("GetDIBits()"));
|
m_handle = hbmp;
|
||||||
|
|
||||||
return 0;
|
// wxBitmap will free it, not we
|
||||||
|
m_ownsHandle = false;
|
||||||
|
|
||||||
|
// copy all the bitmap parameters too as we have them now anyhow
|
||||||
|
m_width = ds.dsBm.bmWidth;
|
||||||
|
m_height = ds.dsBm.bmHeight;
|
||||||
|
m_depth = ds.dsBm.bmBitsPixel;
|
||||||
|
|
||||||
|
m_data = ds.dsBm.bmBits;
|
||||||
|
}
|
||||||
|
else // no, it's a DDB -- convert it to DIB
|
||||||
|
{
|
||||||
|
const int w = bmp.GetWidth();
|
||||||
|
const int h = bmp.GetHeight();
|
||||||
|
int d = bmp.GetDepth();
|
||||||
|
if ( d == -1 )
|
||||||
|
d = wxDisplayDepth();
|
||||||
|
|
||||||
|
if ( !Create(w, h, d) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// we could have used GetDIBits() too but GetBitmapBits() is simpler
|
||||||
|
if ( !::GetBitmapBits
|
||||||
|
(
|
||||||
|
GetHbitmapOf(bmp), // the source DDB
|
||||||
|
GetLineSize(w, d)*h, // the number of bytes to copy
|
||||||
|
m_data // the pixels will be copied here
|
||||||
|
) )
|
||||||
|
{
|
||||||
|
wxLogLastError(wxT("GetDIBits()"));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user