vcl: test BitmapAlphaClampFilter

Change-Id: Ie44884a3010cd26b057bac593059a4bd0a3aabc8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173345
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Chris Sherlock
2024-09-14 01:04:55 +10:00
committed by Tomaž Vajngerl
parent 393b1a5de4
commit 05c01410f3
2 changed files with 20 additions and 2 deletions

View File

@@ -10,12 +10,11 @@
#pragma once
#include <config_options.h>
#include <vcl/BitmapFilter.hxx>
/** If the alpha is beyond a certain threshold, make it fully transparent
*/
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) BitmapAlphaClampFilter final : public BitmapFilter
class VCL_DLLPUBLIC BitmapAlphaClampFilter final : public BitmapFilter
{
public:
BitmapAlphaClampFilter(sal_uInt8 cThreshold)

View File

@@ -15,6 +15,7 @@
#include <tools/stream.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/BitmapAlphaClampFilter.hxx>
#include <vcl/BitmapArithmeticBlendFilter.hxx>
#include <vcl/BitmapDarkenBlendFilter.hxx>
#include <vcl/BitmapLightenBlendFilter.hxx>
@@ -41,6 +42,7 @@ public:
{
}
void testClampAlpha();
void testBlurCorrectness();
void testBasicMorphology();
void testPerformance();
@@ -53,6 +55,7 @@ public:
void testArithmeticBlendFilter();
CPPUNIT_TEST_SUITE(BitmapFilterTest);
CPPUNIT_TEST(testClampAlpha);
CPPUNIT_TEST(testBlurCorrectness);
CPPUNIT_TEST(testBasicMorphology);
CPPUNIT_TEST(testPerformance);
@@ -91,6 +94,22 @@ private:
}
};
void BitmapFilterTest::testClampAlpha()
{
// Setup test bitmap
Size aSize(1, 1);
Bitmap aBitmap24Bit(aSize, vcl::PixelFormat::N24_BPP);
{
BitmapScopedWriteAccess aWriteAccess(aBitmap24Bit);
aWriteAccess->Erase(COL_RED);
}
BitmapEx aBitmapEx24Bit(aBitmap24Bit);
BitmapFilter::Filter(aBitmapEx24Bit, BitmapAlphaClampFilter(0x7F));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(0xFF), aBitmapEx24Bit.GetAlpha(0, 0));
}
void BitmapFilterTest::testBlurCorrectness()
{
// Setup test bitmap