xref: /aoo4110/main/basebmp/test/bmptest.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // autogenerated file with codegen.pl
25 
26 #include "preextstl.h"
27 #include "cppunit/TestAssert.h"
28 #include "cppunit/TestFixture.h"
29 #include "cppunit/extensions/HelperMacros.h"
30 #include "postextstl.h"
31 
32 #include <basegfx/vector/b2isize.hxx>
33 #include <basegfx/range/b2irange.hxx>
34 #include <basegfx/point/b2ipoint.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include <basegfx/polygon/b2dpolypolygon.hxx>
38 #include <basegfx/polygon/b2dpolypolygontools.hxx>
39 
40 #include <basebmp/color.hxx>
41 #include <basebmp/scanlineformats.hxx>
42 #include <basebmp/bitmapdevice.hxx>
43 #include <basebmp/debug.hxx>
44 #include "tools.hxx"
45 
46 #include <iostream>
47 #include <fstream>
48 
49 using namespace ::basebmp;
50 
51 namespace
52 {
53 /*
54         std::ofstream output("32bpp_test.dump");
55         debugDump( rDevice, output );
56         std::ofstream output2("32bpp_bmp.dump");
57         debugDump( rBmp, output2 );
58 */
59 
60 class BmpTest : public CppUnit::TestFixture
61 {
62 private:
63     BitmapDeviceSharedPtr mpDevice1bpp;
64     BitmapDeviceSharedPtr mpBmp1bpp;
65     BitmapDeviceSharedPtr mpDevice32bpp;
66     BitmapDeviceSharedPtr mpBmp32bpp;
67 
implTestBmpBasics(const BitmapDeviceSharedPtr & rDevice,const BitmapDeviceSharedPtr & rBmp)68     void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
69                            const BitmapDeviceSharedPtr& rBmp)
70     {
71         rDevice->clear(Color(0));
72         const Color aCol(0xFFFFFFFF);
73 
74         const basegfx::B2IRange aSourceRect(0,0,10,10);
75         const basegfx::B2IRange aDestLeftTop(0,0,4,4);
76         const basegfx::B2IRange aDestRightTop(6,0,10,4);
77         const basegfx::B2IRange aDestLeftBottom(0,6,4,10);
78         const basegfx::B2IRange aDestRightBottom(6,6,10,10);
79 
80         rDevice->drawBitmap(
81             rBmp,
82             aSourceRect,
83             aDestLeftTop,
84             DrawMode_PAINT );
85         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
86                                countPixel( rDevice, aCol ) == 8);
87 
88         rDevice->drawBitmap(
89             rBmp,
90             aSourceRect,
91             aDestRightTop,
92             DrawMode_PAINT );
93         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
94                                countPixel( rDevice, aCol ) == 16);
95 
96         rDevice->drawBitmap(
97             rBmp,
98             aSourceRect,
99             aDestLeftBottom,
100             DrawMode_PAINT );
101         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
102                                countPixel( rDevice, aCol ) == 24);
103 
104         rDevice->drawBitmap(
105             rBmp,
106             aSourceRect,
107             aDestRightBottom,
108             DrawMode_PAINT );
109         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
110                                countPixel( rDevice, aCol ) == 32);
111     }
112 
implTestBmpClip(const BitmapDeviceSharedPtr & rDevice,const BitmapDeviceSharedPtr & rBmp)113     void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
114                          const BitmapDeviceSharedPtr& rBmp)
115     {
116         rDevice->clear(Color(0));
117         const Color aCol(0xFFFFFFFF);
118 
119         const basegfx::B2IRange aSourceRect(0,0,10,10);
120         const basegfx::B2IRange aDestLeftTop(-2,-2,2,2);
121         const basegfx::B2IRange aDestRightTop(8,-2,12,2);
122         const basegfx::B2IRange aDestLeftBottom(-2,8,2,12);
123         const basegfx::B2IRange aDestRightBottom(8,8,12,12);
124 
125         rDevice->drawBitmap(
126             rBmp,
127             aSourceRect,
128             aDestLeftTop,
129             DrawMode_PAINT );
130         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
131                                countPixel( rDevice, aCol ) == 4);
132 
133         rDevice->drawBitmap(
134             rBmp,
135             aSourceRect,
136             aDestLeftBottom,
137             DrawMode_PAINT );
138         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
139                                countPixel( rDevice, aCol ) == 4);
140 
141         rDevice->drawBitmap(
142             rBmp,
143             aSourceRect,
144             aDestRightBottom,
145             DrawMode_PAINT );
146         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
147                                countPixel( rDevice, aCol ) == 8);
148     }
149 
150 public:
setUp()151     void setUp()
152     {
153         const basegfx::B2ISize aSize(10,10);
154         mpDevice1bpp = createBitmapDevice( aSize,
155                                            true,
156                                            Format::ONE_BIT_MSB_PAL );
157         mpDevice32bpp = createBitmapDevice( aSize,
158                                             true,
159                                             Format::THIRTYTWO_BIT_TC_MASK );
160 
161         mpBmp1bpp = createBitmapDevice( aSize,
162                                         true,
163                                         Format::ONE_BIT_MSB_PAL );
164         mpBmp32bpp = createBitmapDevice( aSize,
165                                          true,
166                                          Format::THIRTYTWO_BIT_TC_MASK );
167 
168         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
169             "m 0 0h5v10h5v-5h-10z" );
170 
171         basegfx::B2DPolyPolygon aPoly;
172         basegfx::tools::importFromSvgD( aPoly, aSvg );
173         const Color aCol(0xFFFFFFFF);
174         mpBmp1bpp->fillPolyPolygon(
175             aPoly,
176             aCol,
177             DrawMode_PAINT );
178         mpBmp32bpp->fillPolyPolygon(
179             aPoly,
180             aCol,
181             DrawMode_PAINT );
182     }
183 
testBmpBasics()184     void testBmpBasics()
185     {
186         implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
187         implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
188     }
189 
testBmpClip()190     void testBmpClip()
191     {
192         implTestBmpClip( mpDevice1bpp, mpBmp1bpp );
193         implTestBmpClip( mpDevice32bpp, mpBmp32bpp );
194     }
195 
196     // Change the following lines only, if you add, remove or rename
197     // member functions of the current class,
198     // because these macros are need by auto register mechanism.
199 
200     CPPUNIT_TEST_SUITE(BmpTest);
201     CPPUNIT_TEST(testBmpBasics);
202     CPPUNIT_TEST(testBmpClip);
203     CPPUNIT_TEST_SUITE_END();
204 };
205 
206 // -----------------------------------------------------------------------------
207 CPPUNIT_TEST_SUITE_REGISTRATION(BmpTest);
208 }
209 
210 
211 // -----------------------------------------------------------------------------
212 
213 // this macro creates an empty function, which will called by the RegisterAllFunctions()
214 // to let the user the possibility to also register some functions by hand.
215 //NOADDITIONAL;
216 
217