Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "cppunit/TestAssert.h"
21 : : #include "cppunit/TestFixture.h"
22 : : #include "cppunit/extensions/HelperMacros.h"
23 : :
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>
31 : :
32 : : #include <basebmp/color.hxx>
33 : : #include <basebmp/scanlineformats.hxx>
34 : : #include <basebmp/bitmapdevice.hxx>
35 : : #include "tools.hxx"
36 : :
37 : : using namespace ::basebmp;
38 : :
39 : : namespace
40 : : {
41 [ + - ][ + - ]: 30 : class BmpTest : public CppUnit::TestFixture
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ]
42 : : {
43 : : private:
44 : : BitmapDeviceSharedPtr mpDevice1bpp;
45 : : BitmapDeviceSharedPtr mpBmp1bpp;
46 : : BitmapDeviceSharedPtr mpDevice32bpp;
47 : : BitmapDeviceSharedPtr mpBmp32bpp;
48 : :
49 : 10 : void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
50 : : const BitmapDeviceSharedPtr& rBmp)
51 : : {
52 [ + - ]: 10 : rDevice->clear(Color(0));
53 : 10 : const Color aCol(0xFFFFFFFF);
54 : :
55 [ + - ]: 10 : const basegfx::B2IBox aSourceRect(0,0,10,10);
56 [ + - ]: 10 : const basegfx::B2IBox aDestLeftTop(0,0,4,4);
57 [ + - ]: 10 : const basegfx::B2IBox aDestRightTop(6,0,10,4);
58 [ + - ]: 10 : const basegfx::B2IBox aDestLeftBottom(0,6,4,10);
59 [ + - ]: 10 : const basegfx::B2IBox aDestRightBottom(6,6,10,10);
60 : :
61 : : rDevice->drawBitmap(
62 : : rBmp,
63 : : aSourceRect,
64 : : aDestLeftTop,
65 [ + - ]: 10 : DrawMode_PAINT );
66 [ + - ][ + - ]: 20 : CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
67 [ + - ]: 10 : countPixel( rDevice, aCol ) == 8);
68 : :
69 : : rDevice->drawBitmap(
70 : : rBmp,
71 : : aSourceRect,
72 : : aDestRightTop,
73 [ + - ]: 10 : DrawMode_PAINT );
74 [ + - ][ + - ]: 20 : CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
75 [ + - ]: 10 : countPixel( rDevice, aCol ) == 16);
76 : :
77 : : rDevice->drawBitmap(
78 : : rBmp,
79 : : aSourceRect,
80 : : aDestLeftBottom,
81 [ + - ]: 10 : DrawMode_PAINT );
82 [ + - ][ + - ]: 20 : CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
83 [ + - ]: 10 : countPixel( rDevice, aCol ) == 24);
84 : :
85 : : rDevice->drawBitmap(
86 : : rBmp,
87 : : aSourceRect,
88 : : aDestRightBottom,
89 [ + - ]: 10 : DrawMode_PAINT );
90 [ + - ][ + - ]: 20 : CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
91 [ + - ]: 10 : countPixel( rDevice, aCol ) == 32);
92 : 10 : }
93 : :
94 : 10 : void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
95 : : const BitmapDeviceSharedPtr& rBmp)
96 : : {
97 [ + - ]: 10 : rDevice->clear(Color(0));
98 : 10 : const Color aCol(0xFFFFFFFF);
99 : :
100 [ + - ]: 10 : const basegfx::B2IBox aSourceRect(0,0,10,10);
101 [ + - ]: 10 : const basegfx::B2IBox aDestLeftTop(-2,-2,2,2);
102 [ + - ]: 10 : const basegfx::B2IBox aDestRightTop(8,-2,12,2);
103 [ + - ]: 10 : const basegfx::B2IBox aDestLeftBottom(-2,8,2,12);
104 [ + - ]: 10 : const basegfx::B2IBox aDestRightBottom(8,8,12,12);
105 : :
106 : : rDevice->drawBitmap(
107 : : rBmp,
108 : : aSourceRect,
109 : : aDestLeftTop,
110 [ + - ]: 10 : DrawMode_PAINT );
111 [ + - ][ + - ]: 20 : CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
112 [ + - ]: 10 : countPixel( rDevice, aCol ) == 4);
113 : :
114 : : rDevice->drawBitmap(
115 : : rBmp,
116 : : aSourceRect,
117 : : aDestLeftBottom,
118 [ + - ]: 10 : DrawMode_PAINT );
119 [ + - ][ + - ]: 20 : CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
120 [ + - ]: 10 : countPixel( rDevice, aCol ) == 4);
121 : :
122 : : rDevice->drawBitmap(
123 : : rBmp,
124 : : aSourceRect,
125 : : aDestRightBottom,
126 [ + - ]: 10 : DrawMode_PAINT );
127 [ + - ][ + - ]: 20 : CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
128 [ + - ]: 10 : countPixel( rDevice, aCol ) == 8);
129 : 10 : }
130 : :
131 : : public:
132 : 10 : void setUp()
133 : : {
134 : 10 : const basegfx::B2ISize aSize(10,10);
135 : : mpDevice1bpp = createBitmapDevice( aSize,
136 : : true,
137 [ + - ][ + - ]: 10 : Format::ONE_BIT_MSB_PAL );
[ + - ]
138 : : mpDevice32bpp = createBitmapDevice( aSize,
139 : : true,
140 [ + - ][ + - ]: 10 : Format::THIRTYTWO_BIT_TC_MASK );
[ + - ]
141 : :
142 : : mpBmp1bpp = createBitmapDevice( aSize,
143 : : true,
144 [ + - ][ + - ]: 10 : Format::ONE_BIT_MSB_PAL );
[ + - ]
145 : : mpBmp32bpp = createBitmapDevice( aSize,
146 : : true,
147 [ + - ][ + - ]: 10 : Format::THIRTYTWO_BIT_TC_MASK );
[ + - ]
148 : :
149 [ + - ]: 10 : ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0h5v10h5v-5h-10z" ));
150 : :
151 [ + - ]: 10 : basegfx::B2DPolyPolygon aPoly;
152 [ + - ]: 10 : basegfx::tools::importFromSvgD( aPoly, aSvg );
153 : 10 : const Color aCol(0xFFFFFFFF);
154 : : mpBmp1bpp->fillPolyPolygon(
155 : : aPoly,
156 : : aCol,
157 [ + - ]: 10 : DrawMode_PAINT );
158 : : mpBmp32bpp->fillPolyPolygon(
159 : : aPoly,
160 : : aCol,
161 [ + - ][ + - ]: 10 : DrawMode_PAINT );
162 : 10 : }
163 : :
164 : 5 : void testBmpBasics()
165 : : {
166 : 5 : implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
167 : 5 : implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
168 : 5 : }
169 : :
170 : 5 : void testBmpClip()
171 : : {
172 : 5 : implTestBmpClip( mpDevice1bpp, mpBmp1bpp );
173 : 5 : implTestBmpClip( mpDevice32bpp, mpBmp32bpp );
174 : 5 : }
175 : :
176 : : // Change the following lines only, if you add, remove or rename
177 : : // member functions of the current class,
178 : : // because these macros are need by auto register mechanism.
179 : :
180 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(BmpTest);
[ + - ][ + - ]
[ # # ]
181 [ + - ][ + - ]: 5 : CPPUNIT_TEST(testBmpBasics);
[ + - ][ + - ]
[ + - ][ + - ]
182 [ + - ][ + - ]: 5 : CPPUNIT_TEST(testBmpClip);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
183 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
184 : : };
185 : :
186 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(BmpTest);
187 [ + - ][ + - ]: 15 : }
188 : :
189 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|