xref: /aoo42x/main/basebmp/test/bmptest.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/range/b2irange.hxx>
38*cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx>
39*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
40*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
41*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
42*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <basebmp/color.hxx>
45*cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
46*cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx>
47*cdf0e10cSrcweir #include <basebmp/debug.hxx>
48*cdf0e10cSrcweir #include "tools.hxx"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <iostream>
51*cdf0e10cSrcweir #include <fstream>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir using namespace ::basebmp;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir /*
58*cdf0e10cSrcweir         std::ofstream output("32bpp_test.dump");
59*cdf0e10cSrcweir         debugDump( rDevice, output );
60*cdf0e10cSrcweir         std::ofstream output2("32bpp_bmp.dump");
61*cdf0e10cSrcweir         debugDump( rBmp, output2 );
62*cdf0e10cSrcweir */
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir class BmpTest : public CppUnit::TestFixture
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir private:
67*cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice1bpp;
68*cdf0e10cSrcweir     BitmapDeviceSharedPtr mpBmp1bpp;
69*cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice32bpp;
70*cdf0e10cSrcweir     BitmapDeviceSharedPtr mpBmp32bpp;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
73*cdf0e10cSrcweir                            const BitmapDeviceSharedPtr& rBmp)
74*cdf0e10cSrcweir     {
75*cdf0e10cSrcweir         rDevice->clear(Color(0));
76*cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir         const basegfx::B2IRange aSourceRect(0,0,10,10);
79*cdf0e10cSrcweir         const basegfx::B2IRange aDestLeftTop(0,0,4,4);
80*cdf0e10cSrcweir         const basegfx::B2IRange aDestRightTop(6,0,10,4);
81*cdf0e10cSrcweir         const basegfx::B2IRange aDestLeftBottom(0,6,4,10);
82*cdf0e10cSrcweir         const basegfx::B2IRange aDestRightBottom(6,6,10,10);
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir         rDevice->drawBitmap(
85*cdf0e10cSrcweir             rBmp,
86*cdf0e10cSrcweir             aSourceRect,
87*cdf0e10cSrcweir             aDestLeftTop,
88*cdf0e10cSrcweir             DrawMode_PAINT );
89*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
90*cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 8);
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         rDevice->drawBitmap(
93*cdf0e10cSrcweir             rBmp,
94*cdf0e10cSrcweir             aSourceRect,
95*cdf0e10cSrcweir             aDestRightTop,
96*cdf0e10cSrcweir             DrawMode_PAINT );
97*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
98*cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 16);
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         rDevice->drawBitmap(
101*cdf0e10cSrcweir             rBmp,
102*cdf0e10cSrcweir             aSourceRect,
103*cdf0e10cSrcweir             aDestLeftBottom,
104*cdf0e10cSrcweir             DrawMode_PAINT );
105*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
106*cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 24);
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir         rDevice->drawBitmap(
109*cdf0e10cSrcweir             rBmp,
110*cdf0e10cSrcweir             aSourceRect,
111*cdf0e10cSrcweir             aDestRightBottom,
112*cdf0e10cSrcweir             DrawMode_PAINT );
113*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
114*cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 32);
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
118*cdf0e10cSrcweir                          const BitmapDeviceSharedPtr& rBmp)
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         rDevice->clear(Color(0));
121*cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir         const basegfx::B2IRange aSourceRect(0,0,10,10);
124*cdf0e10cSrcweir         const basegfx::B2IRange aDestLeftTop(-2,-2,2,2);
125*cdf0e10cSrcweir         const basegfx::B2IRange aDestRightTop(8,-2,12,2);
126*cdf0e10cSrcweir         const basegfx::B2IRange aDestLeftBottom(-2,8,2,12);
127*cdf0e10cSrcweir         const basegfx::B2IRange aDestRightBottom(8,8,12,12);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         rDevice->drawBitmap(
130*cdf0e10cSrcweir             rBmp,
131*cdf0e10cSrcweir             aSourceRect,
132*cdf0e10cSrcweir             aDestLeftTop,
133*cdf0e10cSrcweir             DrawMode_PAINT );
134*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
135*cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 4);
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         rDevice->drawBitmap(
138*cdf0e10cSrcweir             rBmp,
139*cdf0e10cSrcweir             aSourceRect,
140*cdf0e10cSrcweir             aDestLeftBottom,
141*cdf0e10cSrcweir             DrawMode_PAINT );
142*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
143*cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 4);
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir         rDevice->drawBitmap(
146*cdf0e10cSrcweir             rBmp,
147*cdf0e10cSrcweir             aSourceRect,
148*cdf0e10cSrcweir             aDestRightBottom,
149*cdf0e10cSrcweir             DrawMode_PAINT );
150*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
151*cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 8);
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir public:
155*cdf0e10cSrcweir     void setUp()
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         const basegfx::B2ISize aSize(10,10);
158*cdf0e10cSrcweir         mpDevice1bpp = createBitmapDevice( aSize,
159*cdf0e10cSrcweir                                            true,
160*cdf0e10cSrcweir                                            Format::ONE_BIT_MSB_PAL );
161*cdf0e10cSrcweir         mpDevice32bpp = createBitmapDevice( aSize,
162*cdf0e10cSrcweir                                             true,
163*cdf0e10cSrcweir                                             Format::THIRTYTWO_BIT_TC_MASK );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         mpBmp1bpp = createBitmapDevice( aSize,
166*cdf0e10cSrcweir                                         true,
167*cdf0e10cSrcweir                                         Format::ONE_BIT_MSB_PAL );
168*cdf0e10cSrcweir         mpBmp32bpp = createBitmapDevice( aSize,
169*cdf0e10cSrcweir                                          true,
170*cdf0e10cSrcweir                                          Format::THIRTYTWO_BIT_TC_MASK );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
173*cdf0e10cSrcweir             "m 0 0h5v10h5v-5h-10z" );
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
176*cdf0e10cSrcweir         basegfx::tools::importFromSvgD( aPoly, aSvg );
177*cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
178*cdf0e10cSrcweir         mpBmp1bpp->fillPolyPolygon(
179*cdf0e10cSrcweir             aPoly,
180*cdf0e10cSrcweir             aCol,
181*cdf0e10cSrcweir             DrawMode_PAINT );
182*cdf0e10cSrcweir         mpBmp32bpp->fillPolyPolygon(
183*cdf0e10cSrcweir             aPoly,
184*cdf0e10cSrcweir             aCol,
185*cdf0e10cSrcweir             DrawMode_PAINT );
186*cdf0e10cSrcweir     }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     void testBmpBasics()
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
191*cdf0e10cSrcweir         implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
192*cdf0e10cSrcweir     }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     void testBmpClip()
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         implTestBmpClip( mpDevice1bpp, mpBmp1bpp );
197*cdf0e10cSrcweir         implTestBmpClip( mpDevice32bpp, mpBmp32bpp );
198*cdf0e10cSrcweir     }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
201*cdf0e10cSrcweir     // member functions of the current class,
202*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(BmpTest);
205*cdf0e10cSrcweir     CPPUNIT_TEST(testBmpBasics);
206*cdf0e10cSrcweir     CPPUNIT_TEST(testBmpClip);
207*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
208*cdf0e10cSrcweir };
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir // -----------------------------------------------------------------------------
211*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(BmpTest);
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir // -----------------------------------------------------------------------------
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
218*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
219*cdf0e10cSrcweir //NOADDITIONAL;
220*cdf0e10cSrcweir 
221