diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-09-12 15:21:02 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-09-12 19:30:31 +0200 |
commit | cdf4b60e3ed8beafc573ed9741a7828e299f14cc (patch) | |
tree | 8198595d9a2e32214ef4c66aaeed30918529a7e1 | |
parent | 2f6b4fcd380e227a8767f08b3b4853db5743db40 (diff) |
add a unit test for AlphaMask::BlendWith
Change-Id: Id4602470292d0ba66601c5d2446a06df7e4b508b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156851
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | vcl/qa/cppunit/BitmapExTest.cxx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/BitmapExTest.cxx b/vcl/qa/cppunit/BitmapExTest.cxx index a8f1e5a9cda5..9e5da1c9fab6 100644 --- a/vcl/qa/cppunit/BitmapExTest.cxx +++ b/vcl/qa/cppunit/BitmapExTest.cxx @@ -24,11 +24,13 @@ class BitmapExTest : public CppUnit::TestFixture void testGetPixelColor24_8(); void testGetPixelColor32(); void testTransformBitmapEx(); + void testAlphaBlendWith(); CPPUNIT_TEST_SUITE(BitmapExTest); CPPUNIT_TEST(testGetPixelColor24_8); CPPUNIT_TEST(testGetPixelColor32); CPPUNIT_TEST(testTransformBitmapEx); + CPPUNIT_TEST(testAlphaBlendWith); CPPUNIT_TEST_SUITE_END(); }; @@ -106,6 +108,65 @@ void BitmapExTest::testTransformBitmapEx() } } +void BitmapExTest::testAlphaBlendWith() +{ + AlphaMask alpha(Size(1, 1)); + AlphaMask bitmap(Size(1, 1)); + + // Just test a handful of combinations to make sure the algorithm doesn't + // change (as happened when I did some 32-bit alpha changes) + + // Note that Erase() takes a transparency value, but we get alpha values in GetPixelIndex. + + alpha.Erase(64); + bitmap.Erase(64); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 112), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); + + alpha.Erase(12); + bitmap.Erase(64); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 73), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); + + alpha.Erase(12); + bitmap.Erase(12); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 24), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); + + alpha.Erase(127); + bitmap.Erase(13); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 134), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); + + alpha.Erase(255); + bitmap.Erase(255); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 255), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); + + alpha.Erase(0); + bitmap.Erase(255); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 255), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); + + alpha.Erase(255); + bitmap.Erase(0); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 255), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); + + alpha.Erase(0); + bitmap.Erase(0); + alpha.BlendWith(bitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(255 - 0), + AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); +} + } // namespace CPPUNIT_TEST_SUITE_REGISTRATION(BitmapExTest); |