From 0c8ae72029686a5993f6ddc88589ceccdafb15aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 15 Jul 2007 10:05:09 +0000 Subject: [PATCH] convert bitmap's surface to RGB24/ARGB in wxBitmap::GetRawData() if it uses different format git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47480 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/dfb/bitmap.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/dfb/bitmap.cpp b/src/dfb/bitmap.cpp index 2072c300b7..e6a8b26dc9 100644 --- a/src/dfb/bitmap.cpp +++ b/src/dfb/bitmap.cpp @@ -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; -- 2.47.2