xref: /trunk/main/basebmp/test/linetest.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/point/b2ipoint.hxx>
32 
33 #include <basebmp/color.hxx>
34 #include <basebmp/scanlineformats.hxx>
35 #include <basebmp/bitmapdevice.hxx>
36 #include <basebmp/debug.hxx>
37 #include "tools.hxx"
38 
39 #include <iostream>
40 #include <fstream>
41 
42 using namespace ::basebmp;
43 
44 namespace
45 {
46 /*
47   std::ofstream output("32bpp_test.dump");
48   debugDump( mpDevice32bpp, output );
49 */
50 
51 class LineTest : public ::testing::Test
52 {
53 protected:
54     BitmapDeviceSharedPtr mpDevice1bpp;
55     BitmapDeviceSharedPtr mpDevice32bpp;
56 
implTestBasicDiagonalLines(const BitmapDeviceSharedPtr & rDevice)57     void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice)
58     {
59         rDevice->clear(Color(0));
60 
61         const basegfx::B2IPoint aPt1(1,1);
62         const basegfx::B2IPoint aPt2(9,9);
63         const Color aCol(0xFFFFFFFF);
64         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
65         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
66         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
67         const basegfx::B2IPoint aPt3(0,0);
68         ASSERT_TRUE(rDevice->getPixel(aPt3) != aCol) << "topmost pixel not set";
69         const basegfx::B2IPoint aPt4(10,10);
70         ASSERT_TRUE(rDevice->getPixel(aPt4) != aCol) << "bottommost pixel not set";
71 
72         ASSERT_TRUE(countPixel( rDevice, aCol ) == 9) << "number of rendered pixel is not 9";
73 
74         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
75 
76         ASSERT_TRUE(countPixel( rDevice, aCol ) == 9)
77             << "number of rendered pixel after reversed paint is not 9";
78     }
79 
implTestBasicHorizontalLines(const BitmapDeviceSharedPtr & rDevice)80     void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice)
81     {
82         rDevice->clear(Color(0));
83 
84         const basegfx::B2IPoint aPt1(10,10);
85         const basegfx::B2IPoint aPt2(0,10);
86         const Color aCol(0xFFFFFFFF);
87         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
88         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
89         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
90         ASSERT_TRUE(countPixel( rDevice, aCol ) == 11) << "number of rendered pixel is not 11";
91 
92         rDevice->clear(Color(0));
93         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
94         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
95         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
96         ASSERT_TRUE(countPixel( rDevice, aCol ) == 11) << "number of rendered pixel is not 11";
97     }
98 
implTestBasicVerticalLines(const BitmapDeviceSharedPtr & rDevice)99     void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice)
100     {
101         rDevice->clear(Color(0));
102 
103         const basegfx::B2IPoint aPt1(1,1);
104         const basegfx::B2IPoint aPt2(1,9);
105         const Color aCol(0xFFFFFFFF);
106         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
107         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
108         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
109         const basegfx::B2IPoint aPt3(0,0);
110         ASSERT_TRUE(rDevice->getPixel(aPt3) != aCol) << "topmost pixel not set";
111         const basegfx::B2IPoint aPt4(0,10);
112         ASSERT_TRUE(rDevice->getPixel(aPt4) != aCol) << "bottommost pixel not set";
113 
114         ASSERT_TRUE(countPixel( rDevice, aCol ) == 9) << "number of rendered pixel is not 9";
115     }
116 
117     // test pixel rounding (should always tend towards start point of
118     // the line)
implTestTieBreaking(const BitmapDeviceSharedPtr & rDevice)119     void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice)
120     {
121         rDevice->clear(Color(0));
122 
123         const basegfx::B2IPoint aPt1(1,1);
124         const basegfx::B2IPoint aPt2(3,2);
125         const Color aCol(0xFFFFFFFF);
126         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
127         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
128         ASSERT_TRUE(rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol) << "second pixel set";
129         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
130         ASSERT_TRUE(countPixel( rDevice, aCol ) == 3)
131             << "number of rendered pixel after reversed paint is not 3";
132 
133         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
134         ASSERT_TRUE(rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol)
135             << "alternate second pixel set";
136 
137         ASSERT_TRUE(countPixel( rDevice, aCol ) == 4)
138             << "number of rendered pixel after reversed paint is not 4";
139     }
140 
141 public:
SetUp()142     virtual void SetUp()
143     {
144         const basegfx::B2ISize aSize(11,11);
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 };
153 
TEST_F(LineTest,testBasicDiagonalLines)154 TEST_F(LineTest, testBasicDiagonalLines)
155 {
156     implTestBasicDiagonalLines( mpDevice1bpp );
157     implTestBasicDiagonalLines( mpDevice32bpp );
158 }
159 
TEST_F(LineTest,testBasicHorizontalLines)160 TEST_F(LineTest, testBasicHorizontalLines)
161 {
162     implTestBasicHorizontalLines( mpDevice1bpp );
163     implTestBasicHorizontalLines( mpDevice32bpp );
164 }
165 
TEST_F(LineTest,testBasicVerticalLines)166 TEST_F(LineTest, testBasicVerticalLines)
167 {
168     implTestBasicVerticalLines( mpDevice1bpp );
169     implTestBasicVerticalLines( mpDevice32bpp );
170 }
171 
172 // test pixel rounding (should always tend towards start point of
173 // the line)
TEST_F(LineTest,testTieBreaking)174 TEST_F(LineTest, testTieBreaking)
175 {
176     implTestTieBreaking( mpDevice1bpp );
177     implTestTieBreaking( mpDevice32bpp );
178 }
179 
180 
181 }
182