diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-06-19 17:42:03 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-06-20 10:15:00 +0100 |
commit | b1b8419d34379dcca31e85ca78957fcf1656b178 (patch) | |
tree | 5df99c33bfd14e5b1f1acf7d3f3ace9f6b8e9a59 /basebmp | |
parent | 40e64af9e242206b9e0d01a6c8d7020fc0815520 (diff) |
tdf#92194 - fix headless masking operations in vcl.
These were causing horrible rendering artifacts for all manner of
headless rendering across Android & Online.
A very simple fix in vcl, plus a set of tests.
Change-Id: Ib261c0ea29d79ee6415e164c0b9b098efb52458b
Diffstat (limited to 'basebmp')
-rw-r--r-- | basebmp/test/bmpmasktest.cxx | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/basebmp/test/bmpmasktest.cxx b/basebmp/test/bmpmasktest.cxx index f123823cd78a..4b643072f7ec 100644 --- a/basebmp/test/bmpmasktest.cxx +++ b/basebmp/test/bmpmasktest.cxx @@ -17,8 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -// autogenerated file with codegen.pl - #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> @@ -142,6 +140,7 @@ public: void testBmpBasics() { + // mpDevice1bpp has a black rect. 0x0 -> 6x10 implTestBmpBasics( mpDevice1bpp, mpBmp1bpp ); implTestBmpBasics( mpDevice32bpp, mpBmp32bpp ); } @@ -152,11 +151,74 @@ public: implTestBmpScaledClip( mpDevice32bpp, mpBmp32bpp ); } + void testMasking() + { + BitmapDeviceSharedPtr xOutput; + BitmapDeviceSharedPtr xBitmap; + BitmapDeviceSharedPtr xMask; + + { // mpMask & mpBitmap + const basegfx::B2ISize aSize(5, 5); + std::vector< basebmp::Color > aDevPal; + aDevPal.push_back( basebmp::Color( 0, 0, 0 ) ); + aDevPal.push_back( basebmp::Color( 0xff, 0xff, 0xff ) ); + + basebmp::Format nFormat; + + nFormat = Format::OneBitMsbPal; +// nFormat = Format::OneBitMsbGrey; // FIXME - un-comment me to crash hard. + xMask = createBitmapDevice( aSize, false /* bTopDown */, + nFormat, + basebmp::getBitmapDeviceStrideForWidth( nFormat, aSize.getX()), + PaletteMemorySharedVector( + new std::vector< basebmp::Color >(aDevPal) ) ); + // wipe to copy everything. + xMask->clear( basebmp::Color( 0x00, 0x00, 0x00 ) ); + + // punch out another piece not to copy + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, "m 2 2 h4 v8 h-4z", + false, NULL ); + xMask->fillPolyPolygon( aPoly, basebmp::Color( 0xff, 0xff, 0xff ), + DrawMode::Paint ); + + xBitmap = createBitmapDevice( aSize, false, + Format::ThirtyTwoBitTcMaskBGRX, + basebmp::getBitmapDeviceStrideForWidth( + Format::ThirtyTwoBitTcMaskBGRX, aSize.getX()) ); + xBitmap->clear(Color(0x80808080)); + } + { // mpOutput & mpBitmap + const basegfx::B2ISize aSize(9, 9); + xOutput = createBitmapDevice( aSize, false, + Format::ThirtyTwoBitTcMaskBGRX, + basebmp::getBitmapDeviceStrideForWidth( + Format::ThirtyTwoBitTcMaskBGRX, aSize.getX()) ); + xOutput->clear(Color(0xffffffff)); + } + + const basegfx::B2IBox aSourceRect(0,0,4,4); + const basegfx::B2IBox aDestAll(2,2,7,7); + + xOutput->drawMaskedBitmap( + xBitmap, xMask, + aSourceRect, aDestAll, + DrawMode::Paint ); + + CPPUNIT_ASSERT_MESSAGE( "output not cleared to white", + xOutput->getPixelData( basegfx::B2IPoint( 0, 0 ) ) == 0xffffff ); + CPPUNIT_ASSERT_MESSAGE( "bitmap not drawn", + xOutput->getPixelData( basegfx::B2IPoint( 2, 2 ) ) == 0x808080 ); + CPPUNIT_ASSERT_MESSAGE( "mask not applied", + xOutput->getPixelData( basegfx::B2IPoint( 6, 6 ) ) == 0xffffff ); + } + // Change the following lines only, if you add, remove or rename // member functions of the current class, // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(BmpMaskTest); + CPPUNIT_TEST(testMasking); CPPUNIT_TEST(testBmpBasics); CPPUNIT_TEST(testBmpClip); CPPUNIT_TEST_SUITE_END(); |