include/vcl/bitmapex.hxx | 2 +- vcl/source/bitmap/BitmapEx.cxx | 12 ++++++------ vcl/source/graphic/UnoGraphic.cxx | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-)
New commits: commit b00c1ea3c41aabd47f4965620e60462627f8ed26 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jan 9 14:06:49 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Jan 10 10:45:58 2023 +0000 rename setAlphaFrom->ChangeColorAlpha and fix parameter The nAlphaTo parameter was actually transparency. Change the implementation and the call sites to actually use alpha. Also remove one of the calls in Graphic::colorChange, because if the BitmapEx has no alpha channel, the call was going to do nothing anyway. Change-Id: I0bf27835b62596ac7c497c8606ceba04fcf859a1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145205 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx index f847c9f6dcb2..6d86d0633f64 100644 --- a/include/vcl/bitmapex.hxx +++ b/include/vcl/bitmapex.hxx @@ -434,7 +434,7 @@ public: const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas, const Size &rSize ); - void setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo ); + void ChangeColorAlpha( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo ); void AdjustTransparency( sal_uInt8 cTrans ); diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx index a770f2acfc8d..2aeccf83c879 100644 --- a/vcl/source/bitmap/BitmapEx.cxx +++ b/vcl/source/bitmap/BitmapEx.cxx @@ -1357,24 +1357,24 @@ tools::Polygon BitmapEx::GetContour( bool bContourEdgeDetect, return aRetPoly; } -void BitmapEx::setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo ) +void BitmapEx::ChangeColorAlpha( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo ) { AlphaMask aAlphaMask(GetAlpha()); - BitmapScopedWriteAccess pWriteAccess(aAlphaMask); + BitmapScopedWriteAccess pAlphaWriteAccess(aAlphaMask); Bitmap::ScopedReadAccess pReadAccess(maBitmap); - assert( pReadAccess.get() && pWriteAccess.get() ); - if ( !(pReadAccess.get() && pWriteAccess.get()) ) + assert( pReadAccess.get() && pAlphaWriteAccess.get() ); + if ( !(pReadAccess.get() && pAlphaWriteAccess.get()) ) return; for ( tools::Long nY = 0; nY < pReadAccess->Height(); nY++ ) { - Scanline pScanline = pWriteAccess->GetScanline( nY ); + Scanline pScanline = pAlphaWriteAccess->GetScanline( nY ); Scanline pScanlineRead = pReadAccess->GetScanline( nY ); for ( tools::Long nX = 0; nX < pReadAccess->Width(); nX++ ) { const sal_uInt8 cIndex = pReadAccess->GetPixelFromData( pScanlineRead, nX ).GetIndex(); if ( cIndex == cIndexFrom ) - pWriteAccess->SetPixelOnData( pScanline, nX, BitmapColor(nAlphaTo) ); + pAlphaWriteAccess->SetPixelOnData( pScanline, nX, BitmapColor(255 - nAlphaTo) ); } } *this = BitmapEx( GetBitmap(), aAlphaMask ); diff --git a/vcl/source/graphic/UnoGraphic.cxx b/vcl/source/graphic/UnoGraphic.cxx index 4d5f42dfcf82..60d6d9cce86e 100644 --- a/vcl/source/graphic/UnoGraphic.cxx +++ b/vcl/source/graphic/UnoGraphic.cxx @@ -211,7 +211,7 @@ uno::Reference< graphic::XGraphic > SAL_CALL Graphic::colorChange( if (aBitmapEx.IsAlpha()) { - aBitmapEx.setAlphaFrom( cIndexFrom, 0xff - nAlphaTo ); + aBitmapEx.ChangeColorAlpha( cIndexFrom, nAlphaTo ); aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance); aReturnGraphic = ::Graphic(aBitmapEx); } @@ -226,7 +226,6 @@ uno::Reference< graphic::XGraphic > SAL_CALL Graphic::colorChange( } else { - aBitmapEx.setAlphaFrom(cIndexFrom, nAlphaTo); aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance); aReturnGraphic = ::Graphic(aBitmapEx); }