vcl: make BitmapDarkenBlendFilter use BitmapFilter

Change-Id: I2ec47793fa094e452f30f9628c121772db578656
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173743
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Jenkins
This commit is contained in:
Chris Sherlock 2024-09-21 00:58:52 +10:00 committed by Tomaž Vajngerl
parent 717a898b05
commit a43320a3ad
4 changed files with 22 additions and 30 deletions

View File

@ -10,19 +10,17 @@
#pragma once #pragma once
#include <vcl/bitmapex.hxx> #include <vcl/bitmap/BitmapFilter.hxx>
class VCL_DLLPUBLIC BitmapDarkenBlendFilter class VCL_DLLPUBLIC BitmapDarkenBlendFilter : public BitmapFilter
{ {
private: private:
BitmapEx maBitmapEx; BitmapEx maBlendBitmapBitmapEx;
BitmapEx maBitmapEx2;
public: public:
BitmapDarkenBlendFilter(BitmapEx const& rBmpEx, BitmapEx const& rBmpEx2); BitmapDarkenBlendFilter(BitmapEx const& rBitmapBlendEx);
~BitmapDarkenBlendFilter(); virtual BitmapEx execute(BitmapEx const& rBitmapEx) const override;
BitmapEx execute();
}; };
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -169,8 +169,8 @@ void SvgFeBlendNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTar
} }
case Mode::Darken: case Mode::Darken:
{ {
BitmapDarkenBlendFilter aDarkenBlendFilter(aBmpEx, aBmpEx2); BitmapDarkenBlendFilter aDarkenBlendFilter(aBmpEx2);
aResBmpEx = aDarkenBlendFilter.execute(); aResBmpEx = aDarkenBlendFilter.execute(aBmpEx);
break; break;
} }
case Mode::Lighten: case Mode::Lighten:

View File

@ -449,26 +449,23 @@ void BitmapFilterTest::testDarkenBlendFilter()
// same color // same color
{ {
BitmapDarkenBlendFilter* pArithmeticFilter BitmapDarkenBlendFilter aArithmeticFilter(aRedBitmapEx);
= new BitmapDarkenBlendFilter(aRedBitmapEx, aRedBitmapEx); BitmapEx aResBitmapEx = aArithmeticFilter.execute(aRedBitmapEx);
BitmapEx aResBitmapEx = pArithmeticFilter->execute();
CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aResBitmapEx.GetPixelColor(2, 2)); CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aResBitmapEx.GetPixelColor(2, 2));
} }
// different color // different color
{ {
BitmapDarkenBlendFilter* pArithmeticFilter BitmapDarkenBlendFilter aArithmeticFilter(aGreenBitmapEx);
= new BitmapDarkenBlendFilter(aRedBitmapEx, aGreenBitmapEx); BitmapEx aResBitmapEx = aArithmeticFilter.execute(aRedBitmapEx);
BitmapEx aResBitmapEx = pArithmeticFilter->execute();
CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xFF, 0x00, 0x00, 0x00), CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xFF, 0x00, 0x00, 0x00),
aResBitmapEx.GetPixelColor(2, 2)); aResBitmapEx.GetPixelColor(2, 2));
} }
// transparent // transparent
{ {
BitmapDarkenBlendFilter* pArithmeticFilter BitmapDarkenBlendFilter aArithmeticFilter(aTransparentBitmapEx);
= new BitmapDarkenBlendFilter(aRedBitmapEx, aTransparentBitmapEx); BitmapEx aResBitmapEx = aArithmeticFilter.execute(aRedBitmapEx);
BitmapEx aResBitmapEx = pArithmeticFilter->execute();
CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xFF, 0xFF, 0x00, 0x00), CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xFF, 0xFF, 0x00, 0x00),
aResBitmapEx.GetPixelColor(2, 2)); aResBitmapEx.GetPixelColor(2, 2));
} }

View File

@ -14,15 +14,11 @@
#include <vcl/BitmapWriteAccess.hxx> #include <vcl/BitmapWriteAccess.hxx>
#include <vcl/BitmapTools.hxx> #include <vcl/BitmapTools.hxx>
BitmapDarkenBlendFilter::BitmapDarkenBlendFilter(BitmapEx const& rBitmapEx, BitmapDarkenBlendFilter::BitmapDarkenBlendFilter(BitmapEx const& rBitmapBlendEx)
BitmapEx const& rBitmapEx2) : maBlendBitmapBitmapEx(rBitmapBlendEx)
: maBitmapEx(rBitmapEx)
, maBitmapEx2(rBitmapEx2)
{ {
} }
BitmapDarkenBlendFilter::~BitmapDarkenBlendFilter() {}
static sal_uInt8 lcl_calculate(const sal_uInt8 aColor, const sal_uInt8 aAlpha, static sal_uInt8 lcl_calculate(const sal_uInt8 aColor, const sal_uInt8 aAlpha,
const sal_uInt8 aColor2, const sal_uInt8 aAlpha2) 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; 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(); return BitmapEx();
Size aSize = maBitmapEx.GetBitmap().GetSizePixel(); Size aSize = rBitmapBlendEx.GetBitmap().GetSizePixel();
Size aSize2 = maBitmapEx2.GetBitmap().GetSizePixel(); Size aSize2 = maBlendBitmapBitmapEx.GetBitmap().GetSizePixel();
sal_Int32 nHeight = std::min(aSize.getHeight(), aSize2.getHeight()); sal_Int32 nHeight = std::min(aSize.getHeight(), aSize2.getHeight());
sal_Int32 nWidth = std::min(aSize.getWidth(), aSize2.getWidth()); sal_Int32 nWidth = std::min(aSize.getWidth(), aSize2.getWidth());
@ -56,8 +52,8 @@ BitmapEx BitmapDarkenBlendFilter::execute()
Scanline pScanAlpha = pAlphaWriteAccess->GetScanline(y); Scanline pScanAlpha = pAlphaWriteAccess->GetScanline(y);
for (tools::Long x(0); x < nWidth; ++x) for (tools::Long x(0); x < nWidth; ++x)
{ {
BitmapColor i1 = vcl::bitmap::premultiply(maBitmapEx.GetPixelColor(x, y)); BitmapColor i1 = vcl::bitmap::premultiply(rBitmapBlendEx.GetPixelColor(x, y));
BitmapColor i2 = vcl::bitmap::premultiply(maBitmapEx2.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 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 g(lcl_calculate(i1.GetGreen(), i1.GetAlpha(), i2.GetGreen(), i2.GetAlpha()));
sal_uInt8 b(lcl_calculate(i1.GetBlue(), i1.GetAlpha(), i2.GetBlue(), 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)); return BitmapEx(aDstBitmap, AlphaMask(aDstAlpha));
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */