From c3ee7025523a7a0ac32bf4c807ae1276fd3bcc09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 10 Jul 2007 16:49:19 +0000 Subject: [PATCH] implemented raw bitmap access for wxDFB git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47300 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dfb/bitmap.h | 8 +++++ include/wx/rawbmp.h | 5 +++ src/dfb/bitmap.cpp | 68 +++++++++++++++++++++++++++++++++++------ 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/include/wx/dfb/bitmap.h b/include/wx/dfb/bitmap.h index 3f26341f47..28bd0b0f28 100644 --- a/include/wx/dfb/bitmap.h +++ b/include/wx/dfb/bitmap.h @@ -13,6 +13,8 @@ #include "wx/dfb/dfbptr.h" +class WXDLLIMPEXP_FWD_CORE wxPixelDataBase; + wxDFB_DECLARE_INTERFACE(IDirectFBSurface); //----------------------------------------------------------------------------- @@ -69,6 +71,12 @@ public: static void InitStandardHandlers(); + // raw bitmap access support functions + void *GetRawData(wxPixelDataBase& data, int bpp); + void UngetRawData(wxPixelDataBase& data); + + bool HasAlpha() const; + // implementation: virtual void SetHeight(int height); virtual void SetWidth(int width); diff --git a/include/wx/rawbmp.h b/include/wx/rawbmp.h index cdd4e66759..3956623b70 100644 --- a/include/wx/rawbmp.h +++ b/include/wx/rawbmp.h @@ -167,6 +167,11 @@ typedef wxPixelFormat wxImagePixelFormat; // Under GTK+ 2.X we use GdkPixbuf, which is standard RGB or RGBA typedef wxPixelFormat wxNativePixelFormat; + #define wxPIXEL_FORMAT_ALPHA 3 +#elif defined(__WXDFB__) + // Under DirectFB, RGB components are reversed, they're in BGR order + typedef wxPixelFormat wxNativePixelFormat; + #define wxPIXEL_FORMAT_ALPHA 3 #endif diff --git a/src/dfb/bitmap.cpp b/src/dfb/bitmap.cpp index 6c759fafb4..6d4b5b0acb 100644 --- a/src/dfb/bitmap.cpp +++ b/src/dfb/bitmap.cpp @@ -23,6 +23,7 @@ #include "wx/bitmap.h" #include "wx/colour.h" #include "wx/image.h" +#include "wx/rawbmp.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) 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 // cannot use preallocated surface that shares data with wxImage, we // have to copy the data to temporary surface instead - DFBSurfaceDescription desc; - desc.flags = (DFBSurfaceDescriptionFlags) - (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); + return CreateSurfaceWithFormat(image.GetWidth(), image.GetHeight(), + DSPF_RGB24); } //----------------------------------------------------------------------------- @@ -361,6 +369,48 @@ wxImage wxBitmap::ConvertToImage() const } #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) { LoadFile(filename, type); -- 2.45.2