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 BmpTest
: public CppUnit::TestFixture
44 BitmapDeviceSharedPtr mpDevice1bpp
;
45 BitmapDeviceSharedPtr mpBmp1bpp
;
46 BitmapDeviceSharedPtr mpDevice32bpp
;
47 BitmapDeviceSharedPtr mpBmp32bpp
;
49 void implTestBmpBasics(const BitmapDeviceSharedPtr
& rDevice
,
50 const BitmapDeviceSharedPtr
& rBmp
)
52 rDevice
->clear(Color(0));
53 const Color
aCol(0xFFFFFFFF);
55 const basegfx::B2IBox
aSourceRect(0,0,10,10);
56 const basegfx::B2IBox
aDestLeftTop(0,0,4,4);
57 const basegfx::B2IBox
aDestRightTop(6,0,10,4);
58 const basegfx::B2IBox
aDestLeftBottom(0,6,4,10);
59 const basegfx::B2IBox
aDestRightBottom(6,6,10,10);
66 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
67 countPixel( rDevice
, aCol
) == 8);
74 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
75 countPixel( rDevice
, aCol
) == 16);
82 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
83 countPixel( rDevice
, aCol
) == 24);
90 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
91 countPixel( rDevice
, aCol
) == 32);
93 BitmapDeviceSharedPtr pClone
= subsetBitmapDevice(
96 // two overlapping areas within the same memory block, check
97 // if we clobber the mem or properly detect the case
98 const basegfx::B2IBox
aSourceOverlap(0,0,6,10);
99 const basegfx::B2IBox
aDestOverlap(3,0,9,10);
105 CPPUNIT_ASSERT_MESSAGE("clobbertest - number of set pixel is not 50",
106 countPixel( rBmp
, aCol
) == 50);
110 void implTestBmpClip(const BitmapDeviceSharedPtr
& rDevice
,
111 const BitmapDeviceSharedPtr
& rBmp
)
113 rDevice
->clear(Color(0));
114 const Color
aCol(0xFFFFFFFF);
116 const basegfx::B2IBox
aSourceRect(0,0,10,10);
117 const basegfx::B2IBox
aDestLeftTop(-2,-2,2,2);
118 const basegfx::B2IBox
aDestRightTop(8,-2,12,2);
119 const basegfx::B2IBox
aDestLeftBottom(-2,8,2,12);
120 const basegfx::B2IBox
aDestRightBottom(8,8,12,12);
127 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
128 countPixel( rDevice
, aCol
) == 4);
135 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
136 countPixel( rDevice
, aCol
) == 4);
143 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
144 countPixel( rDevice
, aCol
) == 8);
148 void setUp() SAL_OVERRIDE
150 const basegfx::B2ISize
aSize(10,10);
151 sal_Int32 nStride
= basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_MSB_PAL
, aSize
.getX());
152 mpDevice1bpp
= createBitmapDevice( aSize
,
154 FORMAT_ONE_BIT_MSB_PAL
, nStride
);
155 nStride
= basebmp::getBitmapDeviceStrideForWidth(FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA
, aSize
.getX());
156 mpDevice32bpp
= createBitmapDevice( aSize
,
158 FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA
, nStride
);
160 nStride
= basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_MSB_PAL
, aSize
.getX());
161 mpBmp1bpp
= createBitmapDevice( aSize
,
163 FORMAT_ONE_BIT_MSB_PAL
, nStride
);
164 nStride
= basebmp::getBitmapDeviceStrideForWidth(FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA
, aSize
.getX());
165 mpBmp32bpp
= createBitmapDevice( aSize
,
167 FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA
, nStride
);
169 OUString
aSvg( "m 0 0h5v10h5v-5h-10z" );
171 basegfx::B2DPolyPolygon aPoly
;
172 basegfx::tools::importFromSvgD( aPoly
, aSvg
, false, NULL
);
173 const Color
aCol(0xFFFFFFFF);
174 mpBmp1bpp
->fillPolyPolygon(
178 mpBmp32bpp
->fillPolyPolygon(
186 implTestBmpBasics( mpDevice1bpp
, mpBmp1bpp
);
187 implTestBmpBasics( mpDevice32bpp
, mpBmp32bpp
);
192 implTestBmpClip( mpDevice1bpp
, mpBmp1bpp
);
193 implTestBmpClip( mpDevice32bpp
, mpBmp32bpp
);
196 // Change the following lines only, if you add, remove or rename
197 // member functions of the current class,
198 // because these macros are need by auto register mechanism.
200 CPPUNIT_TEST_SUITE(BmpTest
);
201 CPPUNIT_TEST(testBmpBasics
);
202 CPPUNIT_TEST(testBmpClip
);
203 CPPUNIT_TEST_SUITE_END();
206 CPPUNIT_TEST_SUITE_REGISTRATION(BmpTest
);
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */