diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx b/drawinglayer/source/processor2d/vclprocessor2d.cxx index 73e3d8adbac9..575431513e8e 100644 --- a/drawinglayer/source/processor2d/vclprocessor2d.cxx +++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx @@ -553,13 +553,6 @@ void VclProcessor2D::RenderFillGraphicPrimitive2D( return; } - if (rFillBitmapCandidate.hasTransparency()) - { - // cannot handle yet, use decomposition - process(rFillBitmapCandidate); - return; - } - bool bPrimitiveAccepted = RenderFillGraphicPrimitive2DImpl(rFillBitmapCandidate); if (!bPrimitiveAccepted) @@ -649,6 +642,10 @@ bool VclProcessor2D::RenderFillGraphicPrimitive2DImpl( aBitmapEx.Scale(aNeededBitmapSizePixel, BmpScaleFlag::Interpolate); } + if (rFillBitmapCandidate.hasTransparency()) + aBitmapEx.BlendAlpha( + static_cast(255 - (rFillBitmapCandidate.getTransparency() * 255))); + if (maBColorModifierStack.count()) { // when color modifier, apply to bitmap diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx index bfcbaa99e234..feee3c29ab85 100644 --- a/include/vcl/bitmapex.hxx +++ b/include/vcl/bitmapex.hxx @@ -434,8 +434,17 @@ public: SAL_DLLPRIVATE void ChangeColorAlpha( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo ); + /** + * Adds a constant value to the alpha layer + */ SAL_DLLPRIVATE void AdjustTransparency( sal_uInt8 cTrans ); + /** + * Blends, i.e. multiplies the alpha layer with the new alpha value. + */ + void BlendAlpha( sal_uInt8 nAlpha ); + + void CombineMaskOr(Color maskColor, sal_uInt8 nTol); /** diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx index d32f6473a22a..7244869f7b90 100644 --- a/vcl/source/bitmap/BitmapEx.cxx +++ b/vcl/source/bitmap/BitmapEx.cxx @@ -1375,6 +1375,58 @@ void BitmapEx::AdjustTransparency(sal_uInt8 cTrans) *this = BitmapEx( GetBitmap(), aAlpha ); } +void BitmapEx::BlendAlpha(sal_uInt8 nAlpha) +{ + AlphaMask aAlpha; + + if (!IsAlpha()) + { + sal_uInt8 cTrans = 255 - nAlpha; + aAlpha = AlphaMask(GetSizePixel(), &cTrans); + } + else + { + aAlpha = GetAlphaMask(); + BitmapScopedWriteAccess pA(aAlpha); + assert(pA); + + if( !pA ) + return; + + const tools::Long nWidth = pA->Width(), nHeight = pA->Height(); + + if( pA->GetScanlineFormat() == ScanlineFormat::N8BitPal ) + { + for( tools::Long nY = 0; nY < nHeight; nY++ ) + { + Scanline pAScan = pA->GetScanline( nY ); + + for( tools::Long nX = 0; nX < nWidth; nX++ ) + { + sal_uInt8 nNewAlpha = static_cast(nAlpha) * (*pAScan) / 255; + *pAScan++ = nNewAlpha; + } + } + } + else + { + BitmapColor aAlphaValue( 0 ); + + for( tools::Long nY = 0; nY < nHeight; nY++ ) + { + Scanline pScanline = pA->GetScanline( nY ); + for( tools::Long nX = 0; nX < nWidth; nX++ ) + { + sal_uInt8 nNewAlpha = static_cast(nAlpha) * (pA->GetIndexFromData( pScanline, nX )) / 255; + aAlphaValue.SetIndex( nNewAlpha ); + pA->SetPixelOnData( pScanline, nX, aAlphaValue ); + } + } + } + } + *this = BitmapEx( GetBitmap(), aAlpha ); +} + void BitmapEx::CombineMaskOr(Color maskColor, sal_uInt8 nTol) { AlphaMask aNewMask = maBitmap.CreateAlphaMask( maskColor, nTol );