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