diff options
author | Thorsten Behrens <tbehrens@suse.com> | 2011-11-15 12:24:52 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2011-11-15 12:38:50 +0100 |
commit | b53d2bc9dd92079c030346af57e9b1a0078a05e7 (patch) | |
tree | 492f6e07cf7dc7251a83e1afa9a1b54c4137e3d6 /basebmp/test | |
parent | 2264f482e57e989e649934d3980368f2b135d496 (diff) |
Fix clipped line renderer.
Fix for a nasty corner case where supposedly clipped pixel were
still rasterized (see polytest.cxx:implTestPolyDrawClip for what
failed previously).
Added much more unit tests while at it, clippedlinerenderer.hxx
should now have 100% coverage.
Diffstat (limited to 'basebmp/test')
-rw-r--r-- | basebmp/test/linetest.cxx | 33 | ||||
-rw-r--r-- | basebmp/test/polytest.cxx | 105 |
2 files changed, 133 insertions, 5 deletions
diff --git a/basebmp/test/linetest.cxx b/basebmp/test/linetest.cxx index 885235d128c3..6e0297848c81 100644 --- a/basebmp/test/linetest.cxx +++ b/basebmp/test/linetest.cxx @@ -171,6 +171,38 @@ public: Format::THIRTYTWO_BIT_TC_MASK ); } + void testCornerCases() + { + const basegfx::B2ISize aSize(1,1); + BitmapDeviceSharedPtr pDevice = createBitmapDevice( + aSize, + true, + Format::ONE_BIT_MSB_PAL ); + + const basegfx::B2IPoint aPt1(0,0); + const basegfx::B2IPoint aPt2(10,10); + CPPUNIT_ASSERT_MESSAGE("only pixel cleared", + pDevice->getPixelData(aPt1) == 0); + + const Color aCol(0xFFFFFFFF); + pDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("only pixel set", + pDevice->getPixelData(aPt1) == 1); + + const basegfx::B2ISize aSize2(1,0); + pDevice = createBitmapDevice( + aSize2, + true, + Format::ONE_BIT_MSB_PAL ); + + CPPUNIT_ASSERT_MESSAGE("only pixel cleared", + pDevice->getPixelData(aPt1) == 0); + + pDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("only pixel still cleared", + pDevice->getPixelData(aPt1) == 0); + } + void testBasicDiagonalLines() { implTestBasicDiagonalLines( mpDevice1bpp ); @@ -202,6 +234,7 @@ public: // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(LineTest); + CPPUNIT_TEST(testCornerCases); CPPUNIT_TEST(testBasicDiagonalLines); CPPUNIT_TEST(testBasicHorizontalLines); CPPUNIT_TEST(testBasicVerticalLines); diff --git a/basebmp/test/polytest.cxx b/basebmp/test/polytest.cxx index 8cc51d4921ee..63485000b7f9 100644 --- a/basebmp/test/polytest.cxx +++ b/basebmp/test/polytest.cxx @@ -65,7 +65,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, @@ -100,7 +99,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, @@ -150,7 +148,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( @@ -170,7 +167,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( @@ -204,13 +200,98 @@ private: countPixel( rDevice, aCol ) == 7); } + void implTestLineDrawClip(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + + // create rectangular subset, such that we can 'see' extra + // pixel outside + BitmapDeviceSharedPtr pClippedDevice=( + subsetBitmapDevice( rDevice, + basegfx::B2IBox(3,3,5,9) )); + + // trigger "alternate bresenham" case in + // clippedlinerenderer.hxx, first point not clipped + const basegfx::B2IPoint aPt1(3,3); + const basegfx::B2IPoint aPt2(4,2); + pClippedDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1", + countPixel( rDevice, aCol ) == 1); + + // trigger "alternate bresenham" case in + // clippedlinerenderer.hxx, both start and endpoint clipped + const basegfx::B2IPoint aPt3(0,4); + pClippedDevice->drawLine( aPt3, aPt2, aCol, DrawMode_XOR ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0", + countPixel( rDevice, aCol ) == 0); + + // trigger "standard bresenham" case in + // clippedlinerenderer.hxx, first point not clipped + const basegfx::B2IPoint aPt4(6,2); + pClippedDevice->drawLine( aPt1, aPt4, aCol, DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2", + countPixel( rDevice, aCol ) == 2); + + // trigger "clipCode1 & aMinFlag/bMinFlag" cases in + // clippedlinerenderer.hxx (note1: needs forcing end point to + // be clipped as well, otherwise optimisation kicks in. note2: + // needs forcing end point to clip on two edges, not only on + // one, otherwise swap kicks in) + const basegfx::B2IPoint aPt5(1,1); + const basegfx::B2IPoint aPt6(6,10); + pClippedDevice->drawLine( aPt5, aPt6, aCol, DrawMode_XOR ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6", + countPixel( rDevice, aCol ) == 6); + + // trigger "clipCode1 & (aMinFlag|aMaxFlag)" case in + // clippedlinerenderer.hxx that was not taken for the test + // above + pClippedDevice->drawLine( aPt3, aPt6, aCol, DrawMode_XOR ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8", + countPixel( rDevice, aCol ) == 8); + + } + + void implTestPolyDrawClip(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + basegfx::B2DPolyPolygon aPoly; + + // test all corner-touching lines of our clip rect. note that + // *all* of the four two-pixel lines in that polygon do *not* + // generate a single pixel, due to the rasterization effect. + basegfx::tools::importFromSvgD( aPoly, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M2 3 l1 -1 M4 2 l1 1 M2 8 l1 1 M5 8 l-1 1 M2 5 h4 M3 0 v10" )) ); + BitmapDeviceSharedPtr pClippedDevice=( + subsetBitmapDevice( rDevice, + basegfx::B2IBox(3,3,5,9) )); + + for( unsigned int i=0; i<aPoly.count(); ++i ) + pClippedDevice->drawPolygon( + aPoly.getB2DPolygon(i), + aCol, + DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7", + countPixel( rDevice, aCol ) == 7); + } + void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice) { const Color aCol(0xFFFFFFFF); const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( @@ -264,6 +345,18 @@ public: implTestPolyPolyClip(mpDevice32bpp); } + void testLineDrawClip() + { + implTestLineDrawClip(mpDevice1bpp); + implTestLineDrawClip(mpDevice32bpp); + } + + void testPolyDrawClip() + { + implTestPolyDrawClip(mpDevice1bpp); + implTestPolyDrawClip(mpDevice32bpp); + } + void testPolyPolyCrissCross() { implTestPolyPolyCrissCross(mpDevice1bpp); @@ -279,6 +372,8 @@ public: CPPUNIT_TEST(testHairline); CPPUNIT_TEST(testPolyPoly); CPPUNIT_TEST(testPolyPolyClip); + CPPUNIT_TEST(testLineDrawClip); + CPPUNIT_TEST(testPolyDrawClip); CPPUNIT_TEST(testPolyPolyCrissCross); CPPUNIT_TEST_SUITE_END(); }; |