X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/949e0a38278196e5ace3caa1c5c24d4f0cb36a6a..8930b2ed1ebff50797843db75744c6963287dbe7:/src/dfb/bitmap.cpp diff --git a/src/dfb/bitmap.cpp b/src/dfb/bitmap.cpp index 75dc5ea24a..b50e4aac90 100644 --- a/src/dfb/bitmap.cpp +++ b/src/dfb/bitmap.cpp @@ -49,6 +49,27 @@ static wxColour wxQuantizeColour(const wxColour& clr, const wxBitmap& bmp) #endif } +// Creates a surface that will use wxImage's pixel data (RGB only) +static wxIDirectFBSurfacePtr CreateSurfaceForImage(const wxImage& image) +{ + wxCHECK_MSG( image.Ok(), NULL, _T("invalid image") ); + // FIXME_DFB: implement alpha handling by merging alpha buffer with RGB + // into a temporary RGBA surface + wxCHECK_MSG( !image.HasAlpha(), NULL, _T("alpha channel not supported") ); + + DFBSurfaceDescription desc; + desc.flags = (DFBSurfaceDescriptionFlags) + (DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | + DSDESC_PREALLOCATED); + desc.caps = DSCAPS_NONE; + desc.width = image.GetWidth(); + desc.height = image.GetHeight(); + desc.pixelformat = DSPF_RGB24; + desc.preallocated[0].data = image.GetData(); + desc.preallocated[0].pitch = 3 * desc.width; + + return wxIDirectFB::Get()->CreateSurface(&desc); +} //----------------------------------------------------------------------------- // wxMask @@ -247,13 +268,41 @@ bool wxBitmap::CreateFromXpm(const char **bits) wxBitmap::wxBitmap(const wxImage& image, int depth) { wxCHECK_RET( image.Ok(), wxT("invalid image") ); + + // create surface in screen's format: + if ( !Create(image.GetWidth(), image.GetHeight(), depth) ) + return; + + // then copy the image to it: + wxIDirectFBSurfacePtr src(CreateSurfaceForImage(image)); + wxIDirectFBSurfacePtr dst = M_BITMAP->m_surface; + + if ( !dst->SetBlittingFlags(DSBLIT_NOFX) ) + return; + if ( !dst->Blit(src->GetRaw(), NULL, 0, 0) ) + return; + + // FIXME: implement mask creation from image's mask (or alpha channel?) + wxASSERT_MSG( !image.HasMask(), _T("image masks are ignored for now") ); } wxImage wxBitmap::ConvertToImage() const { wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") ); - return wxNullImage; // FIXME + wxImage img(GetWidth(), GetHeight()); + wxIDirectFBSurfacePtr dst(CreateSurfaceForImage(img)); + wxIDirectFBSurfacePtr src = M_BITMAP->m_surface; + + if ( !dst->SetBlittingFlags(DSBLIT_NOFX) ) + return wxNullImage; + if ( !dst->Blit(src->GetRaw(), NULL, 0, 0) ) + return wxNullImage; + + // FIXME: implement mask setting in the image + wxASSERT_MSG( GetMask() == NULL, _T("bitmap masks are ignored for now") ); + + return img; } #endif // wxUSE_IMAGE @@ -420,19 +469,22 @@ void wxBitmap::SetPalette(const wxPalette& palette) void wxBitmap::SetHeight(int height) { AllocExclusive(); -#warning "todo" + + wxFAIL_MSG( _T("SetHeight not implemented") ); } void wxBitmap::SetWidth(int width) { AllocExclusive(); -#warning "todo" + + wxFAIL_MSG( _T("SetWidth not implemented") ); } void wxBitmap::SetDepth(int depth) { AllocExclusive(); -#warning "todo" + + wxFAIL_MSG( _T("SetDepth not implemented") ); } wxIDirectFBSurfacePtr wxBitmap::GetDirectFBSurface() const