[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - 2 commits - drawinglayer/source include/vcl vcl/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Fri May 29 08:30:59 UTC 2020
drawinglayer/source/processor2d/vclpixelprocessor2d.cxx | 11 +++----
include/vcl/alpha.hxx | 1
vcl/source/gdi/alpha.cxx | 23 ++++++++++++++++
3 files changed, 29 insertions(+), 6 deletions(-)
New commits:
commit 2356a687e3abae2eecb9060d52bb4c4fadbaaae2
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu May 14 14:42:24 2020 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri May 29 10:30:31 2020 +0200
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 at collabora.com>
(cherry picked from commit 6806616023242aded27b1fae8637d32c9626d472)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95077
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 )
commit d0aff1174189983a1a090f61a504d6a3c7fca095
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu May 28 12:48:28 2020 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri May 29 10:30:21 2020 +0200
tdf#49247, tdf#101181: don't rely on automatic scaling of alpha mask
Scale it back explicitly in ProcessAndBlurAlphaMask
Change-Id: I8e8a58c117d8b59db40b416edadc559b47dc300a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95021
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
(cherry picked from commit 2cfe93da835eb500c9a170d22fce19fbd1de9473)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95076
diff --git a/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx b/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx
index 32afe33e6147..9e44ef292d34 100644
--- a/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx
@@ -917,18 +917,17 @@ void VclPixelProcessor2D::processMetaFilePrimitive2D(const primitive2d::BasePrim
namespace
{
-/* Returns 8-bit alpha mask created from passed mask. The result may be scaled down; it's
- expected that it will be automatically scaled up back when applied to the bitmap.
+/* Returns 8-bit alpha mask created from passed mask.
Negative fErodeDilateRadius values mean erode, positive - dilate.
nTransparency defines minimal transparency level.
*/
-AlphaMask ProcessAndBlurAlphaMask(const Bitmap& rBWMask, double fErodeDilateRadius,
+AlphaMask ProcessAndBlurAlphaMask(const Bitmap& rMask, double fErodeDilateRadius,
double fBlurRadius, sal_uInt8 nTransparency)
{
// Only completely white pixels on the initial mask must be considered for transparency. Any
// other color must be treated as black. This creates 1-bit B&W bitmap.
- BitmapEx mask(rBWMask.CreateMask(COL_WHITE));
+ BitmapEx mask(rMask.CreateMask(COL_WHITE));
// Scaling down increases performance without noticeable quality loss. Additionally,
// current blur implementation can only handle blur radius between 2 and 254.
@@ -963,6 +962,8 @@ AlphaMask ProcessAndBlurAlphaMask(const Bitmap& rBWMask, double fErodeDilateRadi
// calculate blurry effect
BitmapFilter::Filter(mask, BitmapFilterStackBlur(fBlurRadius));
+ mask.Scale(rMask.GetSizePixel());
+
return AlphaMask(mask.GetBitmap());
}
}
@@ -1005,7 +1006,6 @@ void VclPixelProcessor2D::processGlowPrimitive2D(const primitive2d::GlowPrimitiv
const basegfx::BColor aGlowColor(
maBColorModifierStack.getModifiedColor(rCandidate.getGlowColor().getBColor()));
bitmap.Erase(Color(aGlowColor));
- // alpha mask will be scaled up automatically to match bitmap
BitmapEx result(bitmap, mask);
// back to old OutDev
@@ -1053,7 +1053,6 @@ void VclPixelProcessor2D::processSoftEdgePrimitive2D(
process(rCandidate);
bitmap = mpOutputDevice->GetBitmap(aRect.TopLeft(), aRect.GetSize());
- // alpha mask will be scaled up automatically to match bitmap
BitmapEx result(bitmap, mask);
// back to old OutDev
More information about the Libreoffice-commits
mailing list