vcl/qa/cppunit/BitmapExTest.cxx |   61 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

New commits:
commit cdf4b60e3ed8beafc573ed9741a7828e299f14cc
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Sep 12 15:21:02 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Sep 12 19:30:31 2023 +0200

    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.gran...@collabora.co.uk>

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);

Reply via email to