vcl/source/outdev/bitmap.cxx | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
New commits: commit e68ae6bbdaa9b39949c7e1215e48ef31f0e32efd Author: Christopher Sherlock <chris.sherloc...@gmail.com> AuthorDate: Sat Aug 2 16:18:40 2025 +1000 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Aug 8 09:24:03 2025 +0200 vcl: lcl_AlphaBlend() simplify to mix a color with another with an alpha value Change-Id: I72725af813935bf2788618ef9f34eeef2ad1bbf2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188800 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx index 3c91094fa025..bd49345c8acd 100644 --- a/vcl/source/outdev/bitmap.cxx +++ b/vcl/source/outdev/bitmap.cxx @@ -421,31 +421,24 @@ sal_uInt8 lcl_CalcColor( const sal_uInt8 nSourceColor, const sal_uInt8 nSourceAl return sal_uInt8( c ); } -BitmapColor lcl_AlphaBlend(int nX, int nY, - const tools::Long nMapX, - const tools::Long nMapY, - BitmapReadAccess const* pSrcBmp, - BitmapReadAccess const* pSrcAlphaBmp, - BitmapReadAccess const* pDstBmp) -{ - const BitmapColor aSrcCol = pSrcBmp->GetColor(nMapY, nMapX); - BitmapColor aDstCol = pDstBmp->GetColor(nY, nX); +// blend one color with another color with an alpha value - const sal_uInt8 nSrcAlpha = pSrcAlphaBmp->GetPixelIndex(nMapY, nMapX); - const sal_uInt8 nDstAlpha = aDstCol.GetAlpha(); +BitmapColor lcl_AlphaBlend(const BitmapColor& rCol1, const BitmapColor& rCol2, const sal_uInt8 nAlpha) +{ + BitmapColor aCol(rCol2); // Perform porter-duff compositing 'over' operation // Co = Cs + Cd*(1-As) // Ad = As + Ad*(1-As) - sal_uInt8 nResAlpha = static_cast<int>(nSrcAlpha) + static_cast<int>(nDstAlpha) - - static_cast<int>(nDstAlpha) * nSrcAlpha / 255; - aDstCol.SetAlpha(nResAlpha); - aDstCol.SetRed(lcl_CalcColor(aSrcCol.GetRed(), nSrcAlpha, nDstAlpha, nResAlpha, aDstCol.GetRed())); - aDstCol.SetBlue(lcl_CalcColor(aSrcCol.GetBlue(), nSrcAlpha, nDstAlpha, nResAlpha, aDstCol.GetBlue())); - aDstCol.SetGreen(lcl_CalcColor(aSrcCol.GetGreen(), nSrcAlpha, nDstAlpha, nResAlpha, aDstCol.GetGreen())); - - return aDstCol; + sal_uInt8 nResAlpha = static_cast<int>(nAlpha) + static_cast<int>(rCol2.GetAlpha()) + - static_cast<int>(rCol2.GetAlpha()) * nAlpha / 255; + aCol.SetAlpha(nResAlpha); + aCol.SetRed(lcl_CalcColor(rCol1.GetRed(), nAlpha, rCol2.GetAlpha(), nResAlpha, aCol.GetRed())); + aCol.SetBlue(lcl_CalcColor(rCol1.GetBlue(), nAlpha, rCol2.GetAlpha(), nResAlpha, aCol.GetBlue())); + aCol.SetGreen(lcl_CalcColor(rCol1.GetGreen(), nAlpha, rCol2.GetAlpha(), nResAlpha, aCol.GetGreen())); + + return aCol; } Bitmap lcl_BlendBitmapWithAlpha( @@ -471,8 +464,9 @@ Bitmap lcl_BlendBitmapWithAlpha( for( int nX = 0; nX < nDstWidth; nX++ ) { - const tools::Long nMapX = pMapX[ nX ]; - BitmapColor aDstCol = lcl_AlphaBlend(nX, nY, nMapX, nMapY, pSrcBmp, pSrcAlphaBmp, pDstBmp.get()); + BitmapColor aDstCol = lcl_AlphaBlend(pSrcBmp->GetColor(nMapY, pMapX[nX]), + pDstBmp->GetColor(nY, nX), + pSrcAlphaBmp->GetPixelIndex(nMapY, pMapX[nX])); pDstBmp->SetPixelOnData(pScanlineB, nX, aDstCol); }