calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qa / cppunit / ScanlineToolsTest.cxx
blob8b8a9088a1eaa9a51c38eece9fc737461cf4fcc7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <cppunit/TestAssert.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
14 #include <bitmap/ScanlineTools.hxx>
16 namespace
18 class ScanlineToolsTest : public CppUnit::TestFixture
20 void ScanlineTransformer_32_ARGB();
21 void ScanlineTransformer_24_BGR();
22 void ScanlineTransformer_8bit_Palette();
23 void ScanlineTransformer_4bit_Palette();
24 void ScanlineTransformer_1bit_Palette();
26 CPPUNIT_TEST_SUITE(ScanlineToolsTest);
27 CPPUNIT_TEST(ScanlineTransformer_32_ARGB);
28 CPPUNIT_TEST(ScanlineTransformer_24_BGR);
29 CPPUNIT_TEST(ScanlineTransformer_8bit_Palette);
30 CPPUNIT_TEST(ScanlineTransformer_4bit_Palette);
31 CPPUNIT_TEST(ScanlineTransformer_1bit_Palette);
32 CPPUNIT_TEST_SUITE_END();
35 void ScanlineToolsTest::ScanlineTransformer_32_ARGB()
37 BitmapPalette aPalette;
38 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
39 = vcl::bitmap::getScanlineTransformer(32, aPalette);
41 std::vector<sal_uInt8> aScanLine(5 * 4, 0); // 5 * 4 BytesPerPixel
42 pScanlineTransformer->startLine(aScanLine.data());
44 std::vector<Color> aColors{
45 Color(ColorTransparency, 0, 10, 250, 120), Color(ColorTransparency, 50, 30, 230, 110),
46 Color(ColorTransparency, 100, 50, 210, 100), Color(ColorTransparency, 150, 70, 190, 90),
47 Color(ColorTransparency, 200, 90, 170, 80),
50 for (Color const& aColor : aColors)
52 pScanlineTransformer->writePixel(aColor);
55 std::vector<sal_uInt8> aExpectedBytes{ 0, 10, 250, 120, 50, 30, 230, 110, 100, 50,
56 210, 100, 150, 70, 190, 90, 200, 90, 170, 80 };
58 for (size_t i = 0; i < aScanLine.size(); ++i)
60 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
64 void ScanlineToolsTest::ScanlineTransformer_24_BGR()
66 BitmapPalette aPalette;
67 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
68 = vcl::bitmap::getScanlineTransformer(24, aPalette);
70 std::vector<sal_uInt8> aScanLine(5 * 3, 0); // 5 * 3 BytesPerPixel
71 pScanlineTransformer->startLine(aScanLine.data());
73 std::vector<Color> aColors{
74 Color(ColorTransparency, 0, 10, 250, 120), Color(ColorTransparency, 50, 30, 230, 110),
75 Color(ColorTransparency, 100, 50, 210, 100), Color(ColorTransparency, 150, 70, 190, 90),
76 Color(ColorTransparency, 200, 90, 170, 80),
79 for (Color const& aColor : aColors)
81 pScanlineTransformer->writePixel(aColor);
84 std::vector<sal_uInt8> aExpectedBytes{ 120, 250, 10, 110, 230, 30, 100, 210,
85 50, 90, 190, 70, 80, 170, 90 };
87 for (size_t i = 0; i < aScanLine.size(); ++i)
89 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
93 void ScanlineToolsTest::ScanlineTransformer_8bit_Palette()
95 std::vector<Color> aColors{
96 Color(ColorTransparency, 0, 10, 250, 120), Color(ColorTransparency, 50, 30, 230, 110),
97 Color(ColorTransparency, 100, 50, 210, 100), Color(ColorTransparency, 150, 70, 190, 90),
98 Color(ColorTransparency, 200, 90, 170, 80),
101 BitmapPalette aPalette(256);
102 for (size_t i = 0; i < aColors.size(); ++i)
103 aPalette[i] = aColors[i];
105 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
106 = vcl::bitmap::getScanlineTransformer(8, aPalette);
108 std::vector<sal_uInt8> aScanLine(5, 0); // 5 * 1 BytesPerPixel
109 pScanlineTransformer->startLine(aScanLine.data());
111 for (Color const& aColor : aColors)
113 pScanlineTransformer->writePixel(aColor);
116 std::vector<sal_uInt8> aExpectedBytes{ 0, 1, 2, 3, 4 };
118 for (size_t i = 0; i < aScanLine.size(); ++i)
120 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
123 pScanlineTransformer->startLine(aScanLine.data());
125 for (Color const& rColor : aColors)
127 Color aColor = pScanlineTransformer->readPixel();
128 CPPUNIT_ASSERT_EQUAL(rColor, aColor);
132 void ScanlineToolsTest::ScanlineTransformer_4bit_Palette()
134 std::vector<Color> aColors{
135 Color(10, 250, 120), Color(30, 230, 110), Color(50, 210, 100),
136 Color(70, 190, 90), Color(90, 170, 80), Color(110, 150, 70),
139 BitmapPalette aPalette(16);
140 for (size_t i = 0; i < aColors.size(); ++i)
142 aPalette[i] = aColors[i];
145 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
146 = vcl::bitmap::getScanlineTransformer(4, aPalette);
148 std::vector<sal_uInt8> aScanLine(3, 0); // 6 * 0.5 BytesPerPixel
149 pScanlineTransformer->startLine(aScanLine.data());
151 for (Color const& aColor : aColors)
153 pScanlineTransformer->writePixel(aColor);
156 std::vector<sal_uInt8> aExpectedBytes{ 0x01, 0x23, 0x45 };
158 for (size_t i = 0; i < aScanLine.size(); ++i)
160 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
163 pScanlineTransformer->startLine(aScanLine.data());
165 for (Color const& rColor : aColors)
167 Color aColor = pScanlineTransformer->readPixel();
168 CPPUNIT_ASSERT_EQUAL(rColor, aColor);
172 void ScanlineToolsTest::ScanlineTransformer_1bit_Palette()
174 std::vector<Color> aColors{
175 Color(10, 250, 120), Color(30, 230, 110), Color(50, 210, 100), Color(70, 190, 90),
176 Color(90, 170, 80), Color(110, 150, 70), Color(130, 130, 60), Color(150, 110, 50),
177 Color(170, 90, 40), Color(190, 70, 30), Color(210, 50, 20), Color(230, 30, 10),
178 Color(250, 10, 0),
181 BitmapPalette aPalette(2);
182 aPalette[0] = Color(10, 250, 120);
183 aPalette[1] = Color(110, 150, 70);
185 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
186 = vcl::bitmap::getScanlineTransformer(1, aPalette);
188 std::vector<sal_uInt8> aScanLine(2, 0); // 13 * 1/8 BytesPerPixel
189 pScanlineTransformer->startLine(aScanLine.data());
191 for (Color const& aColor : aColors)
193 pScanlineTransformer->writePixel(aColor);
196 std::vector<sal_uInt8> aExpectedBytes{
197 // We expect 3x index 0 and 10x index 1 => 000 111111111
198 0x1f, // 0001 1111
199 0xf8 // 1111 1000
202 for (size_t i = 0; i < aScanLine.size(); ++i)
204 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
207 pScanlineTransformer->startLine(aScanLine.data());
209 std::vector<Color> aColorsExpected{
210 Color(10, 250, 120), Color(10, 250, 120), Color(10, 250, 120), Color(110, 150, 70),
211 Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70),
212 Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70),
213 Color(110, 150, 70),
216 for (Color const& rColor : aColorsExpected)
218 Color aColor = pScanlineTransformer->readPixel();
219 CPPUNIT_ASSERT_EQUAL(rColor, aColor);
223 } // namespace
225 CPPUNIT_TEST_SUITE_REGISTRATION(ScanlineToolsTest);
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */