]> git.saurik.com Git - wxWidgets.git/commitdiff
implemented raw bitmap access for wxDFB
authorVáclav Slavík <vslavik@fastmail.fm>
Tue, 10 Jul 2007 16:49:19 +0000 (16:49 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Tue, 10 Jul 2007 16:49:19 +0000 (16:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47300 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dfb/bitmap.h
include/wx/rawbmp.h
src/dfb/bitmap.cpp

index 3f26341f473675596b762e41f1187eaf4821052c..28bd0b0f280f918897cd61ac98b3ce2ceaee3d31 100644 (file)
@@ -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:
     virtual void SetHeight(int height);
     virtual void SetWidth(int width);
     // implementation:
     virtual void SetHeight(int height);
     virtual void SetWidth(int width);
index cdd4e66759a4ecfd821c3a8a4aa89296d9f157a8..3956623b709529b0c3eb7b13ee3d5fadad917247 100644 (file)
@@ -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
     typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxNativePixelFormat;
 
     // Under GTK+ 2.X we use GdkPixbuf, which is standard RGB or RGBA
     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
 #endif
 
     #define wxPIXEL_FORMAT_ALPHA 3
 #endif
 
index 6c759fafb4940a69e26cf0bd1287b9cf60f516a7..6d4b5b0acb1819b304f44946472f1e6b7c77ec27 100644 (file)
@@ -23,6 +23,7 @@
 #include "wx/bitmap.h"
 #include "wx/colour.h"
 #include "wx/image.h"
 #include "wx/bitmap.h"
 #include "wx/colour.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)
 static wxIDirectFBSurfacePtr CreateSurfaceForImage(const wxImage& image)
 {
 // 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
     // 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
 
 }
 #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);
 wxBitmap::wxBitmap(const wxString &filename, wxBitmapType type)
 {
     LoadFile(filename, type);