diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2020-05-14 14:42:24 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-05-29 06:23:50 +0200 |
commit | 6806616023242aded27b1fae8637d32c9626d472 (patch) | |
tree | 449da1538f4c08af632315241f476df37bdaa20a | |
parent | 2cfe93da835eb500c9a170d22fce19fbd1de9473 (diff) |
Add AlphaMask::BlendWith method to blend 8-bit alpha masks
Required for subsequent soft edge effect improvement
Change-Id: I9351b827a83c5651100e73a6846c834f491b861d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95027
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | include/vcl/alpha.hxx | 1 | ||||
-rw-r--r-- | vcl/source/gdi/alpha.cxx | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/include/vcl/alpha.hxx b/include/vcl/alpha.hxx index f87ac133970a..159c61243efa 100644 --- a/include/vcl/alpha.hxx +++ b/include/vcl/alpha.hxx @@ -56,6 +56,7 @@ public: void Erase( sal_uInt8 cTransparency ); void Replace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency ); void Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency ); + void BlendWith(const Bitmap& rOther); BitmapReadAccess* AcquireAlphaReadAccess() { return Bitmap::AcquireReadAccess(); } BitmapWriteAccess* AcquireAlphaWriteAccess() { return Bitmap::AcquireWriteAccess(); } diff --git a/vcl/source/gdi/alpha.cxx b/vcl/source/gdi/alpha.cxx index fde0e94583a9..1385f803be8d 100644 --- a/vcl/source/gdi/alpha.cxx +++ b/vcl/source/gdi/alpha.cxx @@ -138,6 +138,29 @@ void AlphaMask::Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransp } } +void AlphaMask::BlendWith(const Bitmap& rOther) +{ + AlphaMask aOther(rOther); // to 8 bits + Bitmap::ScopedReadAccess pOtherAcc(aOther); + AlphaScopedWriteAccess pAcc(*this); + if (pOtherAcc && pAcc && pOtherAcc->GetBitCount() == 8 && pAcc->GetBitCount() == 8) + { + const long nHeight = std::min(pOtherAcc->Height(), pAcc->Height()); + const long nWidth = std::min(pOtherAcc->Width(), pAcc->Width()); + for (long x = 0; x < nWidth; ++x) + { + for (long y = 0; y < nHeight; ++y) + { + // Use sal_uInt16 for following multiplication + const sal_uInt16 nGrey1 = pOtherAcc->GetPixelIndex(y, x); + const sal_uInt16 nGrey2 = pAcc->GetPixelIndex(y, x); + const double fGrey = std::round(nGrey1 + nGrey2 - nGrey1 * nGrey2 / 255.0); + pAcc->SetPixelIndex(y, x, static_cast<sal_uInt8>(fGrey)); + } + } + } +} + void AlphaMask::ReleaseAccess( BitmapReadAccess* pAccess ) { if( pAccess ) |