xref: /trunk/main/basebmp/test/bmptest.cxx (revision 97c63c1b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // autogenerated file with codegen.pl
25 
26 #include "preextstl.h"
27 #include "gtest/gtest.h"
28 #include "postextstl.h"
29 
30 #include <basegfx/vector/b2isize.hxx>
31 #include <basegfx/range/b2irange.hxx>
32 #include <basegfx/point/b2ipoint.hxx>
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <basegfx/polygon/b2dpolypolygon.hxx>
36 #include <basegfx/polygon/b2dpolypolygontools.hxx>
37 
38 #include <basebmp/color.hxx>
39 #include <basebmp/scanlineformats.hxx>
40 #include <basebmp/bitmapdevice.hxx>
41 #include <basebmp/debug.hxx>
42 #include "tools.hxx"
43 
44 #include <iostream>
45 #include <fstream>
46 
47 using namespace ::basebmp;
48 
49 namespace
50 {
51 /*
52         std::ofstream output("32bpp_test.dump");
53         debugDump( rDevice, output );
54         std::ofstream output2("32bpp_bmp.dump");
55         debugDump( rBmp, output2 );
56 */
57 
58 class BmpTest : public ::testing::Test
59 {
60 protected:
61     BitmapDeviceSharedPtr mpDevice1bpp;
62     BitmapDeviceSharedPtr mpBmp1bpp;
63     BitmapDeviceSharedPtr mpDevice32bpp;
64     BitmapDeviceSharedPtr mpBmp32bpp;
65 
implTestBmpBasics(const BitmapDeviceSharedPtr & rDevice,const BitmapDeviceSharedPtr & rBmp)66     void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
67                            const BitmapDeviceSharedPtr& rBmp)
68     {
69         rDevice->clear(Color(0));
70         const Color aCol(0xFFFFFFFF);
71 
72         const basegfx::B2IRange aSourceRect(0,0,10,10);
73         const basegfx::B2IRange aDestLeftTop(0,0,4,4);
74         const basegfx::B2IRange aDestRightTop(6,0,10,4);
75         const basegfx::B2IRange aDestLeftBottom(0,6,4,10);
76         const basegfx::B2IRange aDestRightBottom(6,6,10,10);
77 
78         rDevice->drawBitmap(
79             rBmp,
80             aSourceRect,
81             aDestLeftTop,
82             DrawMode_PAINT );
83         ASSERT_TRUE(countPixel( rDevice, aCol ) == 8) << "number of rendered pixel is not 8";
84 
85         rDevice->drawBitmap(
86             rBmp,
87             aSourceRect,
88             aDestRightTop,
89             DrawMode_PAINT );
90         ASSERT_TRUE(countPixel( rDevice, aCol ) == 16) << "number of rendered pixel is not 16";
91 
92         rDevice->drawBitmap(
93             rBmp,
94             aSourceRect,
95             aDestLeftBottom,
96             DrawMode_PAINT );
97         ASSERT_TRUE(countPixel( rDevice, aCol ) == 24) << "number of rendered pixel is not 24";
98 
99         rDevice->drawBitmap(
100             rBmp,
101             aSourceRect,
102             aDestRightBottom,
103             DrawMode_PAINT );
104         ASSERT_TRUE(countPixel( rDevice, aCol ) == 32) << "number of rendered pixel is not 32";
105     }
106 
implTestBmpClip(const BitmapDeviceSharedPtr & rDevice,const BitmapDeviceSharedPtr & rBmp)107     void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
108                          const BitmapDeviceSharedPtr& rBmp)
109     {
110         rDevice->clear(Color(0));
111         const Color aCol(0xFFFFFFFF);
112 
113         const basegfx::B2IRange aSourceRect(0,0,10,10);
114         const basegfx::B2IRange aDestLeftTop(-2,-2,2,2);
115         const basegfx::B2IRange aDestRightTop(8,-2,12,2);
116         const basegfx::B2IRange aDestLeftBottom(-2,8,2,12);
117         const basegfx::B2IRange aDestRightBottom(8,8,12,12);
118 
119         rDevice->drawBitmap(
120             rBmp,
121             aSourceRect,
122             aDestLeftTop,
123             DrawMode_PAINT );
124         ASSERT_TRUE(countPixel( rDevice, aCol ) == 4) << "number of rendered pixel is not 4";
125 
126         rDevice->drawBitmap(
127             rBmp,
128             aSourceRect,
129             aDestLeftBottom,
130             DrawMode_PAINT );
131         ASSERT_TRUE(countPixel( rDevice, aCol ) == 4) << "number of rendered pixel is not 4(c)";
132 
133         rDevice->drawBitmap(
134             rBmp,
135             aSourceRect,
136             aDestRightBottom,
137             DrawMode_PAINT );
138         ASSERT_TRUE(countPixel( rDevice, aCol ) == 8) << "number of rendered pixel is not 8";
139     }
140 
141 public:
SetUp()142     virtual void SetUp()
143     {
144         const basegfx::B2ISize aSize(10,10);
145         mpDevice1bpp = createBitmapDevice( aSize,
146                                            true,
147                                            Format::ONE_BIT_MSB_PAL );
148         mpDevice32bpp = createBitmapDevice( aSize,
149                                             true,
150                                             Format::THIRTYTWO_BIT_TC_MASK );
151 
152         mpBmp1bpp = createBitmapDevice( aSize,
153                                         true,
154                                         Format::ONE_BIT_MSB_PAL );
155         mpBmp32bpp = createBitmapDevice( aSize,
156                                          true,
157                                          Format::THIRTYTWO_BIT_TC_MASK );
158 
159         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
160             "m 0 0h5v10h5v-5h-10z" );
161 
162         basegfx::B2DPolyPolygon aPoly;
163         basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
164         const Color aCol(0xFFFFFFFF);
165         mpBmp1bpp->fillPolyPolygon(
166             aPoly,
167             aCol,
168             DrawMode_PAINT );
169         mpBmp32bpp->fillPolyPolygon(
170             aPoly,
171             aCol,
172             DrawMode_PAINT );
173     }
174 };
175 
TEST_F(BmpTest,testBmpBasics)176 TEST_F(BmpTest, testBmpBasics)
177 {
178     implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
179     implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
180 }
181 
TEST_F(BmpTest,testBmpClip)182 TEST_F(BmpTest, testBmpClip)
183 {
184     implTestBmpClip( mpDevice1bpp, mpBmp1bpp );
185     implTestBmpClip( mpDevice32bpp, mpBmp32bpp );
186 }
187 
188 
189 }
190