1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <cppunit/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <basegfx/vector/b2isize.hxx>
25 #include <basegfx/range/b2ibox.hxx>
26 #include <basegfx/point/b2ipoint.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <basegfx/polygon/b2dpolygontools.hxx>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
30 #include <basegfx/polygon/b2dpolypolygontools.hxx>
32 #include <basebmp/color.hxx>
33 #include <basebmp/scanlineformats.hxx>
34 #include <basebmp/bitmapdevice.hxx>
37 using namespace ::basebmp
;
41 class MaskTest
: public CppUnit::TestFixture
44 BitmapDeviceSharedPtr mpDevice1bpp
;
45 BitmapDeviceSharedPtr mpDevice32bpp
;
46 BitmapDeviceSharedPtr mpMask
;
48 void implTestMaskBasics(const BitmapDeviceSharedPtr
& rDevice
,
49 const BitmapDeviceSharedPtr
& rBmp
)
52 const Color
aCol2(0xF0F0F0F0);
54 const basegfx::B2IBox
aSourceRect(0,0,10,10);
55 const basegfx::B2IPoint
aDestLeftTop(0,0);
56 const basegfx::B2IPoint
aDestRightTop(5,0);
57 const basegfx::B2IPoint
aDestLeftBottom(0,5);
58 const basegfx::B2IPoint
aDestRightBottom(5,5);
62 basegfx::B2IPoint(1,1),
65 rDevice
->drawMaskedColor(
70 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 50",
71 countPixel( rDevice
, aCol
) == 100-50);
74 rDevice
->drawMaskedColor(
79 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25",
80 countPixel( rDevice
, aCol
) == 100-25);
83 rDevice
->drawMaskedColor(
88 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(b)",
89 countPixel( rDevice
, aCol
) == 100-25);
92 rDevice
->drawMaskedColor(
97 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(c)",
98 countPixel( rDevice
, aCol
) == 100-25);
102 void setUp() SAL_OVERRIDE
104 const basegfx::B2ISize
aSize(10,10);
105 mpDevice1bpp
= createBitmapDevice( aSize
,
107 FORMAT_ONE_BIT_MSB_PAL
,
108 basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_MSB_PAL
, aSize
.getX()) );
109 mpDevice32bpp
= createBitmapDevice( aSize
,
111 FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA
,
112 basebmp::getBitmapDeviceStrideForWidth(FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA
, aSize
.getX()) );
114 mpMask
= createBitmapDevice( aSize
,
116 FORMAT_EIGHT_BIT_GREY
,
117 basebmp::getBitmapDeviceStrideForWidth(FORMAT_EIGHT_BIT_GREY
, aSize
.getX()) );
119 OUString
aSvg( "m 0 0h5v10h5v-5h-10z" );
121 basegfx::B2DPolyPolygon aPoly
;
122 basegfx::tools::importFromSvgD( aPoly
, aSvg
, false, NULL
);
123 const Color
aCol(0xFF);
124 mpMask
->fillPolyPolygon(
130 void testMaskBasics()
132 implTestMaskBasics( mpDevice32bpp
, mpMask
);
133 implTestMaskBasics( mpDevice1bpp
, mpMask
);
136 // Change the following lines only, if you add, remove or rename
137 // member functions of the current class,
138 // because these macros are need by auto register mechanism.
140 CPPUNIT_TEST_SUITE(MaskTest
);
141 CPPUNIT_TEST(testMaskBasics
);
142 CPPUNIT_TEST_SUITE_END();
145 CPPUNIT_TEST_SUITE_REGISTRATION(MaskTest
);
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */