xref: /aoo41x/main/basebmp/test/masktest.cxx (revision 69de5a4c)
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 MaskTest : public CppUnit::TestFixture
61 {
62 private:
63     BitmapDeviceSharedPtr mpDevice1bpp;
64     BitmapDeviceSharedPtr mpDevice32bpp;
65     BitmapDeviceSharedPtr mpMask;
66 
implTestMaskBasics(const BitmapDeviceSharedPtr & rDevice,const BitmapDeviceSharedPtr & rBmp)67     void implTestMaskBasics(const BitmapDeviceSharedPtr& rDevice,
68                             const BitmapDeviceSharedPtr& rBmp)
69     {
70         const Color aCol(0);
71         const Color aCol2(0xF0F0F0F0);
72 
73         const basegfx::B2IRange aSourceRect(0,0,10,10);
74         const basegfx::B2IPoint aDestLeftTop(0,0);
75         const basegfx::B2IPoint aDestRightTop(5,0);
76         const basegfx::B2IPoint aDestLeftBottom(0,5);
77         const basegfx::B2IPoint aDestRightBottom(5,5);
78 
79         rDevice->clear(aCol);
80         rDevice->setPixel(
81             basegfx::B2IPoint(1,1),
82             aCol2,
83             DrawMode_PAINT);
84         rDevice->drawMaskedColor(
85             aCol2,
86             rBmp,
87             aSourceRect,
88             aDestLeftTop );
89         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 50",
90                                countPixel( rDevice, aCol ) == 100-50);
91 
92         rDevice->clear(aCol);
93         rDevice->drawMaskedColor(
94             aCol2,
95             rBmp,
96             aSourceRect,
97             aDestRightTop );
98         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25",
99                                countPixel( rDevice, aCol ) == 100-25);
100 
101         rDevice->clear(aCol);
102         rDevice->drawMaskedColor(
103             aCol2,
104             rBmp,
105             aSourceRect,
106             aDestLeftBottom );
107         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(b)",
108                                countPixel( rDevice, aCol ) == 100-25);
109 
110         rDevice->clear(aCol);
111         rDevice->drawMaskedColor(
112             aCol2,
113             rBmp,
114             aSourceRect,
115             aDestRightBottom );
116         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(c)",
117                                countPixel( rDevice, aCol ) == 100-25);
118     }
119 
120 public:
setUp()121     void setUp()
122     {
123         const basegfx::B2ISize aSize(10,10);
124         mpDevice1bpp = createBitmapDevice( aSize,
125                                            true,
126                                            Format::ONE_BIT_MSB_PAL );
127         mpDevice32bpp = createBitmapDevice( aSize,
128                                             true,
129                                             Format::THIRTYTWO_BIT_TC_MASK );
130 
131         mpMask = createBitmapDevice( aSize,
132                                      true,
133                                      Format::EIGHT_BIT_GREY );
134 
135         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
136             "m 0 0h5v10h5v-5h-10z" );
137 
138         basegfx::B2DPolyPolygon aPoly;
139         basegfx::tools::importFromSvgD( aPoly, aSvg );
140         const Color aCol(0xFF);
141         mpMask->fillPolyPolygon(
142             aPoly,
143             aCol,
144             DrawMode_PAINT );
145     }
146 
testMaskBasics()147     void testMaskBasics()
148     {
149         implTestMaskBasics( mpDevice32bpp, mpMask );
150         implTestMaskBasics( mpDevice1bpp, mpMask );
151     }
152 
testMaskClip()153     void testMaskClip()
154     {
155     }
156 
157     // Change the following lines only, if you add, remove or rename
158     // member functions of the current class,
159     // because these macros are need by auto register mechanism.
160 
161     CPPUNIT_TEST_SUITE(MaskTest);
162     CPPUNIT_TEST(testMaskBasics);
163     CPPUNIT_TEST(testMaskClip);
164     CPPUNIT_TEST_SUITE_END();
165 };
166 
167 // -----------------------------------------------------------------------------
168 CPPUNIT_TEST_SUITE_REGISTRATION(MaskTest);
169 }
170 
171 
172 // -----------------------------------------------------------------------------
173 
174 // this macro creates an empty function, which will called by the RegisterAllFunctions()
175 // to let the user the possibility to also register some functions by hand.
176 //NOADDITIONAL;
177 
178