169de5a4cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 369de5a4cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 469de5a4cSAndrew Rist * or more contributor license agreements. See the NOTICE file 569de5a4cSAndrew Rist * distributed with this work for additional information 669de5a4cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 769de5a4cSAndrew Rist * to you under the Apache License, Version 2.0 (the 869de5a4cSAndrew Rist * "License"); you may not use this file except in compliance 969de5a4cSAndrew Rist * with the License. You may obtain a copy of the License at 1069de5a4cSAndrew Rist * 1169de5a4cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1269de5a4cSAndrew Rist * 1369de5a4cSAndrew Rist * Unless required by applicable law or agreed to in writing, 1469de5a4cSAndrew Rist * software distributed under the License is distributed on an 1569de5a4cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1669de5a4cSAndrew Rist * KIND, either express or implied. See the License for the 1769de5a4cSAndrew Rist * specific language governing permissions and limitations 1869de5a4cSAndrew Rist * under the License. 1969de5a4cSAndrew Rist * 2069de5a4cSAndrew Rist *************************************************************/ 2169de5a4cSAndrew Rist 2269de5a4cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // autogenerated file with codegen.pl 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "preextstl.h" 27*97c63c1bSDamjan Jovanovic #include "gtest/gtest.h" 28cdf0e10cSrcweir #include "postextstl.h" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx> 31cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <basebmp/color.hxx> 34cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx> 35cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx> 36cdf0e10cSrcweir #include <basebmp/debug.hxx> 37cdf0e10cSrcweir #include "tools.hxx" 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <iostream> 40cdf0e10cSrcweir #include <fstream> 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace ::basebmp; 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace 45cdf0e10cSrcweir { 46cdf0e10cSrcweir /* 47cdf0e10cSrcweir std::ofstream output("32bpp_test.dump"); 48cdf0e10cSrcweir debugDump( mpDevice32bpp, output ); 49cdf0e10cSrcweir */ 50cdf0e10cSrcweir 51*97c63c1bSDamjan Jovanovic class BasicTest : public ::testing::Test 52cdf0e10cSrcweir { 53cdf0e10cSrcweir public: 54*97c63c1bSDamjan Jovanovic }; 55*97c63c1bSDamjan Jovanovic 56*97c63c1bSDamjan Jovanovic TEST_F(BasicTest, colorTest) 57*97c63c1bSDamjan Jovanovic { 58*97c63c1bSDamjan Jovanovic Color aTestColor; 59*97c63c1bSDamjan Jovanovic 60*97c63c1bSDamjan Jovanovic aTestColor = Color(0xDEADBEEF); 61*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.toInt32() == 0xDEADBEEF ) << "unary constructor"; 62*97c63c1bSDamjan Jovanovic 63*97c63c1bSDamjan Jovanovic aTestColor = Color( 0x10, 0x20, 0xFF ); 64*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.toInt32() == 0x001020FF ) << "ternary constructor"; 65*97c63c1bSDamjan Jovanovic 66*97c63c1bSDamjan Jovanovic aTestColor.setRed( 0x0F ); 67*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.toInt32() == 0x00F20FF ) << "setRed()"; 68*97c63c1bSDamjan Jovanovic 69*97c63c1bSDamjan Jovanovic aTestColor.setGreen( 0x0F ); 70*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.toInt32() == 0x00F0FFF ) << "setGreen()"; 71*97c63c1bSDamjan Jovanovic 72*97c63c1bSDamjan Jovanovic aTestColor.setBlue( 0x10 ); 73*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.toInt32() == 0x00F0F10 ) << "setBlue()"; 74*97c63c1bSDamjan Jovanovic 75*97c63c1bSDamjan Jovanovic aTestColor.setGrey( 0x13 ); 76*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.toInt32() == 0x00131313 ) << "setGrey()"; 77*97c63c1bSDamjan Jovanovic 78*97c63c1bSDamjan Jovanovic aTestColor = Color( 0x10, 0x20, 0xFF ); 79*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.getRed() == 0x10 ) << "getRed()"; 80*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.getGreen() == 0x20 ) << "getGreen()"; 81*97c63c1bSDamjan Jovanovic ASSERT_TRUE( aTestColor.getBlue() == 0xFF ) << "getBlue()"; 82*97c63c1bSDamjan Jovanovic } 83*97c63c1bSDamjan Jovanovic 84*97c63c1bSDamjan Jovanovic TEST_F(BasicTest, testConstruction) 85*97c63c1bSDamjan Jovanovic { 86*97c63c1bSDamjan Jovanovic const basegfx::B2ISize aSize(101,101); 87*97c63c1bSDamjan Jovanovic basegfx::B2ISize aSize2(aSize); 88*97c63c1bSDamjan Jovanovic BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize, 89*97c63c1bSDamjan Jovanovic true, 90*97c63c1bSDamjan Jovanovic Format::ONE_BIT_MSB_PAL )); 91*97c63c1bSDamjan Jovanovic ASSERT_TRUE( pDevice->getSize() == aSize2 ) << "right size"; 92*97c63c1bSDamjan Jovanovic ASSERT_TRUE( pDevice->isTopDown() == true ) << "Top down format"; 93*97c63c1bSDamjan Jovanovic ASSERT_TRUE( pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL ) << "Scanline format"; 94*97c63c1bSDamjan Jovanovic ASSERT_TRUE( pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 ) << "Scanline len"; 95*97c63c1bSDamjan Jovanovic ASSERT_TRUE( pDevice->getPalette() ) << "Palette existence"; 96*97c63c1bSDamjan Jovanovic ASSERT_TRUE( (*pDevice->getPalette())[0] == Color(0) ) << "Palette entry 0 is black"; 97*97c63c1bSDamjan Jovanovic ASSERT_TRUE( (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) ) << "Palette entry 1 is white"; 98*97c63c1bSDamjan Jovanovic } 99*97c63c1bSDamjan Jovanovic 100*97c63c1bSDamjan Jovanovic TEST_F(BasicTest, testPixelFuncs) 101*97c63c1bSDamjan Jovanovic { 102*97c63c1bSDamjan Jovanovic // 1bpp 103*97c63c1bSDamjan Jovanovic const basegfx::B2ISize aSize(64,64); 104*97c63c1bSDamjan Jovanovic BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize, 105*97c63c1bSDamjan Jovanovic true, 106*97c63c1bSDamjan Jovanovic Format::ONE_BIT_MSB_PAL )); 107*97c63c1bSDamjan Jovanovic 108*97c63c1bSDamjan Jovanovic const basegfx::B2IPoint aPt(3,3); 109*97c63c1bSDamjan Jovanovic const Color aCol(0xFFFFFFFF); 110*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt, aCol, DrawMode_PAINT ); 111*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt) == aCol) << "get/setPixel roundtrip #1"; 112*97c63c1bSDamjan Jovanovic 113*97c63c1bSDamjan Jovanovic const basegfx::B2IPoint aPt2(0,0); 114*97c63c1bSDamjan Jovanovic const Color aCol2(0xFFFFFFFF); 115*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT ); 116*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol2) << "get/setPixel roundtrip #2"; 117*97c63c1bSDamjan Jovanovic 118*97c63c1bSDamjan Jovanovic const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1); 119*97c63c1bSDamjan Jovanovic const Color aCol3(0x00000000); 120*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT ); 121*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol3) << "get/setPixel roundtrip #3"; 122*97c63c1bSDamjan Jovanovic 123*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT ); 124*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol2) << "get/setPixel roundtrip #3.5"; 125*97c63c1bSDamjan Jovanovic 126*97c63c1bSDamjan Jovanovic const basegfx::B2IPoint aPt4(-100000,-100000); 127*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT ); 128*97c63c1bSDamjan Jovanovic const basegfx::B2IPoint aPt5(100000,100000); 129*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT ); 130*97c63c1bSDamjan Jovanovic 131*97c63c1bSDamjan Jovanovic sal_Int32 nPixel(countPixel(pDevice, aCol2)); 132*97c63c1bSDamjan Jovanovic const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY()); 133*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT ); 134*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel(pDevice, aCol2) == nPixel) << "setPixel clipping"; 135*97c63c1bSDamjan Jovanovic 136*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getBuffer()[0] == 0x80) << "raw pixel value #1"; 137*97c63c1bSDamjan Jovanovic 138*97c63c1bSDamjan Jovanovic // 1bit LSB 139cdf0e10cSrcweir { 140*97c63c1bSDamjan Jovanovic pDevice = createBitmapDevice( aSize, 141*97c63c1bSDamjan Jovanovic true, 142*97c63c1bSDamjan Jovanovic Format::ONE_BIT_LSB_PAL ); 143cdf0e10cSrcweir 144*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt2, aCol, DrawMode_PAINT ); 145*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol) << "get/setPixel roundtrip #4"; 146cdf0e10cSrcweir 147*97c63c1bSDamjan Jovanovic const basegfx::B2IPoint aPt222(1,1); 148*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt222, aCol, DrawMode_PAINT ); 149*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt222) == aCol) << "get/setPixel roundtrip #5"; 150cdf0e10cSrcweir 151*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt3, aCol, DrawMode_PAINT ); 152*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol) << "get/setPixel roundtrip #6"; 153cdf0e10cSrcweir 154*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getBuffer()[0] == 0x01) << "raw pixel value #2"; 155*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getBuffer()[8] == 0x02) << "raw pixel value #3"; 156*97c63c1bSDamjan Jovanovic } 157cdf0e10cSrcweir 158*97c63c1bSDamjan Jovanovic // 8bit alpha 159*97c63c1bSDamjan Jovanovic { 160*97c63c1bSDamjan Jovanovic pDevice = createBitmapDevice( aSize, 161*97c63c1bSDamjan Jovanovic true, 162*97c63c1bSDamjan Jovanovic Format::EIGHT_BIT_GREY ); 163cdf0e10cSrcweir 164*97c63c1bSDamjan Jovanovic const Color aCol4(0x010101); 165*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 166*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #4"; 167cdf0e10cSrcweir 168*97c63c1bSDamjan Jovanovic const Color aCol5(0x0F0F0F); 169*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 170*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #5"; 171cdf0e10cSrcweir 172*97c63c1bSDamjan Jovanovic const Color aCol6(0xFFFFFF); 173*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 174*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #6"; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177*97c63c1bSDamjan Jovanovic // 16bpp 178cdf0e10cSrcweir { 179*97c63c1bSDamjan Jovanovic pDevice = createBitmapDevice( aSize, 180*97c63c1bSDamjan Jovanovic true, 181*97c63c1bSDamjan Jovanovic Format::SIXTEEN_BIT_LSB_TC_MASK ); 182*97c63c1bSDamjan Jovanovic const Color aCol7(0); 183*97c63c1bSDamjan Jovanovic pDevice->clear( aCol7 ); 184*97c63c1bSDamjan Jovanovic 185*97c63c1bSDamjan Jovanovic const Color aCol4(0x00101010); 186*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 187*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #7"; 188*97c63c1bSDamjan Jovanovic 189*97c63c1bSDamjan Jovanovic const Color aCol5(0x00F0F0F0); 190*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 191*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt2) != aCol7) << "get/setPixel roundtrip #8"; 192*97c63c1bSDamjan Jovanovic 193*97c63c1bSDamjan Jovanovic const Color aCol6(0x00FFFFFF); 194*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 195*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #9"; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198*97c63c1bSDamjan Jovanovic // 24bpp 199cdf0e10cSrcweir { 200*97c63c1bSDamjan Jovanovic pDevice = createBitmapDevice( aSize, 201*97c63c1bSDamjan Jovanovic true, 202*97c63c1bSDamjan Jovanovic Format::TWENTYFOUR_BIT_TC_MASK ); 203*97c63c1bSDamjan Jovanovic 204*97c63c1bSDamjan Jovanovic const Color aCol4(0x01010101); 205*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 206*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #10"; 207*97c63c1bSDamjan Jovanovic 208*97c63c1bSDamjan Jovanovic const Color aCol5(0x0F3F2F1F); 209*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 210*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #11"; 211*97c63c1bSDamjan Jovanovic 212*97c63c1bSDamjan Jovanovic const Color aCol6(0xFFFFFFFF); 213*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 214*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #12"; 215*97c63c1bSDamjan Jovanovic 216*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getBuffer()[2] == 0x3F 217*97c63c1bSDamjan Jovanovic && pDevice->getBuffer()[1] == 0x2F 218*97c63c1bSDamjan Jovanovic && pDevice->getBuffer()[0] == 0x1F) << "raw pixel value #4"; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221*97c63c1bSDamjan Jovanovic // 32bpp 222*97c63c1bSDamjan Jovanovic { 223*97c63c1bSDamjan Jovanovic pDevice = createBitmapDevice( aSize, 224*97c63c1bSDamjan Jovanovic true, 225*97c63c1bSDamjan Jovanovic Format::THIRTYTWO_BIT_TC_MASK ); 226*97c63c1bSDamjan Jovanovic 227*97c63c1bSDamjan Jovanovic const Color aCol4(0x01010101); 228*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 229*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #13"; 230cdf0e10cSrcweir 231*97c63c1bSDamjan Jovanovic const Color aCol5(0x0F0F0F0F); 232*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 233*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #14"; 234*97c63c1bSDamjan Jovanovic 235*97c63c1bSDamjan Jovanovic const Color aCol6(0xFFFFFFFF); 236*97c63c1bSDamjan Jovanovic pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 237*97c63c1bSDamjan Jovanovic ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #15"; 238*97c63c1bSDamjan Jovanovic } 239*97c63c1bSDamjan Jovanovic } 240cdf0e10cSrcweir 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243