diff options
author | Michael Meeks <michael.meeks@suse.com> | 2013-06-10 17:02:06 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-06-11 14:41:50 +0100 |
commit | 7cf2b5809f7137acc7a5eed9159042b3d748da01 (patch) | |
tree | 518eec0a6e6c86da259d680c194f55b8946db9dc /vcl | |
parent | 03b4c0e0724f9928e00abd822bd846c6e200fa14 (diff) |
Cairo canvas fixes
+ Move BitmapEx construction from an XBitmapCanvas into BitmapEx
where (arguably) it will be easier to re-factor later, treat a
mask fetch failure as if we have no mask
+ Teach the cairo canvas to return a non-pre-multiplied RGB +
separate Alpha BitmapEx when it can to avoid unpleasantness with
the underlying X resources.
+ Add tentative code-path to convert 32bit color Bitmaps into
24bit color, to avoid confusing X
Change-Id: Iaf6998c796aea6d73c57bed2bc03152d9636d5f5
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/bitmapex.cxx | 78 | ||||
-rw-r--r-- | vcl/source/gdi/gdimtf.cxx | 25 |
2 files changed, 79 insertions, 24 deletions
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx index 8e769c1af8d4..5ac3c36c41c1 100644 --- a/vcl/source/gdi/bitmapex.cxx +++ b/vcl/source/gdi/bitmapex.cxx @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include <ctype.h> #include <rtl/crc.h> @@ -39,6 +38,13 @@ #include <image.h> #include <impimagetree.hxx> +// BitmapEx::Create +#include <salbmp.hxx> +#include <salinst.hxx> +#include <svdata.hxx> +#include <com/sun/star/beans/XFastPropertySet.hpp> +using namespace ::com::sun::star; + BitmapEx::BitmapEx() : eTransparent( TRANSPARENT_NONE ), bAlpha ( sal_False ) @@ -873,4 +879,74 @@ SvStream& operator>>( SvStream& rIStm, BitmapEx& rBitmapEx ) return rIStm; } +// Shift alpha transparent pixels between cppcanvas/ implementations +// and vcl in a generally grotesque and under-performing fashion +bool BitmapEx::Create( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XBitmapCanvas > &xBitmapCanvas, + const Size &rSize ) +{ + SetEmpty(); + Size aSize( rSize ); + + uno::Reference< beans::XFastPropertySet > xFastPropertySet( xBitmapCanvas, uno::UNO_QUERY ); + if( xFastPropertySet.get() ) + { + // 0 means get BitmapEx + uno::Any aAny = xFastPropertySet->getFastPropertyValue( 0 ); + BitmapEx* pBitmapEx = (BitmapEx*) *reinterpret_cast<const sal_Int64*>(aAny.getValue()); + if( pBitmapEx ) + { + *this = *pBitmapEx; + delete pBitmapEx; + return true; + } + } + + SalBitmap* pSalBmp, *pSalMask; + + pSalBmp = ImplGetSVData()->mpDefInst->CreateSalBitmap(); + pSalMask = ImplGetSVData()->mpDefInst->CreateSalBitmap(); + + if( pSalBmp->Create( xBitmapCanvas, aSize ) ) + { +#ifdef CLAMP_BITDEPTH_PARANOIA + // did we get alpha mixed up in the bitmap itself + // eg. Cairo Canvas ... yes performance of this is awful. + if( pSalBmp->GetBitCount() > 24 ) + { + // Format convert the pixels with generic code + Bitmap aSrcPixels( pSalBmp ); + aBitmap = Bitmap( rSize, 24 ); + BitmapReadAccess aSrcRead( aSrcPixels ); + BitmapWriteAccess aDestWrite( aBitmap ); + aDestWrite.CopyBuffer( aSrcRead ); + } + else +#endif + aBitmap = Bitmap( pSalBmp ); + + aBitmapSize = rSize; + if ( pSalMask->Create( xBitmapCanvas, aSize, true ) ) + { + aMask = Bitmap( pSalMask ); + bAlpha = sal_True; + aBitmapSize = rSize; + eTransparent = !aMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP; + + return true; + } + else + { + bAlpha = sal_False; + eTransparent = TRANSPARENT_NONE; + return true; + } + } + + delete pSalBmp; + delete pSalMask; + + return false; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index 2195f23fa7ea..fce3d091ab9c 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -432,36 +432,15 @@ bool GDIMetaFile::ImplPlayWithRenderer( OutputDevice* pOut, const Point& rPos, S xMtfRenderer->draw( rDestSize.Width(), rDestSize.Height() ); - uno::Reference< beans::XFastPropertySet > xFastPropertySet( xBitmapCanvas, uno::UNO_QUERY ); - if( xFastPropertySet.get() ) + BitmapEx aBitmapEx; + if( aBitmapEx.Create( xBitmapCanvas, aSize ) ) { - // 0 means get BitmapEx - uno::Any aAny = xFastPropertySet->getFastPropertyValue( 0 ); - BitmapEx* pBitmapEx = (BitmapEx*) *reinterpret_cast<const sal_Int64*>(aAny.getValue()); - if( pBitmapEx ) { - pOut->DrawBitmapEx( rPos, rLogicDestSize, *pBitmapEx ); - delete pBitmapEx; - return true; - } - } - - SalBitmap* pSalBmp = ImplGetSVData()->mpDefInst->CreateSalBitmap(); - SalBitmap* pSalMask = ImplGetSVData()->mpDefInst->CreateSalBitmap(); - if( pSalBmp->Create( xBitmapCanvas, aSize ) && pSalMask->Create( xBitmapCanvas, aSize, true ) ) - { - Bitmap aBitmap( pSalBmp ); - Bitmap aMask( pSalMask ); - AlphaMask aAlphaMask( aMask ); - BitmapEx aBitmapEx( aBitmap, aAlphaMask ); if ( pOut->GetMapMode() == MAP_PIXEL ) pOut->DrawBitmapEx( rPos, aBitmapEx ); else pOut->DrawBitmapEx( rPos, rLogicDestSize, aBitmapEx ); return true; } - - delete pSalBmp; - delete pSalMask; } } } |