summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-04-16 13:25:05 +0900
committerTomaž Vajngerl <quikee@gmail.com>2019-04-16 11:14:18 +0200
commitba9e513ee8305c668c94b6ba59e26da278581652 (patch)
treed7ad5472a61d730bb05e7ad0df1f2e89e6db6c04 /vcl/qa
parent6fd7495bf6bc4d0f7e788d965a599ca3aab7e928 (diff)
Test an alpha VirtualDevice and fix GetPixel and DrawPixel
This adds an test for a VirtualDevice with an alpha channel, which checks that getting a BitmapEx from the alpha VirtualDevice is has a alpha channel properly set. Test that using GetPixel and DrawPixel properly handle an alpha based Color, which they didn't, so this also includes the fix for thouse 2 methods. Change-Id: I419b8e0f66ab5f8266c6129e501ed75ef517fd44 Reviewed-on: https://gerrit.libreoffice.org/70805 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx69
1 files changed, 69 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
index 5fc6c5b7b53c..efb3dcfbcb2e 100644
--- a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
+++ b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
@@ -42,12 +42,14 @@ public:
void testTdf104141();
void testTdf113918();
void testDrawAlphaBitmapEx();
+ void testAlphaVirtualDevice();
void testTdf116888();
CPPUNIT_TEST_SUITE(BitmapRenderTest);
CPPUNIT_TEST(testTdf104141);
CPPUNIT_TEST(testTdf113918);
CPPUNIT_TEST(testDrawAlphaBitmapEx);
+ CPPUNIT_TEST(testAlphaVirtualDevice);
CPPUNIT_TEST(testTdf116888);
CPPUNIT_TEST_SUITE_END();
@@ -150,6 +152,73 @@ void BitmapRenderTest::testDrawAlphaBitmapEx()
#endif
}
+void BitmapRenderTest::testAlphaVirtualDevice()
+{
+ // Create an alpha virtual device
+ ScopedVclPtr<VirtualDevice> pAlphaVirtualDevice(VclPtr<VirtualDevice>::Create(
+ *Application::GetDefaultDevice(), DeviceFormat::DEFAULT, DeviceFormat::DEFAULT));
+
+ // Set it up
+ pAlphaVirtualDevice->SetOutputSizePixel(Size(4, 4));
+ pAlphaVirtualDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+ pAlphaVirtualDevice->Erase();
+
+ // Get a BitmapEx from the VirDev -> Colors should have alpha
+ BitmapEx aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
+ CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
+ Color aColor = aBitmap.GetPixelColor(1, 1);
+ CPPUNIT_ASSERT_EQUAL(Color(0xff, 0xff, 0xff, 0xff), aColor);
+
+ // Draw an opaque pixel to the VirDev
+ pAlphaVirtualDevice->DrawPixel(Point(1, 1), Color(0x00, 0x22, 0xff, 0x55));
+
+ // Read back the opaque pixel
+#ifdef MACOSX
+ // Oh no.. what we input is not the same as what we get out!
+ CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x2C, 0xff, 0x44), pAlphaVirtualDevice->GetPixel(Point(1, 1)));
+#else
+ CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x22, 0xff, 0x55), pAlphaVirtualDevice->GetPixel(Point(1, 1)));
+#endif
+
+ // Read back the BitmapEx and check the opaque pixel
+ aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
+ CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
+
+ aColor = aBitmap.GetPixelColor(1, 1);
+#ifdef MACOSX
+ // Oh no.. what we input is not the same as what we get out!
+ CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x2C, 0xff, 0x44), aColor);
+#else
+ CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x22, 0xff, 0x55), aColor);
+#endif
+
+ // Draw an semi-transparent pixel
+ pAlphaVirtualDevice->DrawPixel(Point(0, 0), Color(0x44, 0x22, 0xff, 0x55));
+
+ // Read back the semi-transparent pixel
+#ifdef MACOSX
+ // Oh no.. what we input is not the same as what we get out!
+ CPPUNIT_ASSERT_EQUAL(Color(0x34, 0x2C, 0xFF, 0x44), pAlphaVirtualDevice->GetPixel(Point(0, 0)));
+#else
+ CPPUNIT_ASSERT_EQUAL(Color(0x44, 0x22, 0xFF, 0x55), pAlphaVirtualDevice->GetPixel(Point(0, 0)));
+#endif
+
+ // Read back the BitmapEx and check the semi-transparent pixel
+ aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
+ CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
+
+ aColor = aBitmap.GetPixelColor(0, 0);
+#ifdef MACOSX
+ // Oh no.. what we input is not the same as what we get out!
+ CPPUNIT_ASSERT_EQUAL(Color(0x34, 0x2C, 0xFF, 0x44), aColor);
+#else
+ CPPUNIT_ASSERT_EQUAL(Color(0x44, 0x22, 0xFF, 0x55), aColor);
+#endif
+}
+
void BitmapRenderTest::testTdf116888()
{
// The image is a 8bit image with a non-grayscale palette. In OpenGL mode