From a43320a3ad867d65a9d9c8b332abc4dad10b430e Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Sat, 21 Sep 2024 00:58:52 +1000 Subject: [PATCH] vcl: make BitmapDarkenBlendFilter use BitmapFilter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2ec47793fa094e452f30f9628c121772db578656 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173743 Reviewed-by: Tomaž Vajngerl Tested-by: Jenkins --- .../vcl/bitmap/BitmapDarkenBlendFilter.hxx | 12 +++++------ svgio/source/svgreader/svgfeblendnode.cxx | 4 ++-- vcl/qa/cppunit/BitmapFilterTest.cxx | 15 ++++++------- vcl/source/bitmap/BitmapDarkenBlendFilter.cxx | 21 ++++++++----------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/include/vcl/bitmap/BitmapDarkenBlendFilter.hxx b/include/vcl/bitmap/BitmapDarkenBlendFilter.hxx index 541ff1af22e5..527eac27efb9 100644 --- a/include/vcl/bitmap/BitmapDarkenBlendFilter.hxx +++ b/include/vcl/bitmap/BitmapDarkenBlendFilter.hxx @@ -10,19 +10,17 @@ #pragma once -#include +#include -class VCL_DLLPUBLIC BitmapDarkenBlendFilter +class VCL_DLLPUBLIC BitmapDarkenBlendFilter : public BitmapFilter { private: - BitmapEx maBitmapEx; - BitmapEx maBitmapEx2; + BitmapEx maBlendBitmapBitmapEx; public: - BitmapDarkenBlendFilter(BitmapEx const& rBmpEx, BitmapEx const& rBmpEx2); + BitmapDarkenBlendFilter(BitmapEx const& rBitmapBlendEx); - ~BitmapDarkenBlendFilter(); - BitmapEx execute(); + virtual BitmapEx execute(BitmapEx const& rBitmapEx) const override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/source/svgreader/svgfeblendnode.cxx b/svgio/source/svgreader/svgfeblendnode.cxx index cbd24b5b5d55..b5380b0a6fe4 100644 --- a/svgio/source/svgreader/svgfeblendnode.cxx +++ b/svgio/source/svgreader/svgfeblendnode.cxx @@ -169,8 +169,8 @@ void SvgFeBlendNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTar } case Mode::Darken: { - BitmapDarkenBlendFilter aDarkenBlendFilter(aBmpEx, aBmpEx2); - aResBmpEx = aDarkenBlendFilter.execute(); + BitmapDarkenBlendFilter aDarkenBlendFilter(aBmpEx2); + aResBmpEx = aDarkenBlendFilter.execute(aBmpEx); break; } case Mode::Lighten: diff --git a/vcl/qa/cppunit/BitmapFilterTest.cxx b/vcl/qa/cppunit/BitmapFilterTest.cxx index 9a7c00a1d0fa..eace3bbde1bc 100644 --- a/vcl/qa/cppunit/BitmapFilterTest.cxx +++ b/vcl/qa/cppunit/BitmapFilterTest.cxx @@ -449,26 +449,23 @@ void BitmapFilterTest::testDarkenBlendFilter() // same color { - BitmapDarkenBlendFilter* pArithmeticFilter - = new BitmapDarkenBlendFilter(aRedBitmapEx, aRedBitmapEx); - BitmapEx aResBitmapEx = pArithmeticFilter->execute(); + BitmapDarkenBlendFilter aArithmeticFilter(aRedBitmapEx); + BitmapEx aResBitmapEx = aArithmeticFilter.execute(aRedBitmapEx); CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aResBitmapEx.GetPixelColor(2, 2)); } // different color { - BitmapDarkenBlendFilter* pArithmeticFilter - = new BitmapDarkenBlendFilter(aRedBitmapEx, aGreenBitmapEx); - BitmapEx aResBitmapEx = pArithmeticFilter->execute(); + BitmapDarkenBlendFilter aArithmeticFilter(aGreenBitmapEx); + BitmapEx aResBitmapEx = aArithmeticFilter.execute(aRedBitmapEx); CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xFF, 0x00, 0x00, 0x00), aResBitmapEx.GetPixelColor(2, 2)); } // transparent { - BitmapDarkenBlendFilter* pArithmeticFilter - = new BitmapDarkenBlendFilter(aRedBitmapEx, aTransparentBitmapEx); - BitmapEx aResBitmapEx = pArithmeticFilter->execute(); + BitmapDarkenBlendFilter aArithmeticFilter(aTransparentBitmapEx); + BitmapEx aResBitmapEx = aArithmeticFilter.execute(aRedBitmapEx); CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xFF, 0xFF, 0x00, 0x00), aResBitmapEx.GetPixelColor(2, 2)); } diff --git a/vcl/source/bitmap/BitmapDarkenBlendFilter.cxx b/vcl/source/bitmap/BitmapDarkenBlendFilter.cxx index 2924a78c7e11..a5812d65ccd9 100644 --- a/vcl/source/bitmap/BitmapDarkenBlendFilter.cxx +++ b/vcl/source/bitmap/BitmapDarkenBlendFilter.cxx @@ -14,15 +14,11 @@ #include #include -BitmapDarkenBlendFilter::BitmapDarkenBlendFilter(BitmapEx const& rBitmapEx, - BitmapEx const& rBitmapEx2) - : maBitmapEx(rBitmapEx) - , maBitmapEx2(rBitmapEx2) +BitmapDarkenBlendFilter::BitmapDarkenBlendFilter(BitmapEx const& rBitmapBlendEx) + : maBlendBitmapBitmapEx(rBitmapBlendEx) { } -BitmapDarkenBlendFilter::~BitmapDarkenBlendFilter() {} - static sal_uInt8 lcl_calculate(const sal_uInt8 aColor, const sal_uInt8 aAlpha, const sal_uInt8 aColor2, const sal_uInt8 aAlpha2) { @@ -34,13 +30,13 @@ static sal_uInt8 lcl_calculate(const sal_uInt8 aColor, const sal_uInt8 aAlpha, return result * 255.0; } -BitmapEx BitmapDarkenBlendFilter::execute() +BitmapEx BitmapDarkenBlendFilter::execute(BitmapEx const& rBitmapBlendEx) const { - if (maBitmapEx.IsEmpty() || maBitmapEx2.IsEmpty()) + if (rBitmapBlendEx.IsEmpty() || maBlendBitmapBitmapEx.IsEmpty()) return BitmapEx(); - Size aSize = maBitmapEx.GetBitmap().GetSizePixel(); - Size aSize2 = maBitmapEx2.GetBitmap().GetSizePixel(); + Size aSize = rBitmapBlendEx.GetBitmap().GetSizePixel(); + Size aSize2 = maBlendBitmapBitmapEx.GetBitmap().GetSizePixel(); sal_Int32 nHeight = std::min(aSize.getHeight(), aSize2.getHeight()); sal_Int32 nWidth = std::min(aSize.getWidth(), aSize2.getWidth()); @@ -56,8 +52,8 @@ BitmapEx BitmapDarkenBlendFilter::execute() Scanline pScanAlpha = pAlphaWriteAccess->GetScanline(y); for (tools::Long x(0); x < nWidth; ++x) { - BitmapColor i1 = vcl::bitmap::premultiply(maBitmapEx.GetPixelColor(x, y)); - BitmapColor i2 = vcl::bitmap::premultiply(maBitmapEx2.GetPixelColor(x, y)); + BitmapColor i1 = vcl::bitmap::premultiply(rBitmapBlendEx.GetPixelColor(x, y)); + BitmapColor i2 = vcl::bitmap::premultiply(maBlendBitmapBitmapEx.GetPixelColor(x, y)); sal_uInt8 r(lcl_calculate(i1.GetRed(), i1.GetAlpha(), i2.GetRed(), i2.GetAlpha())); sal_uInt8 g(lcl_calculate(i1.GetGreen(), i1.GetAlpha(), i2.GetGreen(), i2.GetAlpha())); sal_uInt8 b(lcl_calculate(i1.GetBlue(), i1.GetAlpha(), i2.GetBlue(), i2.GetAlpha())); @@ -74,4 +70,5 @@ BitmapEx BitmapDarkenBlendFilter::execute() return BitmapEx(aDstBitmap, AlphaMask(aDstAlpha)); } + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */