xref: /aoo41x/main/basebmp/test/cliptest.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // autogenerated file with codegen.pl
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "preextstl.h"
31*cdf0e10cSrcweir #include "cppunit/TestAssert.h"
32*cdf0e10cSrcweir #include "cppunit/TestFixture.h"
33*cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h"
34*cdf0e10cSrcweir #include "postextstl.h"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx>
37*cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx>
38*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
39*cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx>
40*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
41*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
42*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
43*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <basebmp/color.hxx>
46*cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
47*cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx>
48*cdf0e10cSrcweir #include <basebmp/debug.hxx>
49*cdf0e10cSrcweir #include "tools.hxx"
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <iostream>
52*cdf0e10cSrcweir #include <fstream>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using namespace ::basebmp;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir namespace
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir /*
59*cdf0e10cSrcweir   std::ofstream output("32bpp_test.dump");
60*cdf0e10cSrcweir   debugDump( mpDevice32bpp, output );
61*cdf0e10cSrcweir */
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir class ClipTest : public CppUnit::TestFixture
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir private:
66*cdf0e10cSrcweir     BitmapDeviceSharedPtr mpClipMask;
67*cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice1bpp;
68*cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice32bpp;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     void implTestPixelClip(const BitmapDeviceSharedPtr& rDevice)
71*cdf0e10cSrcweir     {
72*cdf0e10cSrcweir         const Color aBgCol(0);
73*cdf0e10cSrcweir         rDevice->clear(aBgCol);
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir         const basegfx::B2IPoint aPt(0,0);
76*cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
77*cdf0e10cSrcweir         rDevice->setPixel( aPt, aCol, DrawMode_PAINT, mpClipMask );
78*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #1",
79*cdf0e10cSrcweir                                rDevice->getPixel(aPt) == aBgCol);
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir         const basegfx::B2IPoint aPt2(10,10);
82*cdf0e10cSrcweir         rDevice->setPixel( aPt2, aCol, DrawMode_PAINT, mpClipMask );
83*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #2",
84*cdf0e10cSrcweir                                rDevice->getPixel(aPt2) == aBgCol);
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         const basegfx::B2IPoint aPt1(10,0);
87*cdf0e10cSrcweir         rDevice->setPixel( aPt1, aCol, DrawMode_PAINT, mpClipMask );
88*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #3",
89*cdf0e10cSrcweir                                rDevice->getPixel(aPt1) != aBgCol);
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         const basegfx::B2IPoint aPt3(0,10);
92*cdf0e10cSrcweir         rDevice->setPixel( aPt3, aCol, DrawMode_PAINT, mpClipMask );
93*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #4",
94*cdf0e10cSrcweir                                rDevice->getPixel(aPt3) != aBgCol);
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     void implTestLineClip(const BitmapDeviceSharedPtr& rDevice)
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         const Color aBgCol(0);
100*cdf0e10cSrcweir         rDevice->clear(aBgCol);
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir         const basegfx::B2IPoint aPt1(0,0);
103*cdf0e10cSrcweir         const basegfx::B2IPoint aPt2(1,9);
104*cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
105*cdf0e10cSrcweir         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT, mpClipMask );
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         const basegfx::B2IPoint aPt3(1,5);
108*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("get line pixel",
109*cdf0e10cSrcweir                                rDevice->getPixel(aPt3) != aBgCol);
110*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered line pixel is not 4",
111*cdf0e10cSrcweir                                countPixel( rDevice,
112*cdf0e10cSrcweir                                            rDevice->getPixel(aPt3) ) == 4);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_XOR, mpClipMask );
115*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of xor-rendered line pixel is not 0",
116*cdf0e10cSrcweir                                countPixel( rDevice,
117*cdf0e10cSrcweir                                            rDevice->getPixel(aPt3) ) == 121);
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     void implTestFillClip(const BitmapDeviceSharedPtr& rDevice)
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         rDevice->clear(Color(0));
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         const basegfx::B2DRange aAllOver(-10,-10,20,20);
125*cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
126*cdf0e10cSrcweir         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
127*cdf0e10cSrcweir                                       basegfx::tools::createPolygonFromRect(aAllOver)),
128*cdf0e10cSrcweir                                   aCol,
129*cdf0e10cSrcweir                                   DrawMode_PAINT,
130*cdf0e10cSrcweir                                   mpClipMask );
131*cdf0e10cSrcweir         const basegfx::B2IPoint aPt(0,10);
132*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 30",
133*cdf0e10cSrcweir                                countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30);
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
136*cdf0e10cSrcweir                                       basegfx::tools::createPolygonFromRect(aAllOver)),
137*cdf0e10cSrcweir                                   aCol,
138*cdf0e10cSrcweir                                   DrawMode_PAINT );
139*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of filled pixel is not 121",
140*cdf0e10cSrcweir                                countPixel( rDevice, rDevice->getPixel(aPt) ) == 121);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
143*cdf0e10cSrcweir                                       basegfx::tools::createPolygonFromRect(aAllOver)),
144*cdf0e10cSrcweir                                   aCol,
145*cdf0e10cSrcweir                                   DrawMode_XOR,
146*cdf0e10cSrcweir                                   mpClipMask );
147*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of xor-cleared pixel is not 91",
148*cdf0e10cSrcweir                                countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30);
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice)
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         BitmapDeviceSharedPtr pBmp( cloneBitmapDevice(
154*cdf0e10cSrcweir                                         basegfx::B2IVector(3,3),
155*cdf0e10cSrcweir                                         rDevice ));
156*cdf0e10cSrcweir         Color aCol1(0);
157*cdf0e10cSrcweir         Color aCol2(0xFFFFFFFF);
158*cdf0e10cSrcweir         pBmp->clear(aCol1);
159*cdf0e10cSrcweir         pBmp->setPixel(basegfx::B2IPoint(0,0),aCol2,DrawMode_PAINT);
160*cdf0e10cSrcweir         pBmp->setPixel(basegfx::B2IPoint(1,1),aCol2,DrawMode_PAINT);
161*cdf0e10cSrcweir         pBmp->setPixel(basegfx::B2IPoint(2,2),aCol2,basebmp::DrawMode_PAINT);
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir         rDevice->clear(aCol1);
164*cdf0e10cSrcweir         rDevice->drawBitmap(pBmp,
165*cdf0e10cSrcweir                             basegfx::B2IRange(0,0,3,3),
166*cdf0e10cSrcweir                             basegfx::B2IRange(-1,-1,4,4),
167*cdf0e10cSrcweir                             DrawMode_PAINT,
168*cdf0e10cSrcweir                             mpClipMask);
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir         const basegfx::B2IPoint aPt(1,1);
171*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 5",
172*cdf0e10cSrcweir                                countPixel( rDevice,
173*cdf0e10cSrcweir                                            rDevice->getPixel(aPt) ) == 5);
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     void implTestMaskColorClip(const BitmapDeviceSharedPtr& rDevice)
177*cdf0e10cSrcweir     {
178*cdf0e10cSrcweir         BitmapDeviceSharedPtr pBmp( createBitmapDevice( rDevice->getSize(),
179*cdf0e10cSrcweir                                                         true,
180*cdf0e10cSrcweir                                                         Format::EIGHT_BIT_GREY ));
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
183*cdf0e10cSrcweir             "m 0 0h5v10h5v-5h-10z" );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
186*cdf0e10cSrcweir         basegfx::tools::importFromSvgD( aPoly, aSvg );
187*cdf0e10cSrcweir         const basebmp::Color aCol(0xFF);
188*cdf0e10cSrcweir         pBmp->clear( basebmp::Color(0) );
189*cdf0e10cSrcweir         pBmp->fillPolyPolygon(
190*cdf0e10cSrcweir             aPoly,
191*cdf0e10cSrcweir             aCol,
192*cdf0e10cSrcweir             basebmp::DrawMode_PAINT );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         const basegfx::B2IRange aSourceRect(0,0,10,10);
195*cdf0e10cSrcweir         const basegfx::B2IPoint aDestLeftTop(0,0);
196*cdf0e10cSrcweir         const Color aCol2(0xF0F0F0F0);
197*cdf0e10cSrcweir         rDevice->drawMaskedColor(
198*cdf0e10cSrcweir             aCol2,
199*cdf0e10cSrcweir             pBmp,
200*cdf0e10cSrcweir             aSourceRect,
201*cdf0e10cSrcweir             aDestLeftTop,
202*cdf0e10cSrcweir             mpClipMask );
203*cdf0e10cSrcweir         const basegfx::B2IPoint aPt(1,1);
204*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 41",
205*cdf0e10cSrcweir                                countPixel( rDevice, rDevice->getPixel(aPt) ) == 41);
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir public:
210*cdf0e10cSrcweir     void setUp()
211*cdf0e10cSrcweir     {
212*cdf0e10cSrcweir         const basegfx::B2ISize aSize(11,11);
213*cdf0e10cSrcweir         mpClipMask = createBitmapDevice( aSize,
214*cdf0e10cSrcweir                                          true,
215*cdf0e10cSrcweir                                          Format::ONE_BIT_MSB_GREY );
216*cdf0e10cSrcweir         mpDevice1bpp = createBitmapDevice( aSize,
217*cdf0e10cSrcweir                                            true,
218*cdf0e10cSrcweir                                            Format::ONE_BIT_MSB_PAL );
219*cdf0e10cSrcweir         mpDevice32bpp = createBitmapDevice( aSize,
220*cdf0e10cSrcweir                                            true,
221*cdf0e10cSrcweir                                            Format::THIRTYTWO_BIT_TC_MASK );
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
224*cdf0e10cSrcweir             "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" );
225*cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
226*cdf0e10cSrcweir         basegfx::tools::importFromSvgD( aPoly, aSvg );
227*cdf0e10cSrcweir         mpClipMask->clear(Color(0));
228*cdf0e10cSrcweir         mpClipMask->drawPolygon(
229*cdf0e10cSrcweir             aPoly.getB2DPolygon(0),
230*cdf0e10cSrcweir             Color(0xFFFFFFFF),
231*cdf0e10cSrcweir             DrawMode_PAINT );
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     void testPixelClip()
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir         implTestPixelClip( mpDevice1bpp );
237*cdf0e10cSrcweir         implTestPixelClip( mpDevice32bpp );
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     void testLineClip()
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir         implTestLineClip( mpDevice1bpp );
243*cdf0e10cSrcweir         implTestLineClip( mpDevice32bpp );
244*cdf0e10cSrcweir     }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir     void testFillClip()
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         implTestFillClip( mpDevice1bpp );
249*cdf0e10cSrcweir         implTestFillClip( mpDevice32bpp );
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir     void testBmpClip()
253*cdf0e10cSrcweir     {
254*cdf0e10cSrcweir         implTestBmpClip( mpDevice1bpp );
255*cdf0e10cSrcweir         implTestBmpClip( mpDevice32bpp );
256*cdf0e10cSrcweir     }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     void testMaskColorClip()
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         implTestMaskColorClip( mpDevice1bpp );
261*cdf0e10cSrcweir         implTestMaskColorClip( mpDevice32bpp );
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
265*cdf0e10cSrcweir     // member functions of the current class,
266*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(ClipTest);
269*cdf0e10cSrcweir     CPPUNIT_TEST(testPixelClip);
270*cdf0e10cSrcweir     CPPUNIT_TEST(testLineClip);
271*cdf0e10cSrcweir     CPPUNIT_TEST(testFillClip);
272*cdf0e10cSrcweir     CPPUNIT_TEST(testBmpClip);
273*cdf0e10cSrcweir     CPPUNIT_TEST(testMaskColorClip);
274*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
275*cdf0e10cSrcweir };
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir // -----------------------------------------------------------------------------
278*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(ClipTest);
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir // -----------------------------------------------------------------------------
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
285*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
286*cdf0e10cSrcweir //NOADDITIONAL;
287*cdf0e10cSrcweir 
288