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:
parent
717a898b05
commit
a43320a3ad
@ -10,19 +10,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vcl/bitmapex.hxx>
|
||||
#include <vcl/bitmap/BitmapFilter.hxx>
|
||||
|
||||
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: */
|
||||
|
@ -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:
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -14,15 +14,11 @@
|
||||
#include <vcl/BitmapWriteAccess.hxx>
|
||||
#include <vcl/BitmapTools.hxx>
|
||||
|
||||
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: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user