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