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/point/b2ipoint.hxx> 34cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 35cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx> 36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 37cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 38cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 39cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <basebmp/color.hxx> 42cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx> 43cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx> 44cdf0e10cSrcweir #include <basebmp/debug.hxx> 45cdf0e10cSrcweir #include "tools.hxx" 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <iostream> 48cdf0e10cSrcweir #include <fstream> 49cdf0e10cSrcweir 50cdf0e10cSrcweir using namespace ::basebmp; 51cdf0e10cSrcweir 52cdf0e10cSrcweir namespace 53cdf0e10cSrcweir { 54cdf0e10cSrcweir /* 55cdf0e10cSrcweir std::ofstream output("32bpp_test.dump"); 56cdf0e10cSrcweir debugDump( mpDevice32bpp, output ); 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir 59cdf0e10cSrcweir class ClipTest : public CppUnit::TestFixture 60cdf0e10cSrcweir { 61cdf0e10cSrcweir private: 62cdf0e10cSrcweir BitmapDeviceSharedPtr mpClipMask; 63cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice1bpp; 64cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice32bpp; 65cdf0e10cSrcweir implTestPixelClip(const BitmapDeviceSharedPtr & rDevice)66cdf0e10cSrcweir void implTestPixelClip(const BitmapDeviceSharedPtr& rDevice) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir const Color aBgCol(0); 69cdf0e10cSrcweir rDevice->clear(aBgCol); 70cdf0e10cSrcweir 71cdf0e10cSrcweir const basegfx::B2IPoint aPt(0,0); 72cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 73cdf0e10cSrcweir rDevice->setPixel( aPt, aCol, DrawMode_PAINT, mpClipMask ); 74cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #1", 75cdf0e10cSrcweir rDevice->getPixel(aPt) == aBgCol); 76cdf0e10cSrcweir 77cdf0e10cSrcweir const basegfx::B2IPoint aPt2(10,10); 78cdf0e10cSrcweir rDevice->setPixel( aPt2, aCol, DrawMode_PAINT, mpClipMask ); 79cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #2", 80cdf0e10cSrcweir rDevice->getPixel(aPt2) == aBgCol); 81cdf0e10cSrcweir 82cdf0e10cSrcweir const basegfx::B2IPoint aPt1(10,0); 83cdf0e10cSrcweir rDevice->setPixel( aPt1, aCol, DrawMode_PAINT, mpClipMask ); 84cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #3", 85cdf0e10cSrcweir rDevice->getPixel(aPt1) != aBgCol); 86cdf0e10cSrcweir 87cdf0e10cSrcweir const basegfx::B2IPoint aPt3(0,10); 88cdf0e10cSrcweir rDevice->setPixel( aPt3, aCol, DrawMode_PAINT, mpClipMask ); 89cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #4", 90cdf0e10cSrcweir rDevice->getPixel(aPt3) != aBgCol); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir implTestLineClip(const BitmapDeviceSharedPtr & rDevice)93cdf0e10cSrcweir void implTestLineClip(const BitmapDeviceSharedPtr& rDevice) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir const Color aBgCol(0); 96cdf0e10cSrcweir rDevice->clear(aBgCol); 97cdf0e10cSrcweir 98cdf0e10cSrcweir const basegfx::B2IPoint aPt1(0,0); 99cdf0e10cSrcweir const basegfx::B2IPoint aPt2(1,9); 100cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 101cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT, mpClipMask ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir const basegfx::B2IPoint aPt3(1,5); 104cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get line pixel", 105cdf0e10cSrcweir rDevice->getPixel(aPt3) != aBgCol); 106cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered line pixel is not 4", 107cdf0e10cSrcweir countPixel( rDevice, 108cdf0e10cSrcweir rDevice->getPixel(aPt3) ) == 4); 109cdf0e10cSrcweir 110cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_XOR, mpClipMask ); 111cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of xor-rendered line pixel is not 0", 112cdf0e10cSrcweir countPixel( rDevice, 113cdf0e10cSrcweir rDevice->getPixel(aPt3) ) == 121); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir implTestFillClip(const BitmapDeviceSharedPtr & rDevice)116cdf0e10cSrcweir void implTestFillClip(const BitmapDeviceSharedPtr& rDevice) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir rDevice->clear(Color(0)); 119cdf0e10cSrcweir 120cdf0e10cSrcweir const basegfx::B2DRange aAllOver(-10,-10,20,20); 121cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 122cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( 123cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aAllOver)), 124cdf0e10cSrcweir aCol, 125cdf0e10cSrcweir DrawMode_PAINT, 126cdf0e10cSrcweir mpClipMask ); 127cdf0e10cSrcweir const basegfx::B2IPoint aPt(0,10); 128cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 30", 129cdf0e10cSrcweir countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30); 130cdf0e10cSrcweir 131cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( 132cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aAllOver)), 133cdf0e10cSrcweir aCol, 134cdf0e10cSrcweir DrawMode_PAINT ); 135cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of filled pixel is not 121", 136cdf0e10cSrcweir countPixel( rDevice, rDevice->getPixel(aPt) ) == 121); 137cdf0e10cSrcweir 138cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( 139cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aAllOver)), 140cdf0e10cSrcweir aCol, 141cdf0e10cSrcweir DrawMode_XOR, 142cdf0e10cSrcweir mpClipMask ); 143cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of xor-cleared pixel is not 91", 144cdf0e10cSrcweir countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir implTestBmpClip(const BitmapDeviceSharedPtr & rDevice)147cdf0e10cSrcweir void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir BitmapDeviceSharedPtr pBmp( cloneBitmapDevice( 150cdf0e10cSrcweir basegfx::B2IVector(3,3), 151cdf0e10cSrcweir rDevice )); 152cdf0e10cSrcweir Color aCol1(0); 153cdf0e10cSrcweir Color aCol2(0xFFFFFFFF); 154cdf0e10cSrcweir pBmp->clear(aCol1); 155cdf0e10cSrcweir pBmp->setPixel(basegfx::B2IPoint(0,0),aCol2,DrawMode_PAINT); 156cdf0e10cSrcweir pBmp->setPixel(basegfx::B2IPoint(1,1),aCol2,DrawMode_PAINT); 157cdf0e10cSrcweir pBmp->setPixel(basegfx::B2IPoint(2,2),aCol2,basebmp::DrawMode_PAINT); 158cdf0e10cSrcweir 159cdf0e10cSrcweir rDevice->clear(aCol1); 160cdf0e10cSrcweir rDevice->drawBitmap(pBmp, 161cdf0e10cSrcweir basegfx::B2IRange(0,0,3,3), 162cdf0e10cSrcweir basegfx::B2IRange(-1,-1,4,4), 163cdf0e10cSrcweir DrawMode_PAINT, 164cdf0e10cSrcweir mpClipMask); 165cdf0e10cSrcweir 166cdf0e10cSrcweir const basegfx::B2IPoint aPt(1,1); 167cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 5", 168cdf0e10cSrcweir countPixel( rDevice, 169cdf0e10cSrcweir rDevice->getPixel(aPt) ) == 5); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir implTestMaskColorClip(const BitmapDeviceSharedPtr & rDevice)172cdf0e10cSrcweir void implTestMaskColorClip(const BitmapDeviceSharedPtr& rDevice) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir BitmapDeviceSharedPtr pBmp( createBitmapDevice( rDevice->getSize(), 175cdf0e10cSrcweir true, 176cdf0e10cSrcweir Format::EIGHT_BIT_GREY )); 177cdf0e10cSrcweir 178cdf0e10cSrcweir ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii( 179cdf0e10cSrcweir "m 0 0h5v10h5v-5h-10z" ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir basegfx::B2DPolyPolygon aPoly; 182cdf0e10cSrcweir basegfx::tools::importFromSvgD( aPoly, aSvg ); 183cdf0e10cSrcweir const basebmp::Color aCol(0xFF); 184cdf0e10cSrcweir pBmp->clear( basebmp::Color(0) ); 185cdf0e10cSrcweir pBmp->fillPolyPolygon( 186cdf0e10cSrcweir aPoly, 187cdf0e10cSrcweir aCol, 188cdf0e10cSrcweir basebmp::DrawMode_PAINT ); 189cdf0e10cSrcweir 190cdf0e10cSrcweir const basegfx::B2IRange aSourceRect(0,0,10,10); 191cdf0e10cSrcweir const basegfx::B2IPoint aDestLeftTop(0,0); 192cdf0e10cSrcweir const Color aCol2(0xF0F0F0F0); 193cdf0e10cSrcweir rDevice->drawMaskedColor( 194cdf0e10cSrcweir aCol2, 195cdf0e10cSrcweir pBmp, 196cdf0e10cSrcweir aSourceRect, 197cdf0e10cSrcweir aDestLeftTop, 198cdf0e10cSrcweir mpClipMask ); 199cdf0e10cSrcweir const basegfx::B2IPoint aPt(1,1); 200cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 41", 201cdf0e10cSrcweir countPixel( rDevice, rDevice->getPixel(aPt) ) == 41); 202cdf0e10cSrcweir 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir public: setUp()206cdf0e10cSrcweir void setUp() 207cdf0e10cSrcweir { 208cdf0e10cSrcweir const basegfx::B2ISize aSize(11,11); 209cdf0e10cSrcweir mpClipMask = createBitmapDevice( aSize, 210cdf0e10cSrcweir true, 211cdf0e10cSrcweir Format::ONE_BIT_MSB_GREY ); 212cdf0e10cSrcweir mpDevice1bpp = createBitmapDevice( aSize, 213cdf0e10cSrcweir true, 214cdf0e10cSrcweir Format::ONE_BIT_MSB_PAL ); 215cdf0e10cSrcweir mpDevice32bpp = createBitmapDevice( aSize, 216cdf0e10cSrcweir true, 217cdf0e10cSrcweir Format::THIRTYTWO_BIT_TC_MASK ); 218cdf0e10cSrcweir 219cdf0e10cSrcweir ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii( 220cdf0e10cSrcweir "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" ); 221cdf0e10cSrcweir basegfx::B2DPolyPolygon aPoly; 222cdf0e10cSrcweir basegfx::tools::importFromSvgD( aPoly, aSvg ); 223cdf0e10cSrcweir mpClipMask->clear(Color(0)); 224cdf0e10cSrcweir mpClipMask->drawPolygon( 225cdf0e10cSrcweir aPoly.getB2DPolygon(0), 226cdf0e10cSrcweir Color(0xFFFFFFFF), 227cdf0e10cSrcweir DrawMode_PAINT ); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir testPixelClip()230cdf0e10cSrcweir void testPixelClip() 231cdf0e10cSrcweir { 232cdf0e10cSrcweir implTestPixelClip( mpDevice1bpp ); 233cdf0e10cSrcweir implTestPixelClip( mpDevice32bpp ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir testLineClip()236cdf0e10cSrcweir void testLineClip() 237cdf0e10cSrcweir { 238cdf0e10cSrcweir implTestLineClip( mpDevice1bpp ); 239cdf0e10cSrcweir implTestLineClip( mpDevice32bpp ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir testFillClip()242cdf0e10cSrcweir void testFillClip() 243cdf0e10cSrcweir { 244cdf0e10cSrcweir implTestFillClip( mpDevice1bpp ); 245cdf0e10cSrcweir implTestFillClip( mpDevice32bpp ); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir testBmpClip()248cdf0e10cSrcweir void testBmpClip() 249cdf0e10cSrcweir { 250cdf0e10cSrcweir implTestBmpClip( mpDevice1bpp ); 251cdf0e10cSrcweir implTestBmpClip( mpDevice32bpp ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir testMaskColorClip()254cdf0e10cSrcweir void testMaskColorClip() 255cdf0e10cSrcweir { 256cdf0e10cSrcweir implTestMaskColorClip( mpDevice1bpp ); 257cdf0e10cSrcweir implTestMaskColorClip( mpDevice32bpp ); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 261cdf0e10cSrcweir // member functions of the current class, 262cdf0e10cSrcweir // because these macros are need by auto register mechanism. 263cdf0e10cSrcweir 264cdf0e10cSrcweir CPPUNIT_TEST_SUITE(ClipTest); 265cdf0e10cSrcweir CPPUNIT_TEST(testPixelClip); 266cdf0e10cSrcweir CPPUNIT_TEST(testLineClip); 267cdf0e10cSrcweir CPPUNIT_TEST(testFillClip); 268cdf0e10cSrcweir CPPUNIT_TEST(testBmpClip); 269cdf0e10cSrcweir CPPUNIT_TEST(testMaskColorClip); 270cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 271cdf0e10cSrcweir }; 272cdf0e10cSrcweir 273cdf0e10cSrcweir // ----------------------------------------------------------------------------- 274cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(ClipTest); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir 278cdf0e10cSrcweir // ----------------------------------------------------------------------------- 279cdf0e10cSrcweir 280cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions() 281cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand. 282cdf0e10cSrcweir //NOADDITIONAL; 283cdf0e10cSrcweir 284