xref: /aoo41x/main/basebmp/test/bmpmasktest.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 BmpMaskTest : public CppUnit::TestFixture
65 {
66 private:
67     BitmapDeviceSharedPtr mpDevice1bpp;
68     BitmapDeviceSharedPtr mpMaskBmp1bpp;
69     BitmapDeviceSharedPtr mpBmp1bpp;
70     BitmapDeviceSharedPtr mpDevice32bpp;
71     BitmapDeviceSharedPtr mpBmp32bpp;
72 
73     void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
74                            const BitmapDeviceSharedPtr& rBmp)
75     {
76         rDevice->clear(Color(0));
77         const Color aCol(0xFFFFFFFF);
78 
79         const basegfx::B2IRange aSourceRect(0,0,10,10);
80         const basegfx::B2IRange aDestAll(0,0,10,10);
81 
82         rDevice->drawMaskedBitmap(
83             rBmp,
84             mpMaskBmp1bpp,
85             aSourceRect,
86             aDestAll,
87             DrawMode_PAINT );
88         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 30",
89                                countPixel( rDevice, aCol ) == 30);
90     }
91 
92     void implTestBmpScaledClip(const BitmapDeviceSharedPtr& rDevice,
93                                const BitmapDeviceSharedPtr& rBmp)
94     {
95         rDevice->clear(Color(0));
96         const Color aCol(0xFFFFFFFF);
97 
98         const basegfx::B2IRange aSourceRect(0,0,10,10);
99         const basegfx::B2IRange aDestLeftTop(0,0,6,6);
100 
101         rDevice->drawMaskedBitmap(
102             rBmp,
103             mpMaskBmp1bpp,
104             aSourceRect,
105             aDestLeftTop,
106             DrawMode_PAINT );
107         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 12",
108                                countPixel( rDevice, aCol ) == 12);
109     }
110 
111 public:
112     void setUp()
113     {
114         const basegfx::B2ISize aSize(10,10);
115         mpDevice1bpp = createBitmapDevice( aSize,
116                                            true,
117                                            Format::ONE_BIT_MSB_PAL );
118         mpDevice32bpp = createBitmapDevice( aSize,
119                                             true,
120                                             Format::THIRTYTWO_BIT_TC_MASK );
121 
122         mpMaskBmp1bpp = createBitmapDevice( aSize,
123                                             true,
124                                             Format::ONE_BIT_MSB_GREY );
125 
126         mpBmp1bpp = createBitmapDevice( aSize,
127                                         true,
128                                         Format::ONE_BIT_MSB_PAL );
129         mpBmp32bpp = createBitmapDevice( aSize,
130                                          true,
131                                          Format::THIRTYTWO_BIT_TC_MASK );
132 
133         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
134             "m 0 0h5v10h5v-5h-10z" );
135 
136         basegfx::B2DPolyPolygon aPoly;
137         basegfx::tools::importFromSvgD( aPoly, aSvg );
138         const Color aColWhite(0xFFFFFFFF);
139         const Color aColBlack(0);
140         mpBmp1bpp->fillPolyPolygon(
141             aPoly,
142             aColWhite,
143             DrawMode_PAINT );
144         mpBmp32bpp->fillPolyPolygon(
145             aPoly,
146             aColWhite,
147             DrawMode_PAINT );
148 
149         aSvg = ::rtl::OUString::createFromAscii(
150             "m 0 0 h6 v10 h-6z" );
151 
152         aPoly.clear();
153         basegfx::tools::importFromSvgD( aPoly, aSvg );
154         mpMaskBmp1bpp->clear(aColWhite);
155         mpMaskBmp1bpp->fillPolyPolygon(
156             aPoly,
157             aColBlack,
158             DrawMode_PAINT );
159     }
160 
161     void testBmpBasics()
162     {
163         implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
164         implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
165     }
166 
167     void testBmpClip()
168     {
169         implTestBmpScaledClip( mpDevice1bpp, mpBmp1bpp );
170         implTestBmpScaledClip( mpDevice32bpp, mpBmp32bpp );
171     }
172 
173     // Change the following lines only, if you add, remove or rename
174     // member functions of the current class,
175     // because these macros are need by auto register mechanism.
176 
177     CPPUNIT_TEST_SUITE(BmpMaskTest);
178     CPPUNIT_TEST(testBmpBasics);
179     CPPUNIT_TEST(testBmpClip);
180     CPPUNIT_TEST_SUITE_END();
181 };
182 
183 // -----------------------------------------------------------------------------
184 CPPUNIT_TEST_SUITE_REGISTRATION(BmpMaskTest);
185 }
186 
187 
188 // -----------------------------------------------------------------------------
189 
190 // this macro creates an empty function, which will called by the RegisterAllFunctions()
191 // to let the user the possibility to also register some functions by hand.
192 //NOADDITIONAL;
193 
194