summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-06-24 10:39:35 +0200
committerLuboš Luňák <l.lunak@collabora.com>2020-06-24 12:41:28 +0200
commit3fc4898473752eaac44f3bc1e0df9eb548974425 (patch)
tree94110c96800a7f563cf44205d1572034e9293c8e /vcl
parentacb7f9e072d55c3f91bec247b809b4d367062f60 (diff)
optimize AlphaMask::BlendWith()
It shows up in profiling in some cases (e.g. tdf#134160). - If it's 8-bit, simply work on scanlines instead of pixel by pixel. - The extra precision from using floats doesn't matter and the round() costs something (at least with MSVC). Change-Id: I37bbe31fae03d61946a7382de1fb79cfe2d2ec30 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97010 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/gdi/alpha.cxx15
1 files changed, 9 insertions, 6 deletions
diff --git a/vcl/source/gdi/alpha.cxx b/vcl/source/gdi/alpha.cxx
index 1385f803be8d..bc1d54f36c22 100644
--- a/vcl/source/gdi/alpha.cxx
+++ b/vcl/source/gdi/alpha.cxx
@@ -147,15 +147,18 @@ void AlphaMask::BlendWith(const Bitmap& rOther)
{
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)
{
- for (long y = 0; y < nHeight; ++y)
+ Scanline scanline = pAcc->GetScanline( y );
+ ConstScanline otherScanline = pOtherAcc->GetScanline( y );
+ for (long x = 0; x < nWidth; ++x)
{
// 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));
+ const sal_uInt16 nGrey1 = *scanline;
+ const sal_uInt16 nGrey2 = *otherScanline;
+ *scanline = static_cast<sal_uInt8>(nGrey1 + nGrey2 - nGrey1 * nGrey2 / 255);
+ ++scanline;
+ ++otherScanline;
}
}
}