[Libreoffice-commits] .: basebmp/inc basebmp/source basebmp/test basegfx/inc basegfx/test

Thorsten Behrens thorsten at kemper.freedesktop.org
Thu Nov 3 07:02:26 PDT 2011


 basebmp/inc/basebmp/bitmapdevice.hxx        |   22 ++--
 basebmp/inc/basebmp/clippedlinerenderer.hxx |    2 
 basebmp/source/bitmapdevice.cxx             |   35 ++-----
 basebmp/test/basictest.cxx                  |   16 +++
 basebmp/test/polytest.cxx                   |    2 
 basegfx/inc/basegfx/tools/rectcliptools.hxx |   14 +++
 basegfx/test/basegfx2d.cxx                  |  126 ++++++++++++++++++++++++++--
 7 files changed, 177 insertions(+), 40 deletions(-)

New commits:
commit f7975d2335334899e5d14e35e7640d3afdf220f6
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Thu Nov 3 14:58:40 2011 +0100

    Fix one more subtlety around B2IBox / B2IRange changes.
    
    The Cohen/Sutherland clip flag routine was not aware of B2IBox,
    thusly yielding incorrect line clipping for BitmapDevice software
    rendering. Cleaned that up, added some more unit tests around the
    problem, and removed the now-extraneous maLineClip member from the
    bitmap device.

diff --git a/basebmp/inc/basebmp/bitmapdevice.hxx b/basebmp/inc/basebmp/bitmapdevice.hxx
index 1e6d73b..f97ec4f 100644
--- a/basebmp/inc/basebmp/bitmapdevice.hxx
+++ b/basebmp/inc/basebmp/bitmapdevice.hxx
@@ -664,8 +664,8 @@ private:
 /** Factory method to create a BitmapDevice for given scanline format
  */
 BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
-                                          bool                      bTopDown,
-                                          sal_Int32                 nScanlineFormat );
+                                                            bool                      bTopDown,
+                                                            sal_Int32                 nScanlineFormat );
 
 /** Factory method to create a BitmapDevice for given scanline format
     with the given palette
@@ -675,9 +675,9 @@ BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVe
     format.
  */
 BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector&        rSize,
-                                          bool                             bTopDown,
-                                          sal_Int32                        nScanlineFormat,
-                                          const PaletteMemorySharedVector& rPalette );
+                                                            bool                             bTopDown,
+                                                            sal_Int32                        nScanlineFormat,
+                                                            const PaletteMemorySharedVector& rPalette );
 
 /** Factory method to create a BitmapDevice for given scanline format
     from the given piece of raw memory and palette
@@ -686,10 +686,10 @@ BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVe
     image of the specified area and format.
  */
 BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector&        rSize,
-                                          bool                             bTopDown,
-                                          sal_Int32                        nScanlineFormat,
-                                          const RawMemorySharedArray&      rMem,
-                                          const PaletteMemorySharedVector& rPalette );
+                                                            bool                             bTopDown,
+                                                            sal_Int32                        nScanlineFormat,
+                                                            const RawMemorySharedArray&      rMem,
+                                                            const PaletteMemorySharedVector& rPalette );
 
 
 /** Factory method to retrieve a subsetted BitmapDevice to the same
@@ -709,8 +709,8 @@ BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr subsetBitmapDevice( const BitmapDeviceSh
     copied, only the size can be varied. Note that the prototype's
     bitmap content is <em>not</em> copied, only a palette (if any).
  */
-BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr cloneBitmapDevice( const basegfx::B2IVector&        rSize,
-                                         const BitmapDeviceSharedPtr&     rProto );
+BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr cloneBitmapDevice( const basegfx::B2IVector&    rSize,
+                                                           const BitmapDeviceSharedPtr& rProto );
 
 }
 
diff --git a/basebmp/inc/basebmp/clippedlinerenderer.hxx b/basebmp/inc/basebmp/clippedlinerenderer.hxx
index 2fbf2f7..9969b96 100644
--- a/basebmp/inc/basebmp/clippedlinerenderer.hxx
+++ b/basebmp/inc/basebmp/clippedlinerenderer.hxx
@@ -200,7 +200,7 @@ inline bool prepareClip( sal_Int32  a1,
 template< class Iterator, class Accessor >
 void renderClippedLine( basegfx::B2IPoint             aPt1,
                         basegfx::B2IPoint             aPt2,
-                        const basegfx::B2IBox&      rClipRect,
+                        const basegfx::B2IBox&        rClipRect,
                         typename Accessor::value_type color,
                         Iterator                      begin,
                         Accessor                      acc,
diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx
index 5ac1550..c307a4a 100644
--- a/basebmp/source/bitmapdevice.cxx
+++ b/basebmp/source/bitmapdevice.cxx
@@ -1047,23 +1047,11 @@ struct ImplBitmapDevice
 
         maBounds.getWidth()/getHeight() yield the true size of the
         device (i.e. the rectangle given by maBounds covers the device
-        area under the excluding-bottommost-and-rightmost-pixels fill
-        rule)
+        area under the including-the-bottommost-and-rightmost-pixels
+        fill rule)
      */
     basegfx::B2IBox           maBounds;
 
-    /** Bounds of the device.
-
-        maBounds.getWidth()/getHeight() yield the true size of the
-        device minus 1 (i.e. the rectangle given by maBounds covers
-        the device area under the
-        including-the-bottommost-and-rightmost-pixels fill rule).
-
-        The member is used to clip line stroking against the device
-        bounds.
-     */
-    basegfx::B2IBox           maLineClipRect;
-
     /// Scanline format, as provided at the constructor
     sal_Int32                 mnScanlineFormat;
 
@@ -1102,7 +1090,6 @@ BitmapDevice::BitmapDevice( const basegfx::B2IBox&           rBounds,
     mpImpl->mpMem = rMem;
     mpImpl->mpPalette = rPalette;
     mpImpl->maBounds = rBounds;
-    mpImpl->maLineClipRect = rBounds;
     mpImpl->mnScanlineFormat = nScanlineFormat;
     mpImpl->mnScanlineStride = nScanlineStride;
     mpImpl->mpFirstScanline  = pFirstScanline;
@@ -1170,7 +1157,7 @@ void BitmapDevice::setPixel( const basegfx::B2IPoint& rPt,
                              Color                    lineColor,
                              DrawMode                 drawMode )
 {
-    if( mpImpl->maLineClipRect.isInside(rPt) )
+    if( mpImpl->maBounds.isInside(rPt) )
         setPixel_i(rPt,lineColor,drawMode);
 }
 
@@ -1185,7 +1172,7 @@ void BitmapDevice::setPixel( const basegfx::B2IPoint&     rPt,
         return;
     }
 
-    if( mpImpl->maLineClipRect.isInside(rPt) )
+    if( mpImpl->maBounds.isInside(rPt) )
     {
         if( isCompatibleClipMask( rClip ) )
             setPixel_i(rPt,lineColor,drawMode,rClip);
@@ -1196,7 +1183,7 @@ void BitmapDevice::setPixel( const basegfx::B2IPoint&     rPt,
 
 Color BitmapDevice::getPixel( const basegfx::B2IPoint& rPt )
 {
-    if( mpImpl->maLineClipRect.isInside(rPt) )
+    if( mpImpl->maBounds.isInside(rPt) )
         return getPixel_i(rPt);
 
     return Color();
@@ -1204,7 +1191,7 @@ Color BitmapDevice::getPixel( const basegfx::B2IPoint& rPt )
 
 sal_uInt32 BitmapDevice::getPixelData( const basegfx::B2IPoint& rPt )
 {
-    if( mpImpl->maLineClipRect.isInside(rPt) )
+    if( mpImpl->maBounds.isInside(rPt) )
         return getPixelData_i(rPt);
 
     return 0;
@@ -1217,7 +1204,7 @@ void BitmapDevice::drawLine( const basegfx::B2IPoint& rPt1,
 {
     drawLine_i( rPt1,
                 rPt2,
-                mpImpl->maLineClipRect,
+                mpImpl->maBounds,
                 lineColor,
                 drawMode );
 }
@@ -1237,7 +1224,7 @@ void BitmapDevice::drawLine( const basegfx::B2IPoint&     rPt1,
     if( isCompatibleClipMask( rClip ) )
         drawLine_i( rPt1,
                     rPt2,
-                    mpImpl->maLineClipRect,
+                    mpImpl->maBounds,
                     lineColor,
                     drawMode,
                     rClip );
@@ -1253,7 +1240,7 @@ void BitmapDevice::drawPolygon( const basegfx::B2DPolygon& rPoly,
     const sal_uInt32 numVertices( rPoly.count() );
     if( numVertices )
         drawPolygon_i( rPoly,
-                       mpImpl->maLineClipRect,
+                       mpImpl->maBounds,
                        lineColor, drawMode );
 }
 
@@ -1273,7 +1260,7 @@ void BitmapDevice::drawPolygon( const basegfx::B2DPolygon&   rPoly,
     {
         if( isCompatibleClipMask( rClip ) )
             drawPolygon_i( rPoly,
-                           mpImpl->maLineClipRect,
+                           mpImpl->maBounds,
                            lineColor, drawMode, rClip );
         else
             getGenericRenderer()->drawPolygon( rPoly, lineColor,
@@ -1858,6 +1845,8 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector&
                                               const basegfx::B2IBox*                     pSubset,
                                               const IBitmapDeviceDamageTrackerSharedPtr& rDamage )
 {
+    OSL_ASSERT(rSize.getX() > 0 && rSize.getY() > 0);
+
     if( nScanlineFormat <= Format::NONE ||
         nScanlineFormat >  Format::MAX )
         return BitmapDeviceSharedPtr();
diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx
index 246a25a..6329272 100644
--- a/basebmp/test/basictest.cxx
+++ b/basebmp/test/basictest.cxx
@@ -116,6 +116,21 @@ public:
                                (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) );
     }
 
+    void testClone()
+    {
+        const basegfx::B2ISize aSize(101,101);
+        basegfx::B2ISize       aSize2(3,3);
+        BitmapDeviceSharedPtr  pDevice( createBitmapDevice( aSize,
+                                                            true,
+                                                            Format::ONE_BIT_MSB_PAL ));
+
+        BitmapDeviceSharedPtr  pClone( cloneBitmapDevice(
+                                           aSize2,
+                                           pDevice ));
+        CPPUNIT_ASSERT_MESSAGE("right size",
+                               pClone->getSize() == aSize2 );
+    }
+
     void testPixelFuncs()
     {
         // 1bpp
@@ -288,6 +303,7 @@ public:
     CPPUNIT_TEST_SUITE(BasicTest);
     CPPUNIT_TEST(colorTest);
     CPPUNIT_TEST(testConstruction);
+    CPPUNIT_TEST(testClone);
     CPPUNIT_TEST(testPixelFuncs);
     CPPUNIT_TEST_SUITE_END();
 };
diff --git a/basebmp/test/polytest.cxx b/basebmp/test/polytest.cxx
index 177557c..8cc51d4 100644
--- a/basebmp/test/polytest.cxx
+++ b/basebmp/test/polytest.cxx
@@ -192,6 +192,8 @@ private:
         BitmapDeviceSharedPtr pClippedDevice(
             subsetBitmapDevice( rDevice,
                                 basegfx::B2IBox(3,3,5,8) ));
+        CPPUNIT_ASSERT_MESSAGE("size of subsetted device is not (2,5)",
+                               pClippedDevice->getSize() == basegfx::B2IVector(2,5));
 
         rDevice->clear(aBgCol);
         pClippedDevice->fillPolyPolygon(
diff --git a/basegfx/inc/basegfx/tools/rectcliptools.hxx b/basegfx/inc/basegfx/tools/rectcliptools.hxx
index 7e2ff80..c9b36eb 100644
--- a/basegfx/inc/basegfx/tools/rectcliptools.hxx
+++ b/basegfx/inc/basegfx/tools/rectcliptools.hxx
@@ -30,6 +30,7 @@
 #define _BGFX_TOOLS_RECTCLIPTOOLS_HXX
 
 #include <sal/types.h>
+#include <basegfx/range/b2ibox.hxx>
 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -65,6 +66,19 @@ namespace basegfx
             return clip;
         }
 
+        /// Cohen-Sutherland mask calculation - overload for boxes.
+        template< class Point > inline
+           sal_uInt32 getCohenSutherlandClipFlags( const Point&  rP,
+                                                   const B2IBox& rB )
+        {
+            // maxY | minY | maxX | minX
+            sal_uInt32 clip  = (rP.getX() <  rB.getMinX()) << 0;
+                       clip |= (rP.getX() >= rB.getMaxX()) << 1;
+                       clip |= (rP.getY() <  rB.getMinY()) << 2;
+                       clip |= (rP.getY() >= rB.getMaxY()) << 3;
+            return clip;
+        }
+
         /** Determine number of clip planes hit by given clip mask
 
             This method returns the number of one bits in the four
diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx
index 18a046a..9aceb83 100644
--- a/basegfx/test/basegfx2d.cxx
+++ b/basegfx/test/basegfx2d.cxx
@@ -56,6 +56,7 @@
 #include <basegfx/color/bcolortools.hxx>
 
 #include <basegfx/tools/debugplotter.hxx>
+#include <basegfx/tools/rectcliptools.hxx>
 
 #include <iostream>
 #include <fstream>
@@ -1263,15 +1264,24 @@ public:
 
         // check overlap
         Type aRange2(0,1);
-        CPPUNIT_ASSERT_MESSAGE("box overlapping *includes* upper bound", aRange.overlaps(aRange2));
-        CPPUNIT_ASSERT_MESSAGE("box overlapping *includes* upper bound, but only barely", !aRange.overlapsMore(aRange2));
+        CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound", aRange.overlaps(aRange2));
+        CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely", !aRange.overlapsMore(aRange2));
 
         Type aRange3(0,2);
-        CPPUNIT_ASSERT_MESSAGE("box overlapping is fully overlapping now", aRange.overlapsMore(aRange3));
+        CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now", aRange.overlapsMore(aRange3));
+
+        // check intersect
+        Type aRange4(3,4);
+        aRange.intersect(aRange4);
+        CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange.isEmpty());
+
+        Type aRange5(5,6);
+        aRange.intersect(aRange5);
+        CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange.isEmpty());
 
         // just so that this compiles -
-        Type aRange4( aRange );
-        (void)aRange4;
+        Type aRange6( aRange );
+        (void)aRange6;
     }
 
     void check()
@@ -1333,6 +1343,19 @@ public:
 
         B1IBox aBox3(0,2);
         CPPUNIT_ASSERT_MESSAGE("box overlapping then includes upper bound-1", aBox.overlaps(aBox3));
+
+        // check intersect
+        B1IBox aBox4(4,5);
+        aBox.intersect(aBox4);
+        CPPUNIT_ASSERT_MESSAGE("box intersection is yielding nonempty box!", aBox.isEmpty());
+
+        B1IBox aBox5(2,5);
+        aBox5.intersect(aBox4);
+        CPPUNIT_ASSERT_MESSAGE("box intersection is yielding empty box!", !aBox5.isEmpty());
+
+        // just so that this compiles -
+        B1IBox aBox6( aBox );
+        (void)aBox6;
     }
 
     // Change the following lines only, if you add, remove or rename
@@ -1345,6 +1368,97 @@ public:
 }; // class b1ibox
 
 
+class b2Xrange : public CppUnit::TestFixture
+{
+public:
+    // initialise your test code values here.
+    void setUp()
+    {
+    }
+
+    void tearDown()
+    {
+    }
+
+    template<class Type> void implCheck()
+    {
+        // cohen sutherland clipping
+        Type aRange(0,0,10,10);
+
+        CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aRange) == 0);
+        CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aRange) ==
+                               (tools::RectClipFlags::LEFT|tools::RectClipFlags::TOP));
+        CPPUNIT_ASSERT_MESSAGE("(10,10) is outside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aRange) == 0);
+        CPPUNIT_ASSERT_MESSAGE("(11,11) is inside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(11,11),aRange) ==
+                               (tools::RectClipFlags::RIGHT|tools::RectClipFlags::BOTTOM));
+
+        // just so that this compiles -
+        Type aRange1( aRange );
+        (void)aRange1;
+    }
+
+    void check()
+    {
+        implCheck<B2DRange>();
+        implCheck<B2IRange>();
+    }
+
+    // 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.
+
+    SAL_CPPUNIT_TEST_SUITE(b2Xrange);
+    CPPUNIT_TEST(check);
+    SAL_CPPUNIT_TEST_SUITE_END();
+}; // class b2Xrange
+
+
+class b2ibox : public CppUnit::TestFixture
+{
+public:
+    // initialise your test code values here.
+    void setUp()
+    {
+    }
+
+    void tearDown()
+    {
+    }
+
+    void TestBox()
+    {
+        // cohen sutherland clipping
+        B2IBox aBox(0,0,10,10);
+
+        CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aBox) == 0);
+        CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aBox) ==
+                               (tools::RectClipFlags::LEFT|tools::RectClipFlags::TOP));
+        CPPUNIT_ASSERT_MESSAGE("(9,9) is outside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(9,9),aBox) == 0);
+        CPPUNIT_ASSERT_MESSAGE("(10,10) is inside range!",
+                               tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aBox) ==
+                               (tools::RectClipFlags::RIGHT|tools::RectClipFlags::BOTTOM));
+
+        // just so that this compiles -
+        B2IBox aBox1( aBox );
+        (void)aBox1;
+    }
+
+    // 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.
+    SAL_CPPUNIT_TEST_SUITE(b2ibox);
+    CPPUNIT_TEST(TestBox);
+    SAL_CPPUNIT_TEST_SUITE_END();
+}; // class b2ibox
+
+
 class b2dtuple : public CppUnit::TestFixture
 {
 public:
@@ -1588,6 +1702,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolypolygon);
 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dquadraticbezier);
 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1Xrange);
 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1ibox);
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2Xrange);
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2ibox);
 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dtuple);
 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dvector);
 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::bcolor);


More information about the Libreoffice-commits mailing list