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