vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx | 69 +++++++++++++++++++++++ vcl/source/outdev/pixel.cxx | 29 ++++++--- 2 files changed, 88 insertions(+), 10 deletions(-)
New commits: commit ba9e513ee8305c668c94b6ba59e26da278581652 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Tue Apr 16 13:25:05 2019 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Tue Apr 16 11:14:18 2019 +0200 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 <[email protected]> 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 diff --git a/vcl/source/outdev/pixel.cxx b/vcl/source/outdev/pixel.cxx index b00835fe96db..ecde4564f4ac 100644 --- a/vcl/source/outdev/pixel.cxx +++ b/vcl/source/outdev/pixel.cxx @@ -32,20 +32,26 @@ #include <outdata.hxx> #include <salgdi.hxx> -Color OutputDevice::GetPixel( const Point& rPt ) const +Color OutputDevice::GetPixel(const Point& rPoint) const { Color aColor; - if ( mpGraphics || AcquireGraphics() ) + if (mpGraphics || AcquireGraphics()) { - if ( mbInitClipRegion ) + if (mbInitClipRegion) const_cast<OutputDevice*>(this)->InitClipRegion(); - if ( !mbOutputClipped ) + if (!mbOutputClipped) { - const long nX = ImplLogicXToDevicePixel( rPt.X() ); - const long nY = ImplLogicYToDevicePixel( rPt.Y() ); - aColor = mpGraphics->GetPixel( nX, nY, this ); + const long nX = ImplLogicXToDevicePixel(rPoint.X()); + const long nY = ImplLogicYToDevicePixel(rPoint.Y()); + aColor = mpGraphics->GetPixel(nX, nY, this); + + if (mpAlphaVDev) + { + Color aAlphaColor = mpAlphaVDev->GetPixel(rPoint); + aColor.SetTransparency(aAlphaColor.GetBlue()); + } } } return aColor; @@ -90,7 +96,7 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor ) if ( mpMetaFile ) mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) ); - if ( !IsDeviceOutputNecessary() || ImplIsColorTransparent( aColor ) || ImplIsRecordLayout() ) + if ( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) return; Point aPt = ImplLogicToDevicePixel( rPt ); @@ -106,8 +112,11 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor ) mpGraphics->DrawPixel( aPt.X(), aPt.Y(), aColor, this ); - if( mpAlphaVDev ) - mpAlphaVDev->DrawPixel( rPt ); + if (mpAlphaVDev) + { + Color aAlphaColor(rColor.GetTransparency(), rColor.GetTransparency(), rColor.GetTransparency()); + mpAlphaVDev->DrawPixel(rPt, aAlphaColor); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
