implemented raw bitmap access for wxDFB
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47300 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include "wx/dfb/dfbptr.h"
|
#include "wx/dfb/dfbptr.h"
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
|
||||||
|
|
||||||
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -69,6 +71,12 @@ public:
|
|||||||
|
|
||||||
static void InitStandardHandlers();
|
static void InitStandardHandlers();
|
||||||
|
|
||||||
|
// raw bitmap access support functions
|
||||||
|
void *GetRawData(wxPixelDataBase& data, int bpp);
|
||||||
|
void UngetRawData(wxPixelDataBase& data);
|
||||||
|
|
||||||
|
bool HasAlpha() const;
|
||||||
|
|
||||||
// implementation:
|
// implementation:
|
||||||
virtual void SetHeight(int height);
|
virtual void SetHeight(int height);
|
||||||
virtual void SetWidth(int width);
|
virtual void SetWidth(int width);
|
||||||
|
@@ -167,6 +167,11 @@ typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxImagePixelFormat;
|
|||||||
// Under GTK+ 2.X we use GdkPixbuf, which is standard RGB or RGBA
|
// Under GTK+ 2.X we use GdkPixbuf, which is standard RGB or RGBA
|
||||||
typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxNativePixelFormat;
|
typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxNativePixelFormat;
|
||||||
|
|
||||||
|
#define wxPIXEL_FORMAT_ALPHA 3
|
||||||
|
#elif defined(__WXDFB__)
|
||||||
|
// Under DirectFB, RGB components are reversed, they're in BGR order
|
||||||
|
typedef wxPixelFormat<unsigned char, 24, 2, 1, 0> wxNativePixelFormat;
|
||||||
|
|
||||||
#define wxPIXEL_FORMAT_ALPHA 3
|
#define wxPIXEL_FORMAT_ALPHA 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
#include "wx/colour.h"
|
#include "wx/colour.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/rawbmp.h"
|
||||||
|
|
||||||
#include "wx/dfb/private.h"
|
#include "wx/dfb/private.h"
|
||||||
|
|
||||||
@@ -167,6 +168,20 @@ static void CopyImageToSurface(const wxImage& image,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static wxIDirectFBSurfacePtr
|
||||||
|
CreateSurfaceWithFormat(int w, int h, DFBSurfacePixelFormat format)
|
||||||
|
{
|
||||||
|
DFBSurfaceDescription desc;
|
||||||
|
desc.flags = (DFBSurfaceDescriptionFlags)
|
||||||
|
(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
|
||||||
|
desc.caps = DSCAPS_NONE;
|
||||||
|
desc.width = w;
|
||||||
|
desc.height = h;
|
||||||
|
desc.pixelformat = format;
|
||||||
|
|
||||||
|
return wxIDirectFB::Get()->CreateSurface(&desc);
|
||||||
|
}
|
||||||
|
|
||||||
// Creates a surface that will use wxImage's pixel data (RGB only)
|
// Creates a surface that will use wxImage's pixel data (RGB only)
|
||||||
static wxIDirectFBSurfacePtr CreateSurfaceForImage(const wxImage& image)
|
static wxIDirectFBSurfacePtr CreateSurfaceForImage(const wxImage& image)
|
||||||
{
|
{
|
||||||
@@ -178,15 +193,8 @@ static wxIDirectFBSurfacePtr CreateSurfaceForImage(const wxImage& image)
|
|||||||
// NB: wxImage uses RGB order of bytes while DirectFB uses BGR, so we
|
// NB: wxImage uses RGB order of bytes while DirectFB uses BGR, so we
|
||||||
// cannot use preallocated surface that shares data with wxImage, we
|
// cannot use preallocated surface that shares data with wxImage, we
|
||||||
// have to copy the data to temporary surface instead
|
// have to copy the data to temporary surface instead
|
||||||
DFBSurfaceDescription desc;
|
return CreateSurfaceWithFormat(image.GetWidth(), image.GetHeight(),
|
||||||
desc.flags = (DFBSurfaceDescriptionFlags)
|
DSPF_RGB24);
|
||||||
(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
|
|
||||||
desc.caps = DSCAPS_NONE;
|
|
||||||
desc.width = image.GetWidth();
|
|
||||||
desc.height = image.GetHeight();
|
|
||||||
desc.pixelformat = DSPF_RGB24;
|
|
||||||
|
|
||||||
return wxIDirectFB::Get()->CreateSurface(&desc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -361,6 +369,48 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
}
|
}
|
||||||
#endif // wxUSE_IMAGE
|
#endif // wxUSE_IMAGE
|
||||||
|
|
||||||
|
void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( Ok(), NULL, "invalid bitmap" );
|
||||||
|
|
||||||
|
AllocExclusive();
|
||||||
|
|
||||||
|
DFBSurfacePixelFormat format;
|
||||||
|
if ( bpp == 32 )
|
||||||
|
format = DSPF_ARGB;
|
||||||
|
else
|
||||||
|
format = DSPF_RGB24;
|
||||||
|
|
||||||
|
// requested format is not what this bitmap uses
|
||||||
|
if ( format != M_BITMAP->m_surface->GetPixelFormat() )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
void *bits = NULL;
|
||||||
|
if ( !M_BITMAP->m_surface->Lock
|
||||||
|
(
|
||||||
|
(DFBSurfaceLockFlags)(DSLF_READ | DSLF_WRITE),
|
||||||
|
&bits,
|
||||||
|
&data.m_stride
|
||||||
|
) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
M_BITMAP->m_surface->GetSize(&data.m_width, &data.m_height);
|
||||||
|
|
||||||
|
return bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmap::UngetRawData(wxPixelDataBase& WXUNUSED(data))
|
||||||
|
{
|
||||||
|
M_BITMAP->m_surface->Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::HasAlpha() const
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( Ok(), false, "invalid bitmap" );
|
||||||
|
|
||||||
|
return M_BITMAP->m_surface->GetPixelFormat() == DSPF_ARGB;
|
||||||
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(const wxString &filename, wxBitmapType type)
|
wxBitmap::wxBitmap(const wxString &filename, wxBitmapType type)
|
||||||
{
|
{
|
||||||
LoadFile(filename, type);
|
LoadFile(filename, type);
|
||||||
|
Reference in New Issue
Block a user