diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-04-16 13:10:11 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-04-16 07:20:00 +0200 |
commit | d7263d05bdcbe7e219664e198154e31a986c68fc (patch) | |
tree | 117e3aebd6b36c0b66c2c54609e61bd4f0402a24 /vcl/qa | |
parent | 8d65b2bafa1ee000b2722c3c5e6d45a62b74c196 (diff) |
Test drawing BitmapEx with an alpha channel on a VirtualDevice
This adds a test for drawing a BitmapEx which has an alpha channel
onto a VirtualDevice. Most important is that alpha blending is
done as we expect it (but it is prone to rounding error).
Change-Id: I41a16ca9da98d7a067ada9aafad8c9fc7c6484d5
Reviewed-on: https://gerrit.libreoffice.org/70804
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx index 531494205c14..5fc6c5b7b53c 100644 --- a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx +++ b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx @@ -13,7 +13,7 @@ #include <vcl/virdev.hxx> #include <vcl/salbtype.hxx> #include <vcl/bitmapaccess.hxx> -#include <vcl/wrkwin.hxx> +#include <vcl/svapp.hxx> #include <tools/stream.hxx> #include <vcl/pngwrite.hxx> @@ -21,6 +21,9 @@ #include <vcl/graphicfilter.hxx> #include <vcl/filter/PngImageReader.hxx> +#include <svdata.hxx> +#include <salinst.hxx> + static OUString const gaDataUrl = "/vcl/qa/cppunit/bitmaprender/data/"; class BitmapRenderTest : public test::BootstrapFixture @@ -38,13 +41,13 @@ public: void testTdf104141(); void testTdf113918(); - void testDrawBitmap32(); + void testDrawAlphaBitmapEx(); void testTdf116888(); CPPUNIT_TEST_SUITE(BitmapRenderTest); CPPUNIT_TEST(testTdf104141); CPPUNIT_TEST(testTdf113918); - CPPUNIT_TEST(testDrawBitmap32); + CPPUNIT_TEST(testDrawAlphaBitmapEx); CPPUNIT_TEST(testTdf116888); CPPUNIT_TEST_SUITE_END(); @@ -101,7 +104,7 @@ void BitmapRenderTest::testTdf113918() CPPUNIT_ASSERT(aColor.GetGreen() > 100); } -void BitmapRenderTest::testDrawBitmap32() +void BitmapRenderTest::testDrawAlphaBitmapEx() { ScopedVclPtrInstance<VirtualDevice> pVDev; pVDev->SetOutputSizePixel(Size(8, 8)); @@ -117,10 +120,29 @@ void BitmapRenderTest::testDrawBitmap32() vcl::PngImageReader aPngReader(aFileStream); BitmapEx aBitmapEx; aPngReader.read(aBitmapEx); + + // Check backend capabilities, if the backend support 32-bit bitmap + auto pBackendCapabilities = ImplGetSVData()->mpDefInst->GetBackendCapabilities(); + if (pBackendCapabilities->mbSupportsBitmap32) + { + CPPUNIT_ASSERT_EQUAL(sal_uInt16(32), aBitmapEx.GetBitmap().GetBitCount()); + } + else + { + CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), aBitmapEx.GetBitmap().GetBitCount()); + CPPUNIT_ASSERT_EQUAL(true, aBitmapEx.IsAlpha()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), aBitmapEx.GetAlpha().GetBitCount()); + } + + // Check the bitmap has pixels we expect + CPPUNIT_ASSERT_EQUAL(Color(0xFF, 0x00, 0x00, 0x00), aBitmapEx.GetPixelColor(0, 0)); + CPPUNIT_ASSERT_EQUAL(Color(0x00, 0xFF, 0xFF, 0x00), aBitmapEx.GetPixelColor(1, 1)); + CPPUNIT_ASSERT_EQUAL(Color(0x7F, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(2, 2)); + pVDev->DrawBitmapEx(Point(), aBitmapEx); - CPPUNIT_ASSERT_EQUAL(COL_WHITE, pVDev->GetPixel(Point(0, 0))); - CPPUNIT_ASSERT_EQUAL(COL_YELLOW, pVDev->GetPixel(Point(1, 1))); + CPPUNIT_ASSERT_EQUAL(Color(0x00, 0xFF, 0xFF, 0xFF), pVDev->GetPixel(Point(0, 0))); + CPPUNIT_ASSERT_EQUAL(Color(0x00, 0xFF, 0xFF, 0x00), pVDev->GetPixel(Point(1, 1))); // sometimes on Windows we get rounding error in blending so let's ignore this on Windows for now. #if !defined(_WIN32) |