summaryrefslogtreecommitdiff
path: root/basebmp/test
diff options
context:
space:
mode:
authorThorsten Behrens <thb@openoffice.org>2006-06-28 15:50:20 +0000
committerThorsten Behrens <thb@openoffice.org>2006-06-28 15:50:20 +0000
commit0535516a2f4f08b15ad9a8007f12f9a57d4fbbb1 (patch)
tree5d366d47572bc783da6daf1a4aaaef4c7a7c904b /basebmp/test
parentb40eed0e55f88aae77acbffd9b9b667c42547ea4 (diff)
#i65904# Added more docs; made clip masks for all cases (except masked bitmap); removed hardcoded unsigned int in favor of a metafunction; added tests for clips; fixed Color channel modification methods
Diffstat (limited to 'basebmp/test')
-rw-r--r--basebmp/test/basictest.cxx47
-rw-r--r--basebmp/test/bmpdemo.cxx324
-rw-r--r--basebmp/test/cliptest.cxx274
3 files changed, 358 insertions, 287 deletions
diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx
index 8e33561303f6..893fdae489d9 100644
--- a/basebmp/test/basictest.cxx
+++ b/basebmp/test/basictest.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: basictest.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: thb $ $Date: 2006-06-07 14:27:36 $
+ * last change: $Author: thb $ $Date: 2006-06-28 16:50:19 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -61,6 +61,44 @@ namespace
class BasicTest : public CppUnit::TestFixture
{
public:
+ void colorTest()
+ {
+ Color aTestColor;
+
+ aTestColor = Color(0xDEADBEEF);
+ CPPUNIT_ASSERT_MESSAGE("unary constructor",
+ aTestColor.toInt32() == 0xDEADBEEF );
+
+ aTestColor = Color( 0x10, 0x20, 0xFF );
+ CPPUNIT_ASSERT_MESSAGE("ternary constructor",
+ aTestColor.toInt32() == 0x001020FF );
+
+ aTestColor.setRed( 0x0F );
+ CPPUNIT_ASSERT_MESSAGE("setRed()",
+ aTestColor.toInt32() == 0x00F20FF );
+
+ aTestColor.setGreen( 0x0F );
+ CPPUNIT_ASSERT_MESSAGE("setGreen()",
+ aTestColor.toInt32() == 0x00F0FFF );
+
+ aTestColor.setBlue( 0x10 );
+ CPPUNIT_ASSERT_MESSAGE("setBlue()",
+ aTestColor.toInt32() == 0x00F0F10 );
+
+ aTestColor.setGray( 0x13 );
+ CPPUNIT_ASSERT_MESSAGE("setGray()",
+ aTestColor.toInt32() == 0x00131313 );
+
+ aTestColor = Color( 0x10, 0x20, 0xFF );
+ CPPUNIT_ASSERT_MESSAGE("getRed()",
+ aTestColor.getRed() == 0x10 );
+ CPPUNIT_ASSERT_MESSAGE("getGreen()",
+ aTestColor.getGreen() == 0x20 );
+ CPPUNIT_ASSERT_MESSAGE("getBlue()",
+ aTestColor.getBlue() == 0xFF );
+
+ }
+
void testConstruction()
{
const basegfx::B2ISize aSize(101,101);
@@ -117,10 +155,6 @@ public:
const Color aCol4(0x010101);
pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
-
- std::ofstream output("32bpp_test.dump");
- debugDump( pDevice, output );
-
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
pDevice->getPixel(aPt) == aCol4);
@@ -163,6 +197,7 @@ public:
// because these macros are need by auto register mechanism.
CPPUNIT_TEST_SUITE(BasicTest);
+ CPPUNIT_TEST(colorTest);
CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST(testPixelFuncs);
CPPUNIT_TEST_SUITE_END();
diff --git a/basebmp/test/bmpdemo.cxx b/basebmp/test/bmpdemo.cxx
index 3e43ce8ce2d1..1a0b3d4512c4 100644
--- a/basebmp/test/bmpdemo.cxx
+++ b/basebmp/test/bmpdemo.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: bmpdemo.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: thb $ $Date: 2006-06-09 04:21:01 $
+ * last change: $Author: thb $ $Date: 2006-06-28 16:50:19 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -983,7 +983,7 @@ class TestWindow : public Dialog
TestWindow() : Dialog( (Window *) NULL )
{
SetText( rtl::OUString::createFromAscii( "VIGRA test" ) );
- SetSizePixel( Size( 1024, 500 ) );
+ SetSizePixel( Size( 1024, 1024 ) );
EnablePaint( true );
Show();
}
@@ -1017,7 +1017,8 @@ static basegfx::B2IPoint project( const basegfx::B2IPoint& rPoint )
//double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
double z2 = z1;
- return basegfx::B2IPoint( (sal_Int32)x2, (sal_Int32)z2 );
+ //return basegfx::B2IPoint( (sal_Int32)3*x2, (sal_Int32)3*z2 );
+ return basegfx::B2IPoint( (sal_Int32)6*x2, (sal_Int32)6*z2 );
}
static basebmp::Color approachColor( const basebmp::Color& rFrom, const basebmp::Color& rTo )
@@ -1075,16 +1076,27 @@ static basebmp::Color approachColor( const basebmp::Color& rFrom, const basebmp:
void TestWindow::Paint( const Rectangle& rRect )
{
+ basegfx::B2ISize aTestSize(1000,1000);
+ basebmp::BitmapDeviceSharedPtr pDevice( basebmp::createBitmapDevice( aTestSize,
+ true,
+ basebmp::Format::THIRTYTWO_BIT_TC_MASK ));
+
+ {
+ const basegfx::B2IPoint aPt1(0,0);
+ const basegfx::B2IPoint aPt2(1,9);
+ const basebmp::Color aCol(0xFFFFFFFF);
+ pDevice->drawLine( aPt1, aPt2, aCol, basebmp::DrawMode_PAINT );
+ }
+
{
- basegfx::B2ISize aTestSize(500,500);
- basebmp::BitmapDeviceSharedPtr pDevice2( basebmp::createBitmapDevice( aTestSize,
- true,
- basebmp::Format::THIRTYTWO_BIT_TC_MASK ));
- pDevice2->clear(basebmp::Color(0));
+ pDevice->clear(basebmp::Color(0));
basegfx::B2IPoint aCenter( aTestSize.getX()/2,
aTestSize.getY()/2 );
- basegfx::B2IPoint aP1( aTestSize.getX()/48, 0), aP2( aTestSize.getX()/40, 0 ), aPoint;
+ //basegfx::B2IPoint aP1( aTestSize.getX()/48, 0), aP2( aTestSize.getX()/40, 0 ), aPoint;
+ //basegfx::B2IPoint aP1( aTestSize.getX()/7, 0), aP2( aTestSize.getX()/6, 0 ), aPoint;
+ //basegfx::B2IPoint aP1( aTestSize.getX()/5, 0), aP2( aTestSize.getX()/4, 0 ), aPoint;
+ basegfx::B2IPoint aP1( aTestSize.getX()/12, 0), aP2( aTestSize.getX()/11, 0 ), aPoint;
double sind = sin( DELTA*M_PI/180.0 );
double cosd = cos( DELTA*M_PI/180.0 );
@@ -1110,14 +1122,12 @@ void TestWindow::Paint( const Rectangle& rRect )
basegfx::B2DPolygon aPoly;
aPoly.append( basegfx::B2DPoint(project( aP1 ) + aCenter) );
aPoly.append( basegfx::B2DPoint(project( aP2 ) + aCenter) );
- pDevice2->drawPolygon(
- aPoly,
- basebmp::Color(0xFFFFFFFF),
- basebmp::DrawMode_PAINT);
- pDevice2->fillPolyPolygon(
+ pDevice->fillPolyPolygon(
basegfx::tools::createAreaGeometryForPolygon(
aPoly,
- n/3,
+// std::max(1,n/30),
+// std::max(1,n/60),
+ std::max(1,n/30),
basegfx::tools::B2DLINEJOIN_NONE),
aLineColor,
basebmp::DrawMode_PAINT);
@@ -1131,271 +1141,23 @@ void TestWindow::Paint( const Rectangle& rRect )
}
std::ofstream output4("svptest.dump");
- debugDump( pDevice2, output4 );
-
- const basegfx::B2ISize aSize(10,10);
- basebmp::BitmapDeviceSharedPtr pDevice( basebmp::createBitmapDevice( aSize,
- true,
- basebmp::Format::THIRTYTWO_BIT_TC_MASK ));
- basebmp::BitmapDeviceSharedPtr pMask( basebmp::createBitmapDevice( aSize,
- true,
- basebmp::Format::ONE_BIT_MSB_GRAY ));
- ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
- "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" );
- basegfx::B2DPolyPolygon aPoly;
- basegfx::tools::importFromSvgD( aPoly, aSvg );
- pMask->clear(basebmp::Color(0xFFFFFFFF));
- pMask->drawPolygon(
- aPoly.getB2DPolygon(0),
- basebmp::Color(0),
- basebmp::DrawMode_PAINT );
-
- basebmp::BitmapDeviceSharedPtr pBmp( basebmp::cloneBitmapDevice(
- basegfx::B2IVector(3,3),
- pDevice ));
- basebmp::Color aCol1(0);
- basebmp::Color aCol2(0xFFFFFFFF);
- pBmp->clear(aCol1);
- pBmp->setPixel(basegfx::B2IPoint(0,0),aCol2,basebmp::DrawMode_PAINT);
- pBmp->setPixel(basegfx::B2IPoint(1,1),aCol2,basebmp::DrawMode_PAINT);
- pBmp->setPixel(basegfx::B2IPoint(2,2),aCol2,basebmp::DrawMode_PAINT);
-
- pDevice->clear(aCol1);
- pDevice->drawBitmap(pBmp,
- basegfx::B2IRange(0,0,3,3),
- basegfx::B2IRange(2,2,7,7),
-// basegfx::B2IRange(-1,-1,5,5),
- basebmp::DrawMode_PAINT,
- pMask);
-
- std::ofstream output("32bpp_test.dump");
- debugDump( pDevice, output );
- std::ofstream output2("32bpp_bmp.dump");
- debugDump( pBmp, output2 );
- std::ofstream output3("clipmask.dump");
- debugDump( pMask, output3 );
- }
-
- enum{ srcBitDepth=1, dstBitDepth=4 };
- typedef vigra::RGBValue< sal_uInt8 > RGBVal;
-
- Bitmap aSourceBitmap( Size(100,100),
- srcBitDepth );
- DrawBitmap( Point(0,350), aSourceBitmap );
-
- // Fill bitmap with rhombus
- {
- ScopedBitmapWriteAccess pWriteAccess( aSourceBitmap.AcquireWriteAccess(),
- aSourceBitmap );
- pWriteAccess->SetFillColor(0xFF0000);
- Polygon aPoly(5);
- aPoly[0] = Point(50,0);
- aPoly[1] = Point(100,50);
- aPoly[2] = Point(50,100);
- aPoly[3] = Point(0,50);
- aPoly[4] = Point(50,0);
- pWriteAccess->FillPolygon(aPoly);
- }
-
- Bitmap aDestBitmap( Size(300,300),
- dstBitDepth );
-
- {
- ScopedBitmapReadAccess pReadAccess( aSourceBitmap.AcquireReadAccess(),
- aSourceBitmap );
- ScopedBitmapWriteAccess pWriteAccess( aDestBitmap.AcquireWriteAccess(),
- aDestBitmap );
-
- const sal_Int32 nSrcWidth( pReadAccess->Width() );
- const sal_Int32 nSrcHeight( pReadAccess->Height() );
- const bool bSrcTopDown( pReadAccess->IsTopDown() );
- const sal_uInt32 nSrcScanlineFormat( pReadAccess->GetScanlineFormat() );
- const sal_uInt32 nSrcScanlineStride( pReadAccess->GetScanlineSize() );
- const sal_uInt16 nSrcBitCount( pReadAccess->GetBitCount() );
- const sal_uInt16 nSrcPaletteEntries( pReadAccess->GetPaletteEntryCount() );
- const BitmapColor* pSrcPalette( &pReadAccess->GetPalette()[0] );
- const BYTE* pSrcBuffer = pReadAccess->GetBuffer();
-
- const sal_Int32 nDstWidth( pWriteAccess->Width() );
- const sal_Int32 nDstHeight( pWriteAccess->Height() );
- const bool bDstTopDown( pWriteAccess->IsTopDown() );
- const sal_uInt32 nDstScanlineFormat( pWriteAccess->GetScanlineFormat() );
- const sal_uInt32 nDstScanlineStride( pWriteAccess->GetScanlineSize() );
- const sal_uInt16 nDstBitCount( pWriteAccess->GetBitCount() );
- const sal_uInt16 nDstPaletteEntries( pWriteAccess->GetPaletteEntryCount() );
- const BitmapColor* pDstPalette( &pWriteAccess->GetPalette()[0] );
- BYTE* pDstBuffer = pWriteAccess->GetBuffer();
-
- typedef PackedPixelIterator< const BYTE,
- BYTE,
- srcBitDepth,
- true > SrcPixelIterator;
- typedef PaletteImageAccessor< RGBVal, BYTE > SrcImageAccessor;
-
- typedef PackedPixelIterator< BYTE,
- BYTE,
- dstBitDepth,
- true > DstPixelIterator;
- typedef PaletteImageAccessor< RGBVal, BYTE > DstImageAccessor;
-
- const SrcPixelIterator aStartImage( pSrcBuffer,nSrcScanlineStride );
- const SrcPixelIterator aEndImage( aStartImage + vigra::Diff2D(nSrcWidth,nSrcHeight) );
-
- const DstPixelIterator aStartDstImage( pDstBuffer,nDstScanlineStride );
- const DstPixelIterator aEndDstImage( aStartDstImage + vigra::Diff2D(nDstWidth,nDstHeight) );
-
- vigra::resizeImageNoInterpolation(
- //vigra::resizeImageLinearInterpolation(
- vigra::make_triple(
- aStartImage,
- aEndImage,
- SrcImageAccessor(
- pSrcPalette,
- nSrcPaletteEntries)),
- vigra::make_triple(
- aStartDstImage,
- aEndDstImage,
- DstImageAccessor(
- pDstPalette,
- nDstPaletteEntries)));
- }
-
- DrawBitmap( Point(), aDestBitmap );
-
-
- Bitmap aDestBitmap2( Size(300,300),
- dstBitDepth );
-
- {
- ScopedBitmapReadAccess pReadAccess( aSourceBitmap.AcquireReadAccess(),
- aSourceBitmap );
- ScopedBitmapWriteAccess pWriteAccess( aDestBitmap2.AcquireWriteAccess(),
- aDestBitmap2 );
-
- const sal_Int32 nSrcWidth( pReadAccess->Width() );
- const sal_Int32 nSrcHeight( pReadAccess->Height() );
- const bool bSrcTopDown( pReadAccess->IsTopDown() );
- const sal_uInt32 nSrcScanlineFormat( pReadAccess->GetScanlineFormat() );
- const sal_uInt32 nSrcScanlineStride( pReadAccess->GetScanlineSize() );
- const sal_uInt16 nSrcBitCount( pReadAccess->GetBitCount() );
- const sal_uInt16 nSrcPaletteEntries( pReadAccess->GetPaletteEntryCount() );
- const BitmapColor* pSrcPalette( &pReadAccess->GetPalette()[0] );
- const BYTE* pSrcBuffer = pReadAccess->GetBuffer();
-
- const sal_Int32 nDstWidth( pWriteAccess->Width() );
- const sal_Int32 nDstHeight( pWriteAccess->Height() );
- const bool bDstTopDown( pWriteAccess->IsTopDown() );
- const sal_uInt32 nDstScanlineFormat( pWriteAccess->GetScanlineFormat() );
- const sal_uInt32 nDstScanlineStride( pWriteAccess->GetScanlineSize() );
- const sal_uInt16 nDstBitCount( pWriteAccess->GetBitCount() );
- const sal_uInt16 nDstPaletteEntries( pWriteAccess->GetPaletteEntryCount() );
- const BitmapColor* pDstPalette( &pWriteAccess->GetPalette()[0] );
- BYTE* pDstBuffer = pWriteAccess->GetBuffer();
-
- typedef vigra::RGBValue< sal_uInt8 > RGBVal;
- typedef PackedPixelIterator< const BYTE,
- BYTE,
- srcBitDepth,
- true > SrcPixelIterator;
- typedef PaletteImageAccessor< RGBVal,BYTE > SrcImageAccessor;
-
- typedef PackedPixelIterator< BYTE,
- BYTE,
- dstBitDepth,
- true > DstPixelIterator;
- typedef PaletteImageAccessor< RGBVal,BYTE > DstImageAccessor;
-
- const SrcPixelIterator aStartImage( pSrcBuffer,nSrcScanlineStride );
- const SrcPixelIterator aEndImage( aStartImage + vigra::Diff2D(nSrcWidth,nSrcHeight) );
-
- const DstPixelIterator aStartDstImage( pDstBuffer,nDstScanlineStride );
- const DstPixelIterator aEndDstImage( aStartDstImage + vigra::Diff2D(nDstWidth,nDstHeight) );
-
- vigra::resizeImageLinearInterpolation(
- vigra::make_triple(
- aStartImage,
- aEndImage,
- SrcImageAccessor(
- pSrcPalette,
- nSrcPaletteEntries)),
- vigra::make_triple(
- aStartDstImage,
- aEndDstImage,
- DstImageAccessor(
- pDstPalette,
- nDstPaletteEntries)));
- }
-
- DrawBitmap( Point(310,0), aDestBitmap2 );
-
-
- Bitmap aDestBitmap3( Size(300,300),
- 24 );
-
- {
- ScopedBitmapReadAccess pReadAccess( aSourceBitmap.AcquireReadAccess(),
- aSourceBitmap );
- ScopedBitmapWriteAccess pWriteAccess( aDestBitmap3.AcquireWriteAccess(),
- aDestBitmap3 );
-
- const sal_Int32 nSrcWidth( pReadAccess->Width() );
- const sal_Int32 nSrcHeight( pReadAccess->Height() );
- const bool bSrcTopDown( pReadAccess->IsTopDown() );
- const sal_uInt32 nSrcScanlineFormat( pReadAccess->GetScanlineFormat() );
- const sal_uInt32 nSrcScanlineStride( pReadAccess->GetScanlineSize() );
- const sal_uInt16 nSrcBitCount( pReadAccess->GetBitCount() );
- const sal_uInt16 nSrcPaletteEntries( pReadAccess->GetPaletteEntryCount() );
- const BitmapColor* pSrcPalette( &pReadAccess->GetPalette()[0] );
- const BYTE* pSrcBuffer = pReadAccess->GetBuffer();
-
- const sal_Int32 nDstWidth( pWriteAccess->Width() );
- const sal_Int32 nDstHeight( pWriteAccess->Height() );
- const bool bDstTopDown( pWriteAccess->IsTopDown() );
- const sal_uInt32 nDstScanlineFormat( pWriteAccess->GetScanlineFormat() );
- const sal_uInt32 nDstScanlineStride( pWriteAccess->GetScanlineSize() );
- const sal_uInt16 nDstBitCount( pWriteAccess->GetBitCount() );
- BYTE* pDstBuffer = pWriteAccess->GetBuffer();
-
- vigra::BasicImageView< RGBVal > aDestImage(
- reinterpret_cast<RGBVal*>(pDstBuffer),
- nDstWidth,
- nDstHeight,
- 0 /*nDstScanlineStride should be an integer multiple of 4*/ );
-
- typedef PackedPixelIterator< const BYTE,
- BYTE,
- srcBitDepth,
- true > SrcPixelIterator;
- typedef PaletteImageAccessor< RGBVal,BYTE > SrcImageAccessor;
-
- const SrcPixelIterator aStartImage( pSrcBuffer,nSrcScanlineStride );
- const SrcPixelIterator aEndImage( aStartImage + vigra::Diff2D(nSrcWidth,nSrcHeight) );
-
- // resize bitmap
- vigra::resizeImageSplineInterpolation(
- vigra::make_triple(
- aStartImage,
- aEndImage,
- SrcImageAccessor(
- pSrcPalette,
- nSrcPaletteEntries)),
- vigra::destImageRange(aDestImage));
-
- // add ellipse to bitmap
- basegfx::B2DPolygon aPoly(
- basegfx::tools::createPolygonFromEllipse(
- basegfx::B2DPoint(150,150),
- 50, 80 ));
- aPoly = basegfx::tools::adaptiveSubdivideByCount(aPoly);
- makeRenderer( basegfx::B2DPolyPolygon( aPoly ),
- RGBVal(0,0xFF,0),
- RGBVal(0xFF,0xFF,0xFF),
- vigra::destImageRange(aDestImage) )->rasterConvert(
- basegfx::FillRule_NONZERO_WINDING_NUMBER );
- }
-
- DrawBitmap( Point(620,0), aDestBitmap3 );
- DrawBitmap( Point(310,350), aSourceBitmap );
+ debugDump( pDevice, output4 );
+ }
+
+ Bitmap aBitmap( Size(aTestSize.getX(),
+ aTestSize.getY()), 24 );
+
+ // Fill bitmap with generated content
+ {
+ ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(),
+ aBitmap );
+ for( int y=0; y<aTestSize.getY(); ++y )
+ for( int x=0; x<aTestSize.getX(); ++x )
+ pWriteAccess->SetPixel(y,x,
+ Color(pDevice->getPixelData(basegfx::B2IPoint(x,y))) );
+ }
+
+ DrawBitmap( Point(), aBitmap );
}
USHORT TestApp::Exception( USHORT nError )
diff --git a/basebmp/test/cliptest.cxx b/basebmp/test/cliptest.cxx
new file mode 100644
index 000000000000..bf6dbc3d7376
--- /dev/null
+++ b/basebmp/test/cliptest.cxx
@@ -0,0 +1,274 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: cliptest.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: thb $ $Date: 2006-06-28 16:50:20 $
+ *
+ * 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
+ *
+ ************************************************************************/
+
+// autogenerated file with codegen.pl
+
+#include <cppunit/simpleheader.hxx>
+
+#include <basegfx/vector/b2isize.hxx>
+#include <basegfx/point/b2ipoint.hxx>
+#include <basegfx/range/b2drange.hxx>
+#include <basegfx/range/b2irange.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
+
+#include <basebmp/color.hxx>
+#include <basebmp/scanlineformats.hxx>
+#include <basebmp/bitmapdevice.hxx>
+#include <basebmp/debug.hxx>
+#include "tools.hxx"
+
+#include <iostream>
+#include <fstream>
+
+using namespace ::basebmp;
+
+namespace
+{
+/*
+ std::ofstream output("32bpp_test.dump");
+ debugDump( mpDevice32bpp, output );
+*/
+
+class ClipTest : public CppUnit::TestFixture
+{
+private:
+ BitmapDeviceSharedPtr mpClipMask;
+ BitmapDeviceSharedPtr mpDevice1bpp;
+ BitmapDeviceSharedPtr mpDevice32bpp;
+
+ void implTestPixelClip(const BitmapDeviceSharedPtr& rDevice)
+ {
+ const Color aBgCol(0);
+ rDevice->clear(aBgCol);
+
+ const basegfx::B2IPoint aPt(0,0);
+ const Color aCol(0xFFFFFFFF);
+ rDevice->setPixel( aPt, aCol, DrawMode_PAINT, mpClipMask );
+ CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #1",
+ rDevice->getPixel(aPt) == aBgCol);
+
+ const basegfx::B2IPoint aPt2(10,10);
+ rDevice->setPixel( aPt2, aCol, DrawMode_PAINT, mpClipMask );
+ CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #2",
+ rDevice->getPixel(aPt2) == aBgCol);
+
+ const basegfx::B2IPoint aPt1(10,0);
+ rDevice->setPixel( aPt1, aCol, DrawMode_PAINT, mpClipMask );
+ CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #3",
+ rDevice->getPixel(aPt1) != aBgCol);
+
+ const basegfx::B2IPoint aPt3(0,10);
+ rDevice->setPixel( aPt3, aCol, DrawMode_PAINT, mpClipMask );
+ CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #4",
+ rDevice->getPixel(aPt3) != aBgCol);
+ }
+
+ void implTestLineClip(const BitmapDeviceSharedPtr& rDevice)
+ {
+ const Color aBgCol(0);
+ rDevice->clear(aBgCol);
+
+ const basegfx::B2IPoint aPt1(0,0);
+ const basegfx::B2IPoint aPt2(1,9);
+ const Color aCol(0xFFFFFFFF);
+ rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT, mpClipMask );
+
+ std::ofstream output("32bpp_test.dump");
+ debugDump( mpDevice32bpp, output );
+
+ const basegfx::B2IPoint aPt3(1,5);
+ CPPUNIT_ASSERT_MESSAGE("get line pixel",
+ rDevice->getPixel(aPt3) != aBgCol);
+ CPPUNIT_ASSERT_MESSAGE("number of rendered line pixel is not 4",
+ countPixel( rDevice,
+ rDevice->getPixel(aPt3) ) == 4);
+ }
+
+ void implTestFillClip(const BitmapDeviceSharedPtr& rDevice)
+ {
+ rDevice->clear(Color(0));
+
+ const basegfx::B2DRange aAllOver(-10,-10,20,20);
+ const Color aCol(0xFFFFFFFF);
+ rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
+ basegfx::tools::createPolygonFromRect(aAllOver)),
+ aCol,
+ DrawMode_PAINT,
+ mpClipMask );
+ const basegfx::B2IPoint aPt(0,10);
+ CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 28",
+ countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-28);
+ }
+
+ void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice)
+ {
+ BitmapDeviceSharedPtr pBmp( cloneBitmapDevice(
+ basegfx::B2IVector(3,3),
+ rDevice ));
+ Color aCol1(0);
+ Color aCol2(0xFFFFFFFF);
+ pBmp->clear(aCol1);
+ pBmp->setPixel(basegfx::B2IPoint(0,0),aCol2,DrawMode_PAINT);
+ pBmp->setPixel(basegfx::B2IPoint(1,1),aCol2,DrawMode_PAINT);
+ pBmp->setPixel(basegfx::B2IPoint(2,2),aCol2,basebmp::DrawMode_PAINT);
+
+ rDevice->clear(aCol1);
+ rDevice->drawBitmap(pBmp,
+ basegfx::B2IRange(0,0,3,3),
+ basegfx::B2IRange(-1,-1,4,4),
+ DrawMode_PAINT,
+ mpClipMask);
+
+ const basegfx::B2IPoint aPt(1,1);
+ CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 5",
+ countPixel( rDevice,
+ rDevice->getPixel(aPt) ) == 5);
+ }
+
+ void implTestMaskColorClip(const BitmapDeviceSharedPtr& rDevice)
+ {
+ BitmapDeviceSharedPtr pBmp( createBitmapDevice( rDevice->getSize(),
+ true,
+ Format::EIGHT_BIT_GRAY ));
+
+ ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
+ "m 0 0h5v10h5v-5h-10z" );
+
+ basegfx::B2DPolyPolygon aPoly;
+ basegfx::tools::importFromSvgD( aPoly, aSvg );
+ const basebmp::Color aCol(0xFF);
+ pBmp->clear( basebmp::Color(0) );
+ pBmp->fillPolyPolygon(
+ aPoly,
+ aCol,
+ basebmp::DrawMode_PAINT );
+
+ const basegfx::B2IRange aSourceRect(0,0,10,10);
+ const basegfx::B2IPoint aDestLeftTop(0,0);
+ const Color aCol2(0xF0F0F0F0);
+ rDevice->drawMaskedColor(
+ aCol2,
+ pBmp,
+ aSourceRect,
+ aDestLeftTop,
+ mpClipMask );
+ const basegfx::B2IPoint aPt(1,1);
+ CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 41",
+ countPixel( rDevice, rDevice->getPixel(aPt) ) == 41);
+
+ }
+
+public:
+ void setUp()
+ {
+ const basegfx::B2ISize aSize(11,11);
+ mpClipMask = createBitmapDevice( aSize,
+ true,
+ Format::ONE_BIT_MSB_GRAY );
+ mpDevice1bpp = createBitmapDevice( aSize,
+ true,
+ Format::ONE_BIT_MSB_PAL );
+ mpDevice32bpp = createBitmapDevice( aSize,
+ true,
+ Format::THIRTYTWO_BIT_TC_MASK );
+
+ ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
+ "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" );
+ basegfx::B2DPolyPolygon aPoly;
+ basegfx::tools::importFromSvgD( aPoly, aSvg );
+ mpClipMask->clear(Color(0xFFFFFFFF));
+ mpClipMask->drawPolygon(
+ aPoly.getB2DPolygon(0),
+ Color(0),
+ DrawMode_PAINT );
+ }
+
+ void testPixelClip()
+ {
+ implTestPixelClip( mpDevice1bpp );
+ implTestPixelClip( mpDevice32bpp );
+ }
+
+ void testLineClip()
+ {
+ implTestLineClip( mpDevice1bpp );
+ implTestLineClip( mpDevice32bpp );
+ }
+
+ void testFillClip()
+ {
+ implTestFillClip( mpDevice1bpp );
+ implTestFillClip( mpDevice32bpp );
+ }
+
+ void testBmpClip()
+ {
+ implTestBmpClip( mpDevice1bpp );
+ implTestBmpClip( mpDevice32bpp );
+ }
+
+ void testMaskColorClip()
+ {
+ implTestMaskColorClip( mpDevice1bpp );
+ implTestMaskColorClip( mpDevice32bpp );
+ }
+
+ // 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(ClipTest);
+ CPPUNIT_TEST(testPixelClip);
+ CPPUNIT_TEST(testLineClip);
+ CPPUNIT_TEST(testFillClip);
+ CPPUNIT_TEST(testBmpClip);
+ CPPUNIT_TEST(testMaskColorClip);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ClipTest, "ClipTest");
+}
+
+
+// -----------------------------------------------------------------------------
+
+// this macro creates an empty function, which will called by the RegisterAllFunctions()
+// to let the user the possibility to also register some functions by hand.
+//NOADDITIONAL;
+