]> git.saurik.com Git - wxWidgets.git/commitdiff
convert bitmap's surface to RGB24/ARGB in wxBitmap::GetRawData() if it uses different...
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 15 Jul 2007 10:05:09 +0000 (10:05 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 15 Jul 2007 10:05:09 +0000 (10:05 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47480 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/dfb/bitmap.cpp

index 2072c300b79f762ce7c89b3c381b7fde345f2be9..e6a8b26dc93efd3478456b25f1d5d4876abc1054 100644 (file)
@@ -203,6 +203,27 @@ static wxIDirectFBSurfacePtr CreateSurfaceForImage(const wxImage& image)
                                    DSPF_RGB24);
 }
 
+static bool ConvertSurfaceToFormat(wxIDirectFBSurfacePtr& surface,
+                                   DFBSurfacePixelFormat format)
+{
+    if ( surface->GetPixelFormat() == format )
+        return true;
+
+    int w, h;
+    surface->GetSize(&w, &h);
+    wxIDirectFBSurfacePtr s = CreateSurfaceWithFormat(w, h, format);
+    if ( !s )
+        return false;
+
+    if ( !s->SetBlittingFlags(DSBLIT_NOFX) )
+        return false;
+    if ( !s->Blit(surface->GetRaw(), NULL, 0, 0) )
+        return false;
+
+    surface = s;
+    return true;
+}
+
 static DFBSurfacePixelFormat DepthToFormat(int depth)
 {
     switch ( depth )
@@ -392,8 +413,11 @@ void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
     else
         format = DSPF_RGB24;
 
-    // requested format is not what this bitmap uses
-    if ( format != M_BITMAP->m_surface->GetPixelFormat() )
+    // convert the bitmap into format compatible with requested raw access;
+    // note that we don't bother converting the bitmap back in UngetRawData(),
+    // as unpacked formats (RGB24, RGB32) are the common case and converting
+    // between them while blitting is fast enough (FIXME?)
+    if ( !ConvertSurfaceToFormat(M_BITMAP->m_surface, format) )
         return NULL;
 
     void *bits = NULL;