From d48e3998b0fd42f5f94d4465ab61aff9bbfe9344 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Mar 2007 16:39:21 +0000 Subject: [PATCH] Fix to allow using Cairo version < 1.2 where cairo_image_surface_get_data doesn't exist. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@44597 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/graphicc.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index a3a93aeb76..f40b1c5845 100755 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1152,12 +1152,16 @@ void wxCairoContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wx int bw = bmp.GetWidth(); int bh = bmp.GetHeight(); wxBitmap bmpSource = bmp; // we need a non-const instance + unsigned char* buffer = new unsigned char[bw*bh*4]; + wxUint32* data = (wxUint32*)buffer; - // Create a surface object and copy the bitmap pixel data to it. + // Create a surface object and copy the bitmap pixel data to it. if the + // image has alpha (or a mask represented as alpha) then we'll use a + // different format and iterator than if it doesn't... if (bmpSource.HasAlpha() || bmpSource.GetMask()) { - surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bw, bh); - wxUint32* data = (wxUint32*)cairo_image_surface_get_data(surface); + surface = cairo_image_surface_create_for_data( + buffer, CAIRO_FORMAT_ARGB32, bw, bh, bw*4); wxAlphaPixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh)); wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data.")); @@ -1186,14 +1190,10 @@ void wxCairoContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wx p.OffsetY(pixData, 1); } } - else + else // no alpha { - wxImage img = bmpSource.ConvertToImage(); surface = cairo_image_surface_create_for_data( - img.GetData(), CAIRO_FORMAT_RGB24, bw, bh, bw*3); - - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, bw, bh); - wxUint32* data = (wxUint32*)cairo_image_surface_get_data(surface); + buffer, CAIRO_FORMAT_RGB24, bw, bh, bw*4); wxNativePixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh)); wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data.")); @@ -1238,6 +1238,7 @@ void wxCairoContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wx // clean up cairo_pattern_destroy(pattern); cairo_surface_destroy(surface); + delete [] buffer; PopState(); }