summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2013-06-13 12:47:02 +0200
committerThorsten Behrens <tbehrens@suse.com>2013-06-13 14:03:52 +0200
commit243e40694936c21b781bf929a7153b1f8cb7f8ae (patch)
tree23a34b5a6a950d219cd61033f7bbe1812377026d
parent12d9559a5498d1c73b3bd8f130a416a029ceaf15 (diff)
Add some error handling to bitmap conversion.
Fixup for 7cf2b5809f7137acc7a5eed9159042b3d748da01, makes sure cairo has all data committed to the surface, and handle random errors. Conflicts: canvas/source/cairo/cairo_canvasbitmap.cxx Change-Id: I39e5b5777968c4563a8ce3870bac3d4182090f3b (cherry picked from commit 83b785e1924e418f98167205cd1b20054feffe3f)
-rw-r--r--canvas/source/cairo/cairo_canvasbitmap.cxx55
1 files changed, 31 insertions, 24 deletions
diff --git a/canvas/source/cairo/cairo_canvasbitmap.cxx b/canvas/source/cairo/cairo_canvasbitmap.cxx
index 062af840b595..59a84d82b9aa 100644
--- a/canvas/source/cairo/cairo_canvasbitmap.cxx
+++ b/canvas/source/cairo/cairo_canvasbitmap.cxx
@@ -172,39 +172,46 @@ namespace cairocanvas
::AlphaMask aMask( aSize );
BitmapWriteAccess *pRGBWrite( aRGB.AcquireWriteAccess() );
- BitmapWriteAccess *pMaskWrite( aMask.AcquireWriteAccess() );
-
- unsigned char *pSrc = cairo_image_surface_get_data( pPixels );
- unsigned int nStride = cairo_image_surface_get_stride( pPixels );
- for( unsigned long y = 0; y < (unsigned long) aSize.Height(); y++ )
+ if( pRGBWrite )
{
- sal_uInt32 *pPix = (sal_uInt32 *)(pSrc + nStride * y);
- for( unsigned long x = 0; x < (unsigned long) aSize.Width(); x++ )
+ BitmapWriteAccess *pMaskWrite( aMask.AcquireWriteAccess() );
+ if( pMaskWrite )
{
- sal_uInt8 nAlpha = (*pPix >> 24);
- sal_uInt8 nR = (*pPix >> 16) & 0xff;
- sal_uInt8 nG = (*pPix >> 8) & 0xff;
- sal_uInt8 nB = *pPix & 0xff;
- if( nAlpha != 0 && nAlpha != 255 )
+ cairo_surface_flush(pPixels);
+ unsigned char *pSrc = cairo_image_surface_get_data( pPixels );
+ unsigned int nStride = cairo_image_surface_get_stride( pPixels );
+ for( unsigned long y = 0; y < (unsigned long) aSize.Height(); y++ )
{
-// fprintf (stderr, "From A(0x%.2x) 0x%.2x 0x%.2x 0x%.2x -> ",
-// nAlpha, nR, nG, nB );
- // Cairo uses pre-multiplied alpha - we do not => re-multiply
- nR = (sal_uInt8) MinMax( ((sal_uInt32)nR * 255) / nAlpha, 0, 255 );
- nG = (sal_uInt8) MinMax( ((sal_uInt32)nG * 255) / nAlpha, 0, 255 );
- nB = (sal_uInt8) MinMax( ((sal_uInt32)nB * 255) / nAlpha, 0, 255 );
-// fprintf (stderr, "0x%.2x 0x%.2x 0x%.2x\n", nR, nG, nB );
+ sal_uInt32 *pPix = (sal_uInt32 *)(pSrc + nStride * y);
+ for( unsigned long x = 0; x < (unsigned long) aSize.Width(); x++ )
+ {
+ sal_uInt8 nAlpha = (*pPix >> 24);
+ sal_uInt8 nR = (*pPix >> 16) & 0xff;
+ sal_uInt8 nG = (*pPix >> 8) & 0xff;
+ sal_uInt8 nB = *pPix & 0xff;
+ if( nAlpha != 0 && nAlpha != 255 )
+ {
+ // Cairo uses pre-multiplied alpha - we do not => re-multiply
+ nR = (sal_uInt8) MinMax( ((sal_uInt32)nR * 255) / nAlpha, 0, 255 );
+ nG = (sal_uInt8) MinMax( ((sal_uInt32)nG * 255) / nAlpha, 0, 255 );
+ nB = (sal_uInt8) MinMax( ((sal_uInt32)nB * 255) / nAlpha, 0, 255 );
+ }
+ pRGBWrite->SetPixel( y, x, BitmapColor( nR, nG, nB ) );
+ pMaskWrite->SetPixel( y, x, BitmapColor( 255 - nAlpha ) );
+ pPix++;
+ }
}
- pRGBWrite->SetPixel( y, x, BitmapColor( nR, nG, nB ) );
- pMaskWrite->SetPixel( y, x, BitmapColor( 255 - nAlpha ) );
- pPix++;
+ aMask.ReleaseAccess( pMaskWrite );
}
+ aRGB.ReleaseAccess( pRGBWrite );
}
- aMask.ReleaseAccess( pMaskWrite );
- aRGB.ReleaseAccess( pRGBWrite );
+ // ignore potential errors above. will get caller a
+ // uniformely white bitmap, but not that there would
+ // be error handling in calling code ...
::BitmapEx *pBitmapEx = new ::BitmapEx( aRGB, aMask );
+ cairo_destroy( pCairo );
cairo_surface_destroy( pPixels );
aRV = uno::Any( reinterpret_cast<sal_Int64>( pBitmapEx ) );