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-12 09:54:57 +0100 |
commit | d6f58fd25eeca84a94528409a05b80aa5172b8b8 (patch) | |
tree | f101366385d1ead118ab59a71b998a71dfff0d54 /vcl/source/gdi | |
parent | 352580fedebcb9ae3c4200d343f88f98b9faa22a (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
Conflicts:
vcl/source/gdi/gdimtf.cxx
Diffstat (limited to 'vcl/source/gdi')
-rw-r--r-- | vcl/source/gdi/bitmapex.cxx | 78 | ||||
-rw-r--r-- | vcl/source/gdi/gdimtf.cxx | 35 |
2 files changed, 85 insertions, 28 deletions
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx index 45fe0aa925ec..59fc06a503ed 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 ) @@ -856,4 +862,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 33e304bbc150..f43b6ca4f6b2 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -487,35 +487,16 @@ bool GDIMetaFile::ImplPlayWithRenderer( OutputDevice* pOut, const Point& rPos, S xMtfFastPropertySet->setFastPropertyValue( 0, uno::Any( reinterpret_cast<sal_Int64>( this ) ) ); xMtfRenderer->draw( rDestSize.Width(), rDestSize.Height() ); + } - 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 ) { - 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 ); + BitmapEx aBitmapEx; + if( aBitmapEx.Create( xBitmapCanvas, aSize ) ) + { + if ( pOut->GetMapMode() == MAP_PIXEL ) pOut->DrawBitmapEx( rPos, aBitmapEx ); - return true; - } - - delete pSalBmp; - delete pSalMask; + else + pOut->DrawBitmapEx( rPos, rLogicDestSize, aBitmapEx ); + return true; } } } |