From 6928d01f7a4cff47b6c6b186885ac79a58e64ac6 Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Fri, 30 Jun 2006 10:05:21 +0000 Subject: #i65904# Fixed ugly typos in clippedLine clipping; improved docs; added testcases for fixed bugs; corrected clip bounds for line and polyline rendering --- basebmp/inc/basebmp/clippedlinerenderer.hxx | 24 ++++++------- basebmp/source/bitmapdevice.cxx | 53 +++++++++++++++++++++-------- basebmp/test/basictest.cxx | 16 +++++++-- basebmp/test/bmpdemo.cxx | 19 ++++++++--- 4 files changed, 78 insertions(+), 34 deletions(-) (limited to 'basebmp') diff --git a/basebmp/inc/basebmp/clippedlinerenderer.hxx b/basebmp/inc/basebmp/clippedlinerenderer.hxx index c48fc7ef2df6..1488dfe57329 100644 --- a/basebmp/inc/basebmp/clippedlinerenderer.hxx +++ b/basebmp/inc/basebmp/clippedlinerenderer.hxx @@ -4,9 +4,9 @@ * * $RCSfile: clippedlinerenderer.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: thb $ $Date: 2006-06-28 16:50:19 $ + * last change: $Author: thb $ $Date: 2006-06-30 11:05:21 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -103,9 +103,9 @@ inline bool prepareClip( sal_Int32 a1, } if( clipCount1 == 2 ) - clipCode1 &= (ca + da < cb + !bRoundTowardsPt2) ? ~(aMin|aMax) : ~(bMin|bMax); + clipCode1 &= (ca + da < cb + !bRoundTowardsPt2) ? ~(aMinFlag|aMaxFlag) : ~(bMinFlag|bMaxFlag); - if( clipCode1 & (aMin|aMax) ) + if( clipCode1 & (aMinFlag|aMaxFlag) ) { cb = (ca + da - !bRoundTowardsPt2) / (2*da); @@ -153,16 +153,16 @@ inline bool prepareClip( sal_Int32 a1, { if( clipCount2 == 2 ) { - ca = 2*db*((clipCode2 & aMin) ? a1 - aMin : aMax - a1); - cb = 2*da*((clipCode2 & bMin) ? b1 - bMin : bMax - b1); - clipCode2 &= (cb + da < ca + bRoundTowardsPt2) ? ~(aMin|aMax) : ~(bMin|bMax); + ca = 2*db*((clipCode2 & aMinFlag) ? a1 - aMin : aMax - a1); + cb = 2*da*((clipCode2 & bMinFlag) ? b1 - bMin : bMax - b1); + clipCode2 &= (cb + da < ca + bRoundTowardsPt2) ? ~(aMinFlag|aMaxFlag) : ~(bMinFlag|bMaxFlag); } - if( clipCode2 & (aMin|aMax) ) - o_n = (clipCode2 & aMin) ? o_as - aMin : aMax - o_as; + if( clipCode2 & (aMinFlag|aMaxFlag) ) + o_n = (clipCode2 & aMinFlag) ? o_as - aMin : aMax - o_as; else { - o_n = (clipCode2 & bMin) ? o_bs - bMin : bMax - o_bs; + o_n = (clipCode2 & bMinFlag) ? o_bs - bMin : bMax - o_bs; bRetVal = true; } } @@ -271,7 +271,7 @@ void renderClippedLine( basegfx::B2IPoint aPt1, const bool bUseAlternateBresenham( prepareClip(x1, x2, y1, adx, ady, xs, ys, sx, sy, - rem, n, clipCode1, clipCount1, clipCode1, clipCount2, + rem, n, clipCode1, clipCount1, clipCode2, clipCount2, rClipRect.getMinX(), basegfx::tools::RectClipFlags::LEFT, rClipRect.getMaxX(), basegfx::tools::RectClipFlags::RIGHT, rClipRect.getMinY(), basegfx::tools::RectClipFlags::TOP, @@ -346,7 +346,7 @@ void renderClippedLine( basegfx::B2IPoint aPt1, const bool bUseAlternateBresenham( prepareClip(y1, y2, x1, ady, adx, ys, xs, sy, sx, - rem, n, clipCode1, clipCount1, clipCode1, clipCount2, + rem, n, clipCode1, clipCount1, clipCode2, clipCount2, rClipRect.getMinY(), basegfx::tools::RectClipFlags::TOP, rClipRect.getMaxY(), basegfx::tools::RectClipFlags::BOTTOM, rClipRect.getMinX(), basegfx::tools::RectClipFlags::LEFT, diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx index 2e85066bfd97..51ffc092f4d2 100644 --- a/basebmp/source/bitmapdevice.cxx +++ b/basebmp/source/bitmapdevice.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bitmapdevice.cxx,v $ * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * - * last change: $Author: thb $ $Date: 2006-06-28 16:50:19 $ + * last change: $Author: thb $ $Date: 2006-06-30 11:05:21 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -802,14 +802,39 @@ namespace struct ImplBitmapDevice { - /// Bitmap memory plus deleter + /** Bitmap memory plus deleter. + + Always points to the start of the mem + */ RawMemorySharedArray mpMem; + /// Palette memory plus deleter (might be NULL) PaletteMemorySharedVector mpPalette; + /** Bounds of the device. + + 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) + */ basegfx::B2IRange maBounds; - basegfx::B2DRange maFloatBounds; + + /** 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::B2IRange maLineClipRect; + + /// Scanline format, as provided at the constructor sal_Int32 mnScanlineFormat; + + /// Scanline stride. Negative for bottom-to-top formats sal_Int32 mnScanlineStride; }; @@ -825,7 +850,7 @@ BitmapDevice::BitmapDevice( const basegfx::B2IVector& rSize, mpImpl->mpMem = rMem; mpImpl->mpPalette = rPalette; mpImpl->maBounds = basegfx::B2IRange( 0,0,rSize.getX(),rSize.getY() ); - mpImpl->maFloatBounds = basegfx::B2DRange( 0,0,rSize.getX(),rSize.getY() ); + mpImpl->maLineClipRect = basegfx::B2IRange( 0,0,rSize.getX()-1,rSize.getY()-1 ); mpImpl->mnScanlineFormat = nScanlineFormat; mpImpl->mnScanlineStride = bTopDown ? nScanlineStride : -nScanlineStride; } @@ -880,7 +905,7 @@ void BitmapDevice::setPixel( const basegfx::B2IPoint& rPt, Color lineColor, DrawMode drawMode ) { - if( mpImpl->maBounds.isInside(rPt) ) + if( mpImpl->maLineClipRect.isInside(rPt) ) setPixel_i(rPt,lineColor,drawMode); } @@ -895,7 +920,7 @@ void BitmapDevice::setPixel( const basegfx::B2IPoint& rPt, return; } - if( mpImpl->maBounds.isInside(rPt) ) + if( mpImpl->maLineClipRect.isInside(rPt) ) { if( isCompatibleClipMask( rClip ) ) setPixel_i(rPt,lineColor,drawMode,rClip); @@ -906,7 +931,7 @@ void BitmapDevice::setPixel( const basegfx::B2IPoint& rPt, Color BitmapDevice::getPixel( const basegfx::B2IPoint& rPt ) { - if( mpImpl->maBounds.isInside(rPt) ) + if( mpImpl->maLineClipRect.isInside(rPt) ) return getPixel_i(rPt); return Color(); @@ -914,7 +939,7 @@ Color BitmapDevice::getPixel( const basegfx::B2IPoint& rPt ) sal_uInt32 BitmapDevice::getPixelData( const basegfx::B2IPoint& rPt ) { - if( mpImpl->maBounds.isInside(rPt) ) + if( mpImpl->maLineClipRect.isInside(rPt) ) return getPixelData_i(rPt); return 0; @@ -927,7 +952,7 @@ void BitmapDevice::drawLine( const basegfx::B2IPoint& rPt1, { drawLine_i( rPt1, rPt2, - mpImpl->maBounds, + mpImpl->maLineClipRect, lineColor, drawMode ); } @@ -947,7 +972,7 @@ void BitmapDevice::drawLine( const basegfx::B2IPoint& rPt1, if( isCompatibleClipMask( rClip ) ) drawLine_i( rPt1, rPt2, - mpImpl->maBounds, + mpImpl->maLineClipRect, lineColor, drawMode, rClip ); @@ -962,7 +987,7 @@ void BitmapDevice::drawPolygon( const basegfx::B2DPolygon& rPoly, const sal_uInt32 numVertices( rPoly.count() ); if( numVertices ) drawPolygon_i( rPoly, - mpImpl->maBounds, + mpImpl->maLineClipRect, lineColor, drawMode ); } @@ -981,7 +1006,7 @@ void BitmapDevice::drawPolygon( const basegfx::B2DPolygon& rPoly, if( numVertices ) if( isCompatibleClipMask( rClip ) ) drawPolygon_i( rPoly, - mpImpl->maBounds, + mpImpl->maLineClipRect, lineColor, drawMode, rClip ); else OSL_ENSURE( false, "Generic output not yet implemented!" ); @@ -1388,7 +1413,7 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& } sal_uInt8* pFirstScanline = nScanlineStride < 0 ? - pMem.get() + nMemSize : pMem.get(); + pMem.get() + nMemSize + nScanlineStride : pMem.get(); switch( nScanlineFormat ) { diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx index 893fdae489d9..8126dfd18f99 100644 --- a/basebmp/test/basictest.cxx +++ b/basebmp/test/basictest.cxx @@ -4,9 +4,9 @@ * * $RCSfile: basictest.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: thb $ $Date: 2006-06-28 16:50:19 $ + * last change: $Author: thb $ $Date: 2006-06-30 11:05:21 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -119,7 +119,7 @@ public: void testPixelFuncs() { // 1bpp - const basegfx::B2ISize aSize(101,101); + const basegfx::B2ISize aSize(64,64); BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize, true, Format::ONE_BIT_MSB_PAL )); @@ -142,11 +142,21 @@ public: CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3", pDevice->getPixel(aPt3) == aCol3); + pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5", + pDevice->getPixel(aPt3) == aCol2); + const basegfx::B2IPoint aPt4(-100000,-100000); pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT ); const basegfx::B2IPoint aPt5(100000,100000); pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT ); + sal_Int32 nPixel(countPixel(pDevice, aCol2)); + const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY()); + pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("setPixel clipping", + countPixel(pDevice, aCol2) == nPixel); + // 8bit alpha { pDevice = createBitmapDevice( aSize, diff --git a/basebmp/test/bmpdemo.cxx b/basebmp/test/bmpdemo.cxx index 1a0b3d4512c4..8f699dc05a18 100644 --- a/basebmp/test/bmpdemo.cxx +++ b/basebmp/test/bmpdemo.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bmpdemo.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: thb $ $Date: 2006-06-28 16:50:19 $ + * last change: $Author: thb $ $Date: 2006-06-30 11:05:21 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -1078,14 +1078,23 @@ void TestWindow::Paint( const Rectangle& rRect ) { basegfx::B2ISize aTestSize(1000,1000); basebmp::BitmapDeviceSharedPtr pDevice( basebmp::createBitmapDevice( aTestSize, - true, + false, basebmp::Format::THIRTYTWO_BIT_TC_MASK )); { - const basegfx::B2IPoint aPt1(0,0); - const basegfx::B2IPoint aPt2(1,9); const basebmp::Color aCol(0xFFFFFFFF); +#if 0 + basegfx::B2DPolygon aRect = basegfx::tools::createPolygonFromRect( + basegfx::B2DRange( 0,0,1001,1001 )); + pDevice->drawPolygon( aRect, aCol, basebmp::DrawMode_PAINT ); +#endif + + const basegfx::B2IPoint aPt1(0,0); + const basegfx::B2IPoint aPt2(0,800); pDevice->drawLine( aPt1, aPt2, aCol, basebmp::DrawMode_PAINT ); + + const basegfx::B2IPoint aPt3(0,1001); + pDevice->drawLine( aPt1, aPt3, aCol, basebmp::DrawMode_PAINT ); } { -- cgit