summaryrefslogtreecommitdiff
path: root/basebmp/source
diff options
context:
space:
mode:
authorThorsten Behrens <thb@openoffice.org>2006-07-27 10:35:32 +0000
committerThorsten Behrens <thb@openoffice.org>2006-07-27 10:35:32 +0000
commit8c044545bbfd533f94743a7d6cb76da5844a9e3e (patch)
treea3df72dd0c7e673d673d017e0ec6268687b38a66 /basebmp/source
parent3df3d44e8776a1384a6a3bd7209a6ed09b5f347a (diff)
#i65904# Dumped basegfx polygon raster converter in favor of a specialized solution; constructing all accessors with passed parameter now for the BitmapRenderer; significantly improved test coverage for polygon rasterizing
Diffstat (limited to 'basebmp/source')
-rw-r--r--basebmp/source/bitmapdevice.cxx116
-rw-r--r--basebmp/source/makefile.mk7
-rw-r--r--basebmp/source/polypolygonrenderer.cxx135
3 files changed, 160 insertions, 98 deletions
diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx
index 324422c23ac2..63d0a41c12e2 100644
--- a/basebmp/source/bitmapdevice.cxx
+++ b/basebmp/source/bitmapdevice.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: bitmapdevice.cxx,v $
*
- * $Revision: 1.23 $
+ * $Revision: 1.24 $
*
- * last change: $Author: thb $ $Date: 2006-07-21 20:57:06 $
+ * last change: $Author: thb $ $Date: 2006-07-27 11:35:31 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -56,6 +56,7 @@
#include "basebmp/fillimage.hxx"
#include "basebmp/scaleimage.hxx"
#include "basebmp/clippedlinerenderer.hxx"
+#include "basebmp/polypolygonrenderer.hxx"
//#include "basebmp/genericintegerimageaccessor.hxx"
#include "basebmp/tools.hxx"
@@ -70,9 +71,7 @@
#include <basegfx/range/b2drange.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
-#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
-#include <basegfx/polygon/b2dpolypolygonrasterconverter.hxx>
#include <basegfx/point/b2ipoint.hxx>
#include <basegfx/vector/b2ivector.hxx>
@@ -173,85 +172,6 @@ namespace
};
- // Polygon scanline conversion
- //------------------------------------------------------------------------
-
- template< class DestIterator, class DestAccessor > class Renderer :
- public basegfx::B2DPolyPolygonRasterConverter
- {
- private:
- basegfx::B2IRange bounds_;
- typename DestAccessor::value_type fillColor_;
- typename DestAccessor::value_type clearColor_;
- DestIterator begin_;
- DestAccessor accessor_;
-
- public:
- Renderer(const basegfx::B2DPolyPolygon& rPolyPolyRaster,
- typename DestAccessor::value_type fillColor,
- const basegfx::B2IRange& bounds,
- DestIterator begin,
- DestAccessor accessor ) :
- B2DPolyPolygonRasterConverter(rPolyPolyRaster,
- basegfx::B2DRange(bounds) ),
- bounds_(bounds),
- fillColor_( fillColor ),
- begin_( begin ),
- accessor_( accessor )
- {
- }
-
- virtual void span(const double& rfXLeft,
- const double& rfXRight,
- sal_Int32 nY,
- bool bOn )
- {
- if( !bOn ||
- nY < bounds_.getMinY() ||
- nY >= bounds_.getMaxY() ||
- rfXLeft >= bounds_.getMaxX() ||
- rfXRight < bounds_.getMinX() )
- {
- return;
- }
-
- // clip span to bitmap bounds
- const sal_Int32 nStartX( std::max( bounds_.getMinX(),
- std::min( bounds_.getMaxX()-1,
- basegfx::fround( rfXLeft ))));
- const sal_Int32 nEndX ( std::max( bounds_.getMinX(),
- std::min( bounds_.getMaxX(),
- basegfx::fround( rfXRight ))));
-
- DestIterator currIter( begin_ + vigra::Diff2D(0,nY) );
- typename vigra::IteratorTraits<DestIterator>::row_iterator
- rowIter( currIter.rowIterator() + nStartX);
- typename vigra::IteratorTraits<DestIterator>::row_iterator
- rowEnd( currIter.rowIterator() + nEndX );
-
- // TODO(P2): Provide specialized span fill methods on the
- // iterator/accessor
- while( rowIter != rowEnd )
- accessor_.set(fillColor_, rowIter++);
- }
- };
-
- template< class DestIterator, class DestAccessor >
- std::auto_ptr< Renderer< DestIterator, DestAccessor > > makeRenderer(
- const basegfx::B2DPolyPolygon& rPolyPolyRaster,
- typename DestAccessor::value_type fillColor,
- const basegfx::B2IRange& outRange,
- const DestIterator& begin,
- const DestAccessor& acc )
- {
- return std::auto_ptr< Renderer< DestIterator, DestAccessor > >(
- new Renderer< DestIterator, DestAccessor >(rPolyPolyRaster,
- fillColor,
- outRange,
- begin,
- acc));
- }
-
// Actual BitmapDevice implementation (templatized by accessor and iterator)
//--------------------------------------------------------------------------
@@ -396,6 +316,7 @@ namespace
sal_Int32 nScanlineStride,
sal_uInt8* pFirstScanline,
dest_iterator_type begin,
+ raw_accessor_type rawAccessor,
dest_accessor_type accessor,
const RawMemorySharedArray& rMem,
const PaletteMemorySharedVector& rPalette ) :
@@ -406,15 +327,15 @@ namespace
maToUInt32Converter(),
maAccessor( accessor ),
maColorBlendAccessor( accessor ),
- maRawAccessor(),
+ maRawAccessor( rawAccessor ),
maXorAccessor( accessor ),
- maRawXorAccessor(),
+ maRawXorAccessor( rawAccessor ),
maMaskedAccessor( accessor ),
maMaskedColorBlendAccessor( maColorBlendAccessor ),
maMaskedXorAccessor( accessor ),
- maRawMaskedAccessor(),
- maRawMaskedXorAccessor(),
- maRawMaskedMaskAccessor()
+ maRawMaskedAccessor( rawAccessor ),
+ maRawMaskedXorAccessor( rawAccessor ),
+ maRawMaskedMaskAccessor( rawAccessor )
{}
private:
@@ -684,13 +605,12 @@ namespace
if( rPoly.areControlVectorsUsed() )
aPoly = basegfx::tools::adaptiveSubdivideByCount( rPoly );
- makeRenderer( aPoly,
- maColorLookup( maAccessor,
- col),
- rBounds,
- begin,
- acc )->rasterConvert(
- basegfx::FillRule_NONZERO_WINDING_NUMBER );
+ renderClippedPolyPolygon( begin,
+ acc,
+ maColorLookup( maAccessor,
+ col),
+ rBounds,
+ aPoly );
}
virtual void fillPolyPolygon_i(const basegfx::B2DPolyPolygon& rPoly,
@@ -1773,6 +1693,7 @@ BitmapDeviceSharedPtr createRenderer(
sal_Int32 nScanlineFormat,
sal_Int32 nScanlineStride,
sal_uInt8* pFirstScanline,
+ typename FormatTraits::raw_accessor_type const& rRawAccessor,
typename FormatTraits::accessor_selector::template wrap_accessor<
typename FormatTraits::raw_accessor_type>::type const& rAccessor,
boost::shared_array< sal_uInt8 > pMem,
@@ -1809,6 +1730,7 @@ BitmapDeviceSharedPtr createRenderer(
reinterpret_cast<typename Iterator::value_type*>(
pFirstScanline),
nScanlineStride),
+ rRawAccessor,
rAccessor,
pMem,
pPal ));
@@ -1851,6 +1773,7 @@ BitmapDeviceSharedPtr createRenderer(
nScanlineFormat,
nScanlineStride,
pFirstScanline,
+ typename FormatTraits::raw_accessor_type(),
typename FormatTraits::accessor_selector::template
wrap_accessor<
typename FormatTraits::raw_accessor_type>::type(),
@@ -1879,6 +1802,7 @@ BitmapDeviceSharedPtr createRenderer(
nScanlineFormat,
nScanlineStride,
pFirstScanline,
+ typename FormatTraits::raw_accessor_type(),
typename FormatTraits::accessor_selector::template
wrap_accessor<
typename FormatTraits::raw_accessor_type>::type(
@@ -2170,6 +2094,8 @@ BitmapDeviceSharedPtr BitmapDevice::getGenericRenderer() const
getScanlineStride(),
mpImpl->mpFirstScanline,
PixelFormatTraits_GenericInteger::iterator_type(),
+ GenericIntegerImageRawAccessor<Color>(
+ const_cast<BitmapDevice*>(this)->shared_from_this()),
GenericIntegerImageAccessor<Color>(
const_cast<BitmapDevice*>(this)->shared_from_this()),
getBuffer(),
diff --git a/basebmp/source/makefile.mk b/basebmp/source/makefile.mk
index da5006e0c07e..30d8433b363b 100644
--- a/basebmp/source/makefile.mk
+++ b/basebmp/source/makefile.mk
@@ -4,9 +4,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.4 $
+# $Revision: 1.5 $
#
-# last change: $Author: thb $ $Date: 2006-07-21 20:57:06 $
+# last change: $Author: thb $ $Date: 2006-07-27 11:35:31 $
#
# The Contents of this file are made available subject to
# the terms of GNU Lesser General Public License Version 2.1.
@@ -51,7 +51,8 @@ CDEFS+= -DBASEBMP_NO_NESTED_TEMPLATE_PARAMETER
SLOFILES = \
$(SLO)$/bitmapdevice.obj \
- $(SLO)$/debug.obj
+ $(SLO)$/debug.obj \
+ $(SLO)$/polypolygonrenderer.obj
# $(SLO)$/genericintegerimageaccessor.obj \
diff --git a/basebmp/source/polypolygonrenderer.cxx b/basebmp/source/polypolygonrenderer.cxx
new file mode 100644
index 000000000000..c94e7fae137e
--- /dev/null
+++ b/basebmp/source/polypolygonrenderer.cxx
@@ -0,0 +1,135 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: polypolygonrenderer.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: thb $ $Date: 2006-07-27 11:35:31 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "basebmp/polypolygonrenderer.hxx"
+
+#include <algorithm>
+
+
+namespace basebmp
+{
+namespace detail
+{
+ sal_uInt32 setupGlobalEdgeTable( VectorOfVectorOfVertices& rGET,
+ basegfx::B2DPolyPolygon const& rPolyPoly,
+ sal_Int32 nMinY )
+ {
+ sal_uInt32 const nNumScanlines( rGET.size() );
+
+ // add all polygons to GET
+ for( sal_uInt32 i(0), nCount(rPolyPoly.count());
+ i<nCount;
+ ++i )
+ {
+ // add all vertices to GET
+ const basegfx::B2DPolygon& rPoly( rPolyPoly.getB2DPolygon(i) );
+ for( sal_uInt32 k(0), nVertices(rPoly.count());
+ k<nVertices;
+ ++k )
+ {
+ const basegfx::B2DPoint& rP1( rPoly.getB2DPoint(k) );
+ const basegfx::B2DPoint& rP2( rPoly.getB2DPoint( (k + 1) % nVertices ) );
+
+ const sal_Int32 nVertexYP1( basegfx::fround(rP1.getY()) );
+ const sal_Int32 nVertexYP2( basegfx::fround(rP2.getY()) );
+
+ // insert only vertices which are not strictly
+ // horizontal. Strictly horizontal vertices don't add
+ // any information that is not already present - due
+ // to their adjacent vertices.
+ if(nVertexYP1 != nVertexYP2)
+ {
+ if( nVertexYP2 < nVertexYP1 )
+ {
+ const sal_Int32 nStartScanline(nVertexYP2 - nMinY);
+
+ // edge direction is upwards - add with swapped vertices
+ if( nStartScanline < nNumScanlines )
+ rGET[ nStartScanline ].push_back( Vertex(rP2, rP1, false) );
+ }
+ else
+ {
+ const sal_Int32 nStartScanline(nVertexYP1 - nMinY);
+
+ if( nStartScanline < nNumScanlines )
+ rGET[ nStartScanline ].push_back( Vertex(rP1, rP2, true) );
+ }
+ }
+ }
+ }
+
+ // now sort all scanlines individually, with increasing x
+ // coordinates
+ VectorOfVectorOfVertices::iterator aIter( rGET.begin() );
+ const VectorOfVectorOfVertices::iterator aEnd( rGET.end() );
+ sal_uInt32 nVertexCount(0);
+ RasterConvertVertexComparator aComp;
+ while( aIter != aEnd )
+ {
+ std::sort( aIter->begin(),
+ aIter->end(),
+ aComp );
+ nVertexCount += aIter->size();
+
+ ++aIter;
+ }
+
+ return nVertexCount;
+ }
+
+ void sortAET( VectorOfVertexPtr& rAETSrc,
+ VectorOfVertexPtr& rAETDest )
+ {
+ static RasterConvertVertexComparator aComp;
+
+ rAETDest.clear();
+
+ // prune AET from ended edges
+ VectorOfVertexPtr::iterator iter( rAETSrc.begin() );
+ VectorOfVertexPtr::iterator const end( rAETSrc.end() );
+ while( iter != end )
+ {
+ if( (*iter)->mnYCounter > 0 )
+ rAETDest.push_back( *iter );
+ ++iter;
+ }
+
+ // stable sort is necessary, to avoid segment crossing where
+ // none was intended.
+ std::stable_sort( rAETDest.begin(), rAETDest.end(), aComp );
+ }
+
+} // namespace detail
+} // namespace basebmp