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