xref: /trunk/main/basebmp/test/basictest.cxx (revision 7a227dd4)
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 BasicTest : public ::testing::Test
52 {
53 public:
54 };
55 
TEST_F(BasicTest,colorTest)56 TEST_F(BasicTest, colorTest)
57 {
58     Color aTestColor;
59 
60     aTestColor = Color(0xDEADBEEF);
61     ASSERT_TRUE( aTestColor.toInt32() == 0xDEADBEEF ) << "unary constructor";
62 
63     aTestColor = Color( 0x10, 0x20, 0xFF );
64     ASSERT_TRUE( aTestColor.toInt32() == 0x001020FF ) << "ternary constructor";
65 
66     aTestColor.setRed( 0x0F );
67     ASSERT_TRUE( aTestColor.toInt32() == 0x00F20FF ) << "setRed()";
68 
69     aTestColor.setGreen( 0x0F );
70     ASSERT_TRUE( aTestColor.toInt32() == 0x00F0FFF ) << "setGreen()";
71 
72     aTestColor.setBlue( 0x10 );
73     ASSERT_TRUE( aTestColor.toInt32() == 0x00F0F10 ) << "setBlue()";
74 
75     aTestColor.setGrey( 0x13 );
76     ASSERT_TRUE( aTestColor.toInt32() == 0x00131313 ) << "setGrey()";
77 
78     aTestColor = Color( 0x10, 0x20, 0xFF );
79     ASSERT_TRUE( aTestColor.getRed() == 0x10 ) << "getRed()";
80     ASSERT_TRUE( aTestColor.getGreen() == 0x20 ) << "getGreen()";
81     ASSERT_TRUE( aTestColor.getBlue() == 0xFF ) << "getBlue()";
82 }
83 
TEST_F(BasicTest,testConstruction)84 TEST_F(BasicTest, testConstruction)
85 {
86     const basegfx::B2ISize aSize(101,101);
87     basegfx::B2ISize       aSize2(aSize);
88     BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
89                                                        true,
90                                                        Format::ONE_BIT_MSB_PAL ));
91     ASSERT_TRUE( pDevice->getSize() == aSize2 ) << "right size";
92     ASSERT_TRUE( pDevice->isTopDown() == true ) << "Top down format";
93     ASSERT_TRUE( pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL ) << "Scanline format";
94     ASSERT_TRUE( pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 ) << "Scanline len";
95     ASSERT_TRUE( pDevice->getPalette() != NULL ) << "Palette existence";
96     ASSERT_TRUE( (*pDevice->getPalette())[0] == Color(0) ) << "Palette entry 0 is black";
97     ASSERT_TRUE( (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) ) << "Palette entry 1 is white";
98 }
99 
TEST_F(BasicTest,testPixelFuncs)100 TEST_F(BasicTest, testPixelFuncs)
101 {
102     // 1bpp
103     const basegfx::B2ISize aSize(64,64);
104     BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
105                                                        true,
106                                                        Format::ONE_BIT_MSB_PAL ));
107 
108     const basegfx::B2IPoint aPt(3,3);
109     const Color aCol(0xFFFFFFFF);
110     pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
111     ASSERT_TRUE(pDevice->getPixel(aPt) == aCol) << "get/setPixel roundtrip #1";
112 
113     const basegfx::B2IPoint aPt2(0,0);
114     const Color aCol2(0xFFFFFFFF);
115     pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
116     ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol2) << "get/setPixel roundtrip #2";
117 
118     const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
119     const Color aCol3(0x00000000);
120     pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
121     ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol3) << "get/setPixel roundtrip #3";
122 
123     pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
124     ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol2) << "get/setPixel roundtrip #3.5";
125 
126     const basegfx::B2IPoint aPt4(-100000,-100000);
127     pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
128     const basegfx::B2IPoint aPt5(100000,100000);
129     pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
130 
131     sal_Int32 nPixel(countPixel(pDevice, aCol2));
132     const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
133     pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
134     ASSERT_TRUE(countPixel(pDevice, aCol2) == nPixel) << "setPixel clipping";
135 
136     ASSERT_TRUE(pDevice->getBuffer()[0] == 0x80) << "raw pixel value #1";
137 
138     // 1bit LSB
139     {
140         pDevice = createBitmapDevice( aSize,
141                                       true,
142                                       Format::ONE_BIT_LSB_PAL );
143 
144         pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
145         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol) << "get/setPixel roundtrip #4";
146 
147         const basegfx::B2IPoint aPt222(1,1);
148         pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
149         ASSERT_TRUE(pDevice->getPixel(aPt222) == aCol) << "get/setPixel roundtrip #5";
150 
151         pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
152         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol) << "get/setPixel roundtrip #6";
153 
154         ASSERT_TRUE(pDevice->getBuffer()[0] == 0x01) << "raw pixel value #2";
155         ASSERT_TRUE(pDevice->getBuffer()[8] == 0x02) << "raw pixel value #3";
156     }
157 
158     // 8bit alpha
159     {
160         pDevice = createBitmapDevice( aSize,
161                                       true,
162                                       Format::EIGHT_BIT_GREY );
163 
164         const Color aCol4(0x010101);
165         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
166         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #4";
167 
168         const Color aCol5(0x0F0F0F);
169         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
170         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #5";
171 
172         const Color aCol6(0xFFFFFF);
173         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
174         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #6";
175     }
176 
177     // 16bpp
178     {
179         pDevice = createBitmapDevice( aSize,
180                                       true,
181                                       Format::SIXTEEN_BIT_LSB_TC_MASK );
182         const Color aCol7(0);
183         pDevice->clear( aCol7 );
184 
185         const Color aCol4(0x00101010);
186         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
187         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #7";
188 
189         const Color aCol5(0x00F0F0F0);
190         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
191         ASSERT_TRUE(pDevice->getPixel(aPt2) != aCol7) << "get/setPixel roundtrip #8";
192 
193         const Color aCol6(0x00FFFFFF);
194         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
195         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #9";
196     }
197 
198     // 24bpp
199     {
200         pDevice = createBitmapDevice( aSize,
201                                       true,
202                                       Format::TWENTYFOUR_BIT_TC_MASK );
203 
204         const Color aCol4(0x01010101);
205         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
206         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #10";
207 
208         const Color aCol5(0x0F3F2F1F);
209         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
210         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #11";
211 
212         const Color aCol6(0xFFFFFFFF);
213         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
214         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #12";
215 
216         ASSERT_TRUE(pDevice->getBuffer()[2] == 0x3F
217                                && pDevice->getBuffer()[1] == 0x2F
218                                && pDevice->getBuffer()[0] == 0x1F) << "raw pixel value #4";
219     }
220 
221     // 32bpp
222     {
223         pDevice = createBitmapDevice( aSize,
224                                       true,
225                                       Format::THIRTYTWO_BIT_TC_MASK );
226 
227         const Color aCol4(0x01010101);
228         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
229         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #13";
230 
231         const Color aCol5(0x0F0F0F0F);
232         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
233         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #14";
234 
235         const Color aCol6(0xFFFFFFFF);
236         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
237         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #15";
238     }
239 }
240 
241 }
242 
243