1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bmptest.cxx,v $
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>
52 using namespace ::basebmp
;
57 std::ofstream output("32bpp_test.dump");
58 debugDump( rDevice, output );
59 std::ofstream output2("32bpp_bmp.dump");
60 debugDump( rBmp, output2 );
63 class BmpTest
: public CppUnit::TestFixture
66 BitmapDeviceSharedPtr mpDevice1bpp
;
67 BitmapDeviceSharedPtr mpBmp1bpp
;
68 BitmapDeviceSharedPtr mpDevice32bpp
;
69 BitmapDeviceSharedPtr mpBmp32bpp
;
71 void implTestBmpBasics(const BitmapDeviceSharedPtr
& rDevice
,
72 const BitmapDeviceSharedPtr
& rBmp
)
74 rDevice
->clear(Color(0));
75 const Color
aCol(0xFFFFFFFF);
77 const basegfx::B2IRange
aSourceRect(0,0,10,10);
78 const basegfx::B2IRange
aDestLeftTop(0,0,4,4);
79 const basegfx::B2IRange
aDestRightTop(6,0,10,4);
80 const basegfx::B2IRange
aDestLeftBottom(0,6,4,10);
81 const basegfx::B2IRange
aDestRightBottom(6,6,10,10);
88 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
89 countPixel( rDevice
, aCol
) == 8);
96 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
97 countPixel( rDevice
, aCol
) == 16);
104 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
105 countPixel( rDevice
, aCol
) == 24);
112 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
113 countPixel( rDevice
, aCol
) == 32);
116 void implTestBmpClip(const BitmapDeviceSharedPtr
& rDevice
,
117 const BitmapDeviceSharedPtr
& rBmp
)
119 rDevice
->clear(Color(0));
120 const Color
aCol(0xFFFFFFFF);
122 const basegfx::B2IRange
aSourceRect(0,0,10,10);
123 const basegfx::B2IRange
aDestLeftTop(-2,-2,2,2);
124 const basegfx::B2IRange
aDestRightTop(8,-2,12,2);
125 const basegfx::B2IRange
aDestLeftBottom(-2,8,2,12);
126 const basegfx::B2IRange
aDestRightBottom(8,8,12,12);
133 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
134 countPixel( rDevice
, aCol
) == 4);
141 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
142 countPixel( rDevice
, aCol
) == 4);
149 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
150 countPixel( rDevice
, aCol
) == 8);
156 const basegfx::B2ISize
aSize(10,10);
157 mpDevice1bpp
= createBitmapDevice( aSize
,
159 Format::ONE_BIT_MSB_PAL
);
160 mpDevice32bpp
= createBitmapDevice( aSize
,
162 Format::THIRTYTWO_BIT_TC_MASK
);
164 mpBmp1bpp
= createBitmapDevice( aSize
,
166 Format::ONE_BIT_MSB_PAL
);
167 mpBmp32bpp
= createBitmapDevice( aSize
,
169 Format::THIRTYTWO_BIT_TC_MASK
);
171 ::rtl::OUString aSvg
= ::rtl::OUString::createFromAscii(
172 "m 0 0h5v10h5v-5h-10z" );
174 basegfx::B2DPolyPolygon aPoly
;
175 basegfx::tools::importFromSvgD( aPoly
, aSvg
);
176 const Color
aCol(0xFFFFFFFF);
177 mpBmp1bpp
->fillPolyPolygon(
181 mpBmp32bpp
->fillPolyPolygon(
189 implTestBmpBasics( mpDevice1bpp
, mpBmp1bpp
);
190 implTestBmpBasics( mpDevice32bpp
, mpBmp32bpp
);
195 implTestBmpClip( mpDevice1bpp
, mpBmp1bpp
);
196 implTestBmpClip( mpDevice32bpp
, mpBmp32bpp
);
199 // Change the following lines only, if you add, remove or rename
200 // member functions of the current class,
201 // because these macros are need by auto register mechanism.
203 CPPUNIT_TEST_SUITE(BmpTest
);
204 CPPUNIT_TEST(testBmpBasics
);
205 CPPUNIT_TEST(testBmpClip
);
206 CPPUNIT_TEST_SUITE_END();
209 // -----------------------------------------------------------------------------
210 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BmpTest
, "BmpTest");
214 // -----------------------------------------------------------------------------
216 // this macro creates an empty function, which will called by the RegisterAllFunctions()
217 // to let the user the possibility to also register some functions by hand.