update dev300-m58
[ooovba.git] / basebmp / test / bmpmasktest.cxx
blobeb92f2296af94c7f0b9a266da9594e8f2d135b31
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bmpmasktest.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // autogenerated file with codegen.pl
33 #include <cppunit/simpleheader.hxx>
35 #include <basegfx/vector/b2isize.hxx>
36 #include <basegfx/range/b2irange.hxx>
37 #include <basegfx/point/b2ipoint.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
39 #include <basegfx/polygon/b2dpolygontools.hxx>
40 #include <basegfx/polygon/b2dpolypolygon.hxx>
41 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 #include <basebmp/color.hxx>
44 #include <basebmp/scanlineformats.hxx>
45 #include <basebmp/bitmapdevice.hxx>
46 #include <basebmp/debug.hxx>
47 #include "tools.hxx"
49 #include <iostream>
50 #include <fstream>
52 using namespace ::basebmp;
54 namespace
57 std::ofstream output("32bpp_test.dump");
58 debugDump( rDevice, output );
59 std::ofstream output2("32bpp_bmp.dump");
60 debugDump( rBmp, output2 );
63 class BmpMaskTest : public CppUnit::TestFixture
65 private:
66 BitmapDeviceSharedPtr mpDevice1bpp;
67 BitmapDeviceSharedPtr mpMaskBmp1bpp;
68 BitmapDeviceSharedPtr mpBmp1bpp;
69 BitmapDeviceSharedPtr mpDevice32bpp;
70 BitmapDeviceSharedPtr mpBmp32bpp;
72 void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
73 const BitmapDeviceSharedPtr& rBmp)
75 rDevice->clear(Color(0));
76 const Color aCol(0xFFFFFFFF);
78 const basegfx::B2IRange aSourceRect(0,0,10,10);
79 const basegfx::B2IRange aDestAll(0,0,10,10);
81 rDevice->drawMaskedBitmap(
82 rBmp,
83 mpMaskBmp1bpp,
84 aSourceRect,
85 aDestAll,
86 DrawMode_PAINT );
87 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 30",
88 countPixel( rDevice, aCol ) == 30);
91 void implTestBmpScaledClip(const BitmapDeviceSharedPtr& rDevice,
92 const BitmapDeviceSharedPtr& rBmp)
94 rDevice->clear(Color(0));
95 const Color aCol(0xFFFFFFFF);
97 const basegfx::B2IRange aSourceRect(0,0,10,10);
98 const basegfx::B2IRange aDestLeftTop(0,0,6,6);
100 rDevice->drawMaskedBitmap(
101 rBmp,
102 mpMaskBmp1bpp,
103 aSourceRect,
104 aDestLeftTop,
105 DrawMode_PAINT );
106 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 12",
107 countPixel( rDevice, aCol ) == 12);
110 public:
111 void setUp()
113 const basegfx::B2ISize aSize(10,10);
114 mpDevice1bpp = createBitmapDevice( aSize,
115 true,
116 Format::ONE_BIT_MSB_PAL );
117 mpDevice32bpp = createBitmapDevice( aSize,
118 true,
119 Format::THIRTYTWO_BIT_TC_MASK );
121 mpMaskBmp1bpp = createBitmapDevice( aSize,
122 true,
123 Format::ONE_BIT_MSB_GREY );
125 mpBmp1bpp = createBitmapDevice( aSize,
126 true,
127 Format::ONE_BIT_MSB_PAL );
128 mpBmp32bpp = createBitmapDevice( aSize,
129 true,
130 Format::THIRTYTWO_BIT_TC_MASK );
132 ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
133 "m 0 0h5v10h5v-5h-10z" );
135 basegfx::B2DPolyPolygon aPoly;
136 basegfx::tools::importFromSvgD( aPoly, aSvg );
137 const Color aColWhite(0xFFFFFFFF);
138 const Color aColBlack(0);
139 mpBmp1bpp->fillPolyPolygon(
140 aPoly,
141 aColWhite,
142 DrawMode_PAINT );
143 mpBmp32bpp->fillPolyPolygon(
144 aPoly,
145 aColWhite,
146 DrawMode_PAINT );
148 aSvg = ::rtl::OUString::createFromAscii(
149 "m 0 0 h6 v10 h-6z" );
151 aPoly.clear();
152 basegfx::tools::importFromSvgD( aPoly, aSvg );
153 mpMaskBmp1bpp->clear(aColWhite);
154 mpMaskBmp1bpp->fillPolyPolygon(
155 aPoly,
156 aColBlack,
157 DrawMode_PAINT );
160 void testBmpBasics()
162 implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
163 implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
166 void testBmpClip()
168 implTestBmpScaledClip( mpDevice1bpp, mpBmp1bpp );
169 implTestBmpScaledClip( mpDevice32bpp, mpBmp32bpp );
172 // Change the following lines only, if you add, remove or rename
173 // member functions of the current class,
174 // because these macros are need by auto register mechanism.
176 CPPUNIT_TEST_SUITE(BmpMaskTest);
177 CPPUNIT_TEST(testBmpBasics);
178 CPPUNIT_TEST(testBmpClip);
179 CPPUNIT_TEST_SUITE_END();
182 // -----------------------------------------------------------------------------
183 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BmpMaskTest, "BmpMaskTest");
187 // -----------------------------------------------------------------------------
189 // this macro creates an empty function, which will called by the RegisterAllFunctions()
190 // to let the user the possibility to also register some functions by hand.
191 //NOADDITIONAL;