xref: /aoo42x/main/basebmp/test/filltest.cxx (revision 97c63c1b)
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 "gtest/gtest.h"
28 #include "postextstl.h"
29 
30 #include <basegfx/vector/b2isize.hxx>
31 #include <basegfx/range/b2drange.hxx>
32 #include <basegfx/point/b2ipoint.hxx>
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <basegfx/polygon/b2dpolypolygon.hxx>
36 #include <basegfx/polygon/b2dpolypolygontools.hxx>
37 
38 #include <basebmp/color.hxx>
39 #include <basebmp/scanlineformats.hxx>
40 #include <basebmp/bitmapdevice.hxx>
41 #include <basebmp/debug.hxx>
42 #include "tools.hxx"
43 
44 #include <iostream>
45 #include <fstream>
46 
47 using namespace ::basebmp;
48 
49 namespace
50 {
51 /*
52   std::ofstream output("32bpp_test.dump");
53   debugDump( mpDevice32bpp, output );
54 */
55 
56 class FillTest : public ::testing::Test
57 {
58 protected:
59     BitmapDeviceSharedPtr mpDevice1bpp;
60     BitmapDeviceSharedPtr mpDevice32bpp;
61 
implTestRectFill(const BitmapDeviceSharedPtr & rDevice)62     void implTestRectFill(const BitmapDeviceSharedPtr& rDevice)
63     {
64         rDevice->clear(Color(0));
65 
66         const basegfx::B2DRange   aRect(1,1,10,10);
67 
68         const Color aCol(0xFFFFFFFF);
69         rDevice->fillPolyPolygon(
70             basegfx::B2DPolyPolygon(
71                 basegfx::tools::createPolygonFromRect( aRect )),
72             aCol,
73             DrawMode_PAINT );
74 
75         const basegfx::B2IPoint aPt1(1,1);
76         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
77         const basegfx::B2IPoint aPt2(9,9);
78         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
79         const basegfx::B2IPoint aPt3(0,0);
80         ASSERT_TRUE(rDevice->getPixel(aPt3) != aCol) << "topmost pixel not set";
81         const basegfx::B2IPoint aPt4(10,10);
82         ASSERT_TRUE(rDevice->getPixel(aPt4) != aCol) << "bottommost pixel not set";
83 
84         ASSERT_TRUE(countPixel( rDevice, aCol ) == 81) << "number of rendered pixel is not 81";
85     }
86 
implTestCornerCases(const BitmapDeviceSharedPtr & rDevice)87     void implTestCornerCases(const BitmapDeviceSharedPtr& rDevice)
88     {
89         rDevice->clear(Color(0));
90 
91         const basegfx::B2DRange aEmpty1(0,0,0,11);
92         const basegfx::B2DRange aEmpty2(0,0,11,0);
93         const basegfx::B2DRange aVertLineLeft(0,0,1,11);
94         const basegfx::B2DRange aVertLineRight(10,0,11,11);
95         const basegfx::B2DRange aHorzLineTop(0,0,11,1);
96         const basegfx::B2DRange aHorzLineBottom(0,10,11,11);
97 
98         const Color aCol(0xFFFFFFFF);
99         rDevice->fillPolyPolygon(
100             basegfx::B2DPolyPolygon(
101                 basegfx::tools::createPolygonFromRect( aEmpty1 )),
102             aCol,
103             DrawMode_PAINT );
104         ASSERT_TRUE(countPixel( rDevice, aCol ) == 0) << "number of rendered pixel is not 0";
105 
106         rDevice->fillPolyPolygon(
107             basegfx::B2DPolyPolygon(
108                 basegfx::tools::createPolygonFromRect( aEmpty2 )),
109             aCol,
110             DrawMode_PAINT );
111         ASSERT_TRUE(countPixel( rDevice, aCol ) == 0) << "number of rendered pixel is not 0";
112 
113         rDevice->fillPolyPolygon(
114             basegfx::B2DPolyPolygon(
115                 basegfx::tools::createPolygonFromRect( aVertLineLeft )),
116             aCol,
117             DrawMode_PAINT );
118         ASSERT_TRUE(countPixel( rDevice, aCol ) == 11) << "number of rendered pixel is not 11";
119         const basegfx::B2IPoint aPt1(0,0);
120         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
121 
122         rDevice->fillPolyPolygon(
123             basegfx::B2DPolyPolygon(
124                 basegfx::tools::createPolygonFromRect( aVertLineRight )),
125             aCol,
126             DrawMode_PAINT );
127         ASSERT_TRUE(countPixel( rDevice, aCol ) == 22) << "number of rendered pixel is not 22";
128         const basegfx::B2IPoint aPt2(10,10);
129         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
130 
131         rDevice->fillPolyPolygon(
132             basegfx::B2DPolyPolygon(
133                 basegfx::tools::createPolygonFromRect( aHorzLineTop )),
134             aCol,
135             DrawMode_PAINT );
136         ASSERT_TRUE(countPixel( rDevice, aCol ) == 31) << "number of rendered pixel is not 31";
137         const basegfx::B2IPoint aPt3(5,0);
138         ASSERT_TRUE(rDevice->getPixel(aPt3) == aCol) << "top-middle pixel set";
139 
140         rDevice->fillPolyPolygon(
141             basegfx::B2DPolyPolygon(
142                 basegfx::tools::createPolygonFromRect( aHorzLineBottom )),
143             aCol,
144             DrawMode_PAINT );
145         ASSERT_TRUE(countPixel( rDevice, aCol ) == 40) << "number of rendered pixel is not 40";
146         const basegfx::B2IPoint aPt4(5,10);
147         ASSERT_TRUE(rDevice->getPixel(aPt4) == aCol) << "bottom-middle pixel set";
148 
149         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
150             "m 0 0l7 7h-1z" );
151 
152         basegfx::B2DPolyPolygon aPoly;
153         basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
154         rDevice->fillPolyPolygon(
155             aPoly,
156             aCol,
157             DrawMode_PAINT );
158         ASSERT_TRUE(countPixel( rDevice, aCol ) == 43) << "number of rendered pixel is not 43";
159     }
160 
implTestClipping(const BitmapDeviceSharedPtr & rDevice)161     void implTestClipping(const BitmapDeviceSharedPtr& rDevice)
162     {
163         rDevice->clear(Color(0));
164 
165         const basegfx::B2DRange   aLeftTop(-10,-10,1,1);
166         const basegfx::B2DRange   aRightTop(10,-10,20,1);
167         const basegfx::B2DRange   aLeftBottom(-10,10,1,20);
168         const basegfx::B2DRange   aRightBottom(10,10,20,20);
169         const basegfx::B2DRange   aAllOver(-10,-10,20,20);
170 
171         const Color aCol(0xFFFFFFFF);
172         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
173                                       basegfx::tools::createPolygonFromRect(aLeftTop)),
174                                   aCol,
175                                   DrawMode_PAINT );
176         ASSERT_TRUE(countPixel( rDevice, aCol ) == 1) << "number of rendered pixel is not 1";
177 
178         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
179                                       basegfx::tools::createPolygonFromRect(aRightTop)),
180                                   aCol,
181                                   DrawMode_PAINT );
182         ASSERT_TRUE(countPixel( rDevice, aCol ) == 2) << "number of rendered pixel is not 2";
183 
184         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
185                                       basegfx::tools::createPolygonFromRect(aLeftBottom)),
186                                   aCol,
187                                   DrawMode_PAINT );
188         ASSERT_TRUE(countPixel( rDevice, aCol ) == 3) << "number of rendered pixel is not 3";
189 
190         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
191                                       basegfx::tools::createPolygonFromRect(aRightBottom)),
192                                   aCol,
193                                   DrawMode_PAINT );
194         ASSERT_TRUE(countPixel( rDevice, aCol ) == 4) << "number of rendered pixel is not 4";
195 
196         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
197                                       basegfx::tools::createPolygonFromRect(aAllOver)),
198                                   aCol,
199                                   DrawMode_PAINT );
200         ASSERT_TRUE(countPixel( rDevice, aCol ) == 121) << "number of rendered pixel is not 121";
201     }
202 
203 public:
SetUp()204     virtual void SetUp()
205     {
206         const basegfx::B2ISize aSize(11,11);
207         mpDevice1bpp = createBitmapDevice( aSize,
208                                            true,
209                                            Format::ONE_BIT_MSB_PAL );
210         mpDevice32bpp = createBitmapDevice( aSize,
211                                             true,
212                                             Format::THIRTYTWO_BIT_TC_MASK );
213     }
214 };
215 
TEST_F(FillTest,testRectFill)216 TEST_F(FillTest, testRectFill)
217 {
218     implTestRectFill( mpDevice1bpp );
219     implTestRectFill( mpDevice32bpp );
220 }
221 
TEST_F(FillTest,testClipping)222 TEST_F(FillTest, testClipping)
223 {
224     implTestClipping( mpDevice1bpp );
225     implTestClipping( mpDevice32bpp );
226 }
227 
TEST_F(FillTest,testCornerCases)228 TEST_F(FillTest, testCornerCases)
229 {
230     implTestCornerCases( mpDevice1bpp );
231     implTestCornerCases( mpDevice32bpp );
232 }
233 
234 
235 }
236