update credits
[LibreOffice.git] / basebmp / test / bmpmasktest.cxx
blob500ba91667d487941a7d01864514797dab61ffbe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 // autogenerated file with codegen.pl
22 #include "cppunit/TestAssert.h"
23 #include "cppunit/TestFixture.h"
24 #include "cppunit/extensions/HelperMacros.h"
26 #include <basegfx/vector/b2isize.hxx>
27 #include <basegfx/range/b2ibox.hxx>
28 #include <basegfx/point/b2ipoint.hxx>
29 #include <basegfx/polygon/b2dpolygon.hxx>
30 #include <basegfx/polygon/b2dpolygontools.hxx>
31 #include <basegfx/polygon/b2dpolypolygon.hxx>
32 #include <basegfx/polygon/b2dpolypolygontools.hxx>
34 #include <basebmp/color.hxx>
35 #include <basebmp/scanlineformats.hxx>
36 #include <basebmp/bitmapdevice.hxx>
37 #include "tools.hxx"
39 using namespace ::basebmp;
41 namespace
43 class BmpMaskTest : public CppUnit::TestFixture
45 private:
46 BitmapDeviceSharedPtr mpDevice1bpp;
47 BitmapDeviceSharedPtr mpMaskBmp1bpp;
48 BitmapDeviceSharedPtr mpBmp1bpp;
49 BitmapDeviceSharedPtr mpDevice32bpp;
50 BitmapDeviceSharedPtr mpBmp32bpp;
52 void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
53 const BitmapDeviceSharedPtr& rBmp)
55 rDevice->clear(Color(0));
56 const Color aCol(0xFFFFFFFF);
58 const basegfx::B2IBox aSourceRect(0,0,10,10);
59 const basegfx::B2IBox aDestAll(0,0,10,10);
61 rDevice->drawMaskedBitmap(
62 rBmp,
63 mpMaskBmp1bpp,
64 aSourceRect,
65 aDestAll,
66 DrawMode_PAINT );
67 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 30",
68 countPixel( rDevice, aCol ) == 30);
71 void implTestBmpScaledClip(const BitmapDeviceSharedPtr& rDevice,
72 const BitmapDeviceSharedPtr& rBmp)
74 rDevice->clear(Color(0));
75 const Color aCol(0xFFFFFFFF);
77 const basegfx::B2IBox aSourceRect(0,0,10,10);
78 const basegfx::B2IBox aDestLeftTop(0,0,6,6);
80 rDevice->drawMaskedBitmap(
81 rBmp,
82 mpMaskBmp1bpp,
83 aSourceRect,
84 aDestLeftTop,
85 DrawMode_PAINT );
86 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 12",
87 countPixel( rDevice, aCol ) == 12);
90 public:
91 void setUp()
93 const basegfx::B2ISize aSize(10,10);
94 mpDevice1bpp = createBitmapDevice( aSize,
95 true,
96 Format::ONE_BIT_MSB_PAL );
97 mpDevice32bpp = createBitmapDevice( aSize,
98 true,
99 Format::THIRTYTWO_BIT_TC_MASK );
101 mpMaskBmp1bpp = createBitmapDevice( aSize,
102 true,
103 Format::ONE_BIT_MSB_GREY );
105 mpBmp1bpp = createBitmapDevice( aSize,
106 true,
107 Format::ONE_BIT_MSB_PAL );
108 mpBmp32bpp = createBitmapDevice( aSize,
109 true,
110 Format::THIRTYTWO_BIT_TC_MASK );
112 OUString aSvg( "m 0 0h5v10h5v-5h-10z" );
114 basegfx::B2DPolyPolygon aPoly;
115 basegfx::tools::importFromSvgD( aPoly, aSvg );
116 const Color aColWhite(0xFFFFFFFF);
117 const Color aColBlack(0);
118 mpBmp1bpp->fillPolyPolygon(
119 aPoly,
120 aColWhite,
121 DrawMode_PAINT );
122 mpBmp32bpp->fillPolyPolygon(
123 aPoly,
124 aColWhite,
125 DrawMode_PAINT );
127 aSvg = "m 0 0 h6 v10 h-6z" ;
129 aPoly.clear();
130 basegfx::tools::importFromSvgD( aPoly, aSvg );
131 mpMaskBmp1bpp->clear(aColWhite);
132 mpMaskBmp1bpp->fillPolyPolygon(
133 aPoly,
134 aColBlack,
135 DrawMode_PAINT );
138 void testBmpBasics()
140 implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
141 implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
144 void testBmpClip()
146 implTestBmpScaledClip( mpDevice1bpp, mpBmp1bpp );
147 implTestBmpScaledClip( mpDevice32bpp, mpBmp32bpp );
150 // Change the following lines only, if you add, remove or rename
151 // member functions of the current class,
152 // because these macros are need by auto register mechanism.
154 CPPUNIT_TEST_SUITE(BmpMaskTest);
155 CPPUNIT_TEST(testBmpBasics);
156 CPPUNIT_TEST(testBmpClip);
157 CPPUNIT_TEST_SUITE_END();
160 CPPUNIT_TEST_SUITE_REGISTRATION(BmpMaskTest);
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */