xref: /trunk/main/basebmp/test/masktest.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // autogenerated file with codegen.pl
29 
30 #include "preextstl.h"
31 #include "cppunit/TestAssert.h"
32 #include "cppunit/TestFixture.h"
33 #include "cppunit/extensions/HelperMacros.h"
34 #include "postextstl.h"
35 
36 #include <basegfx/vector/b2isize.hxx>
37 #include <basegfx/range/b2irange.hxx>
38 #include <basegfx/point/b2ipoint.hxx>
39 #include <basegfx/polygon/b2dpolygon.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <basegfx/polygon/b2dpolypolygon.hxx>
42 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 
44 #include <basebmp/color.hxx>
45 #include <basebmp/scanlineformats.hxx>
46 #include <basebmp/bitmapdevice.hxx>
47 #include <basebmp/debug.hxx>
48 #include "tools.hxx"
49 
50 #include <iostream>
51 #include <fstream>
52 
53 using namespace ::basebmp;
54 
55 namespace
56 {
57 /*
58         std::ofstream output("32bpp_test.dump");
59         debugDump( rDevice, output );
60         std::ofstream output2("32bpp_bmp.dump");
61         debugDump( rBmp, output2 );
62 */
63 
64 class MaskTest : public CppUnit::TestFixture
65 {
66 private:
67     BitmapDeviceSharedPtr mpDevice1bpp;
68     BitmapDeviceSharedPtr mpDevice32bpp;
69     BitmapDeviceSharedPtr mpMask;
70 
71     void implTestMaskBasics(const BitmapDeviceSharedPtr& rDevice,
72                             const BitmapDeviceSharedPtr& rBmp)
73     {
74         const Color aCol(0);
75         const Color aCol2(0xF0F0F0F0);
76 
77         const basegfx::B2IRange aSourceRect(0,0,10,10);
78         const basegfx::B2IPoint aDestLeftTop(0,0);
79         const basegfx::B2IPoint aDestRightTop(5,0);
80         const basegfx::B2IPoint aDestLeftBottom(0,5);
81         const basegfx::B2IPoint aDestRightBottom(5,5);
82 
83         rDevice->clear(aCol);
84         rDevice->setPixel(
85             basegfx::B2IPoint(1,1),
86             aCol2,
87             DrawMode_PAINT);
88         rDevice->drawMaskedColor(
89             aCol2,
90             rBmp,
91             aSourceRect,
92             aDestLeftTop );
93         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 50",
94                                countPixel( rDevice, aCol ) == 100-50);
95 
96         rDevice->clear(aCol);
97         rDevice->drawMaskedColor(
98             aCol2,
99             rBmp,
100             aSourceRect,
101             aDestRightTop );
102         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25",
103                                countPixel( rDevice, aCol ) == 100-25);
104 
105         rDevice->clear(aCol);
106         rDevice->drawMaskedColor(
107             aCol2,
108             rBmp,
109             aSourceRect,
110             aDestLeftBottom );
111         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(b)",
112                                countPixel( rDevice, aCol ) == 100-25);
113 
114         rDevice->clear(aCol);
115         rDevice->drawMaskedColor(
116             aCol2,
117             rBmp,
118             aSourceRect,
119             aDestRightBottom );
120         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(c)",
121                                countPixel( rDevice, aCol ) == 100-25);
122     }
123 
124 public:
125     void setUp()
126     {
127         const basegfx::B2ISize aSize(10,10);
128         mpDevice1bpp = createBitmapDevice( aSize,
129                                            true,
130                                            Format::ONE_BIT_MSB_PAL );
131         mpDevice32bpp = createBitmapDevice( aSize,
132                                             true,
133                                             Format::THIRTYTWO_BIT_TC_MASK );
134 
135         mpMask = createBitmapDevice( aSize,
136                                      true,
137                                      Format::EIGHT_BIT_GREY );
138 
139         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
140             "m 0 0h5v10h5v-5h-10z" );
141 
142         basegfx::B2DPolyPolygon aPoly;
143         basegfx::tools::importFromSvgD( aPoly, aSvg );
144         const Color aCol(0xFF);
145         mpMask->fillPolyPolygon(
146             aPoly,
147             aCol,
148             DrawMode_PAINT );
149     }
150 
151     void testMaskBasics()
152     {
153         implTestMaskBasics( mpDevice32bpp, mpMask );
154         implTestMaskBasics( mpDevice1bpp, mpMask );
155     }
156 
157     void testMaskClip()
158     {
159     }
160 
161     // Change the following lines only, if you add, remove or rename
162     // member functions of the current class,
163     // because these macros are need by auto register mechanism.
164 
165     CPPUNIT_TEST_SUITE(MaskTest);
166     CPPUNIT_TEST(testMaskBasics);
167     CPPUNIT_TEST(testMaskClip);
168     CPPUNIT_TEST_SUITE_END();
169 };
170 
171 // -----------------------------------------------------------------------------
172 CPPUNIT_TEST_SUITE_REGISTRATION(MaskTest);
173 }
174 
175 
176 // -----------------------------------------------------------------------------
177 
178 // this macro creates an empty function, which will called by the RegisterAllFunctions()
179 // to let the user the possibility to also register some functions by hand.
180 //NOADDITIONAL;
181 
182