1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cliptest.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // autogenerated file with codegen.pl
33 #include <cppunit/simpleheader.hxx>
35 #include <basegfx/vector/b2isize.hxx>
36 #include <basegfx/point/b2ipoint.hxx>
37 #include <basegfx/range/b2drange.hxx>
38 #include <basegfx/range/b2irange.hxx>
39 #include <basegfx/polygon/b2dpolygon.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <basegfx/polygon/b2dpolypolygon.hxx>
42 #include <basegfx/polygon/b2dpolypolygontools.hxx>
44 #include <basebmp/color.hxx>
45 #include <basebmp/scanlineformats.hxx>
46 #include <basebmp/bitmapdevice.hxx>
47 #include <basebmp/debug.hxx>
53 using namespace ::basebmp
;
58 std::ofstream output("32bpp_test.dump");
59 debugDump( mpDevice32bpp, output );
62 class ClipTest
: public CppUnit::TestFixture
65 BitmapDeviceSharedPtr mpClipMask
;
66 BitmapDeviceSharedPtr mpDevice1bpp
;
67 BitmapDeviceSharedPtr mpDevice32bpp
;
69 void implTestPixelClip(const BitmapDeviceSharedPtr
& rDevice
)
71 const Color
aBgCol(0);
72 rDevice
->clear(aBgCol
);
74 const basegfx::B2IPoint
aPt(0,0);
75 const Color
aCol(0xFFFFFFFF);
76 rDevice
->setPixel( aPt
, aCol
, DrawMode_PAINT
, mpClipMask
);
77 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #1",
78 rDevice
->getPixel(aPt
) == aBgCol
);
80 const basegfx::B2IPoint
aPt2(10,10);
81 rDevice
->setPixel( aPt2
, aCol
, DrawMode_PAINT
, mpClipMask
);
82 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #2",
83 rDevice
->getPixel(aPt2
) == aBgCol
);
85 const basegfx::B2IPoint
aPt1(10,0);
86 rDevice
->setPixel( aPt1
, aCol
, DrawMode_PAINT
, mpClipMask
);
87 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #3",
88 rDevice
->getPixel(aPt1
) != aBgCol
);
90 const basegfx::B2IPoint
aPt3(0,10);
91 rDevice
->setPixel( aPt3
, aCol
, DrawMode_PAINT
, mpClipMask
);
92 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #4",
93 rDevice
->getPixel(aPt3
) != aBgCol
);
96 void implTestLineClip(const BitmapDeviceSharedPtr
& rDevice
)
98 const Color
aBgCol(0);
99 rDevice
->clear(aBgCol
);
101 const basegfx::B2IPoint
aPt1(0,0);
102 const basegfx::B2IPoint
aPt2(1,9);
103 const Color
aCol(0xFFFFFFFF);
104 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
, mpClipMask
);
106 const basegfx::B2IPoint
aPt3(1,5);
107 CPPUNIT_ASSERT_MESSAGE("get line pixel",
108 rDevice
->getPixel(aPt3
) != aBgCol
);
109 CPPUNIT_ASSERT_MESSAGE("number of rendered line pixel is not 4",
111 rDevice
->getPixel(aPt3
) ) == 4);
113 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_XOR
, mpClipMask
);
114 CPPUNIT_ASSERT_MESSAGE("number of xor-rendered line pixel is not 0",
116 rDevice
->getPixel(aPt3
) ) == 121);
119 void implTestFillClip(const BitmapDeviceSharedPtr
& rDevice
)
121 rDevice
->clear(Color(0));
123 const basegfx::B2DRange
aAllOver(-10,-10,20,20);
124 const Color
aCol(0xFFFFFFFF);
125 rDevice
->fillPolyPolygon( basegfx::B2DPolyPolygon(
126 basegfx::tools::createPolygonFromRect(aAllOver
)),
130 const basegfx::B2IPoint
aPt(0,10);
131 CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 30",
132 countPixel( rDevice
, rDevice
->getPixel(aPt
) ) == 121-30);
134 rDevice
->fillPolyPolygon( basegfx::B2DPolyPolygon(
135 basegfx::tools::createPolygonFromRect(aAllOver
)),
138 CPPUNIT_ASSERT_MESSAGE("number of filled pixel is not 121",
139 countPixel( rDevice
, rDevice
->getPixel(aPt
) ) == 121);
141 rDevice
->fillPolyPolygon( basegfx::B2DPolyPolygon(
142 basegfx::tools::createPolygonFromRect(aAllOver
)),
146 CPPUNIT_ASSERT_MESSAGE("number of xor-cleared pixel is not 91",
147 countPixel( rDevice
, rDevice
->getPixel(aPt
) ) == 121-30);
150 void implTestBmpClip(const BitmapDeviceSharedPtr
& rDevice
)
152 BitmapDeviceSharedPtr
pBmp( cloneBitmapDevice(
153 basegfx::B2IVector(3,3),
156 Color
aCol2(0xFFFFFFFF);
158 pBmp
->setPixel(basegfx::B2IPoint(0,0),aCol2
,DrawMode_PAINT
);
159 pBmp
->setPixel(basegfx::B2IPoint(1,1),aCol2
,DrawMode_PAINT
);
160 pBmp
->setPixel(basegfx::B2IPoint(2,2),aCol2
,basebmp::DrawMode_PAINT
);
162 rDevice
->clear(aCol1
);
163 rDevice
->drawBitmap(pBmp
,
164 basegfx::B2IRange(0,0,3,3),
165 basegfx::B2IRange(-1,-1,4,4),
169 const basegfx::B2IPoint
aPt(1,1);
170 CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 5",
172 rDevice
->getPixel(aPt
) ) == 5);
175 void implTestMaskColorClip(const BitmapDeviceSharedPtr
& rDevice
)
177 BitmapDeviceSharedPtr
pBmp( createBitmapDevice( rDevice
->getSize(),
179 Format::EIGHT_BIT_GREY
));
181 ::rtl::OUString aSvg
= ::rtl::OUString::createFromAscii(
182 "m 0 0h5v10h5v-5h-10z" );
184 basegfx::B2DPolyPolygon aPoly
;
185 basegfx::tools::importFromSvgD( aPoly
, aSvg
);
186 const basebmp::Color
aCol(0xFF);
187 pBmp
->clear( basebmp::Color(0) );
188 pBmp
->fillPolyPolygon(
191 basebmp::DrawMode_PAINT
);
193 const basegfx::B2IRange
aSourceRect(0,0,10,10);
194 const basegfx::B2IPoint
aDestLeftTop(0,0);
195 const Color
aCol2(0xF0F0F0F0);
196 rDevice
->drawMaskedColor(
202 const basegfx::B2IPoint
aPt(1,1);
203 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 41",
204 countPixel( rDevice
, rDevice
->getPixel(aPt
) ) == 41);
211 const basegfx::B2ISize
aSize(11,11);
212 mpClipMask
= createBitmapDevice( aSize
,
214 Format::ONE_BIT_MSB_GREY
);
215 mpDevice1bpp
= createBitmapDevice( aSize
,
217 Format::ONE_BIT_MSB_PAL
);
218 mpDevice32bpp
= createBitmapDevice( aSize
,
220 Format::THIRTYTWO_BIT_TC_MASK
);
222 ::rtl::OUString aSvg
= ::rtl::OUString::createFromAscii(
223 "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" );
224 basegfx::B2DPolyPolygon aPoly
;
225 basegfx::tools::importFromSvgD( aPoly
, aSvg
);
226 mpClipMask
->clear(Color(0));
227 mpClipMask
->drawPolygon(
228 aPoly
.getB2DPolygon(0),
235 implTestPixelClip( mpDevice1bpp
);
236 implTestPixelClip( mpDevice32bpp
);
241 implTestLineClip( mpDevice1bpp
);
242 implTestLineClip( mpDevice32bpp
);
247 implTestFillClip( mpDevice1bpp
);
248 implTestFillClip( mpDevice32bpp
);
253 implTestBmpClip( mpDevice1bpp
);
254 implTestBmpClip( mpDevice32bpp
);
257 void testMaskColorClip()
259 implTestMaskColorClip( mpDevice1bpp
);
260 implTestMaskColorClip( mpDevice32bpp
);
263 // Change the following lines only, if you add, remove or rename
264 // member functions of the current class,
265 // because these macros are need by auto register mechanism.
267 CPPUNIT_TEST_SUITE(ClipTest
);
268 CPPUNIT_TEST(testPixelClip
);
269 CPPUNIT_TEST(testLineClip
);
270 CPPUNIT_TEST(testFillClip
);
271 CPPUNIT_TEST(testBmpClip
);
272 CPPUNIT_TEST(testMaskColorClip
);
273 CPPUNIT_TEST_SUITE_END();
276 // -----------------------------------------------------------------------------
277 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ClipTest
, "ClipTest");
281 // -----------------------------------------------------------------------------
283 // this macro creates an empty function, which will called by the RegisterAllFunctions()
284 // to let the user the possibility to also register some functions by hand.