xref: /aoo42x/main/basebmp/test/bmpmasktest.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 BmpMaskTest : public ::testing::Test
59 {
60 protected:
61     BitmapDeviceSharedPtr mpDevice1bpp;
62     BitmapDeviceSharedPtr mpMaskBmp1bpp;
63     BitmapDeviceSharedPtr mpBmp1bpp;
64     BitmapDeviceSharedPtr mpDevice32bpp;
65     BitmapDeviceSharedPtr mpBmp32bpp;
66 
implTestBmpBasics(const BitmapDeviceSharedPtr & rDevice,const BitmapDeviceSharedPtr & rBmp)67     void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
68                            const BitmapDeviceSharedPtr& rBmp)
69     {
70         rDevice->clear(Color(0));
71         const Color aCol(0xFFFFFFFF);
72 
73         const basegfx::B2IRange aSourceRect(0,0,10,10);
74         const basegfx::B2IRange aDestAll(0,0,10,10);
75 
76         rDevice->drawMaskedBitmap(
77             rBmp,
78             mpMaskBmp1bpp,
79             aSourceRect,
80             aDestAll,
81             DrawMode_PAINT );
82         ASSERT_TRUE(countPixel( rDevice, aCol ) == 30) << "number of rendered pixel is not 30";
83     }
84 
implTestBmpScaledClip(const BitmapDeviceSharedPtr & rDevice,const BitmapDeviceSharedPtr & rBmp)85     void implTestBmpScaledClip(const BitmapDeviceSharedPtr& rDevice,
86                                const BitmapDeviceSharedPtr& rBmp)
87     {
88         rDevice->clear(Color(0));
89         const Color aCol(0xFFFFFFFF);
90 
91         const basegfx::B2IRange aSourceRect(0,0,10,10);
92         const basegfx::B2IRange aDestLeftTop(0,0,6,6);
93 
94         rDevice->drawMaskedBitmap(
95             rBmp,
96             mpMaskBmp1bpp,
97             aSourceRect,
98             aDestLeftTop,
99             DrawMode_PAINT );
100         ASSERT_TRUE(countPixel( rDevice, aCol ) == 12) << "number of rendered pixel is not 12";
101     }
102 
103 public:
SetUp()104     virtual void SetUp()
105     {
106         const basegfx::B2ISize aSize(10,10);
107         mpDevice1bpp = createBitmapDevice( aSize,
108                                            true,
109                                            Format::ONE_BIT_MSB_PAL );
110         mpDevice32bpp = createBitmapDevice( aSize,
111                                             true,
112                                             Format::THIRTYTWO_BIT_TC_MASK );
113 
114         mpMaskBmp1bpp = createBitmapDevice( aSize,
115                                             true,
116                                             Format::ONE_BIT_MSB_GREY );
117 
118         mpBmp1bpp = createBitmapDevice( aSize,
119                                         true,
120                                         Format::ONE_BIT_MSB_PAL );
121         mpBmp32bpp = createBitmapDevice( aSize,
122                                          true,
123                                          Format::THIRTYTWO_BIT_TC_MASK );
124 
125         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
126             "m 0 0h5v10h5v-5h-10z" );
127 
128         basegfx::B2DPolyPolygon aPoly;
129         basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
130         const Color aColWhite(0xFFFFFFFF);
131         const Color aColBlack(0);
132         mpBmp1bpp->fillPolyPolygon(
133             aPoly,
134             aColWhite,
135             DrawMode_PAINT );
136         mpBmp32bpp->fillPolyPolygon(
137             aPoly,
138             aColWhite,
139             DrawMode_PAINT );
140 
141         aSvg = ::rtl::OUString::createFromAscii(
142             "m 0 0 h6 v10 h-6z" );
143 
144         aPoly.clear();
145         basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
146         mpMaskBmp1bpp->clear(aColWhite);
147         mpMaskBmp1bpp->fillPolyPolygon(
148             aPoly,
149             aColBlack,
150             DrawMode_PAINT );
151     }
152 };
153 
TEST_F(BmpMaskTest,testBmpBasics)154 TEST_F(BmpMaskTest, testBmpBasics)
155 {
156     implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
157     implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
158 }
159 
TEST_F(BmpMaskTest,testBmpClip)160 TEST_F(BmpMaskTest, testBmpClip)
161 {
162     implTestBmpScaledClip( mpDevice1bpp, mpBmp1bpp );
163     implTestBmpScaledClip( mpDevice32bpp, mpBmp32bpp );
164 }
165 
166 
167 }
168