nss: upgrade to release 3.73
[LibreOffice.git] / vcl / qa / cppunit / ScanlineToolsTest.cxx
blobbf053d3bc89047e516758323ba0882f88fd266cf
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(0, 10, 250, 120), Color(50, 30, 230, 110), Color(100, 50, 210, 100),
46 Color(150, 70, 190, 90), Color(200, 90, 170, 80),
49 for (Color const& aColor : aColors)
51 pScanlineTransformer->writePixel(aColor);
54 std::vector<sal_uInt8> aExpectedBytes{ 0, 10, 250, 120, 50, 30, 230, 110, 100, 50,
55 210, 100, 150, 70, 190, 90, 200, 90, 170, 80 };
57 for (size_t i = 0; i < aScanLine.size(); ++i)
59 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
63 void ScanlineToolsTest::ScanlineTransformer_24_BGR()
65 BitmapPalette aPalette;
66 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
67 = vcl::bitmap::getScanlineTransformer(24, aPalette);
69 std::vector<sal_uInt8> aScanLine(5 * 3, 0); // 5 * 3 BytesPerPixel
70 pScanlineTransformer->startLine(aScanLine.data());
72 std::vector<Color> aColors{
73 Color(0, 10, 250, 120), Color(50, 30, 230, 110), Color(100, 50, 210, 100),
74 Color(150, 70, 190, 90), Color(200, 90, 170, 80),
77 for (Color const& aColor : aColors)
79 pScanlineTransformer->writePixel(aColor);
82 std::vector<sal_uInt8> aExpectedBytes{ 120, 250, 10, 110, 230, 30, 100, 210,
83 50, 90, 190, 70, 80, 170, 90 };
85 for (size_t i = 0; i < aScanLine.size(); ++i)
87 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
91 void ScanlineToolsTest::ScanlineTransformer_8bit_Palette()
93 std::vector<Color> aColors{
94 Color(0, 10, 250, 120), Color(50, 30, 230, 110), Color(100, 50, 210, 100),
95 Color(150, 70, 190, 90), Color(200, 90, 170, 80),
98 BitmapPalette aPalette(256);
99 for (size_t i = 0; i < aColors.size(); ++i)
100 aPalette[i] = aColors[i];
102 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
103 = vcl::bitmap::getScanlineTransformer(8, aPalette);
105 std::vector<sal_uInt8> aScanLine(5, 0); // 5 * 1 BytesPerPixel
106 pScanlineTransformer->startLine(aScanLine.data());
108 for (Color const& aColor : aColors)
110 pScanlineTransformer->writePixel(aColor);
113 std::vector<sal_uInt8> aExpectedBytes{ 0, 1, 2, 3, 4 };
115 for (size_t i = 0; i < aScanLine.size(); ++i)
117 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
120 pScanlineTransformer->startLine(aScanLine.data());
122 for (size_t i = 0; i < aColors.size(); ++i)
124 Color aColor = pScanlineTransformer->readPixel();
125 CPPUNIT_ASSERT_EQUAL(aColors[i], aColor);
129 void ScanlineToolsTest::ScanlineTransformer_4bit_Palette()
131 std::vector<Color> aColors{
132 Color(10, 250, 120), Color(30, 230, 110), Color(50, 210, 100),
133 Color(70, 190, 90), Color(90, 170, 80), Color(110, 150, 70),
136 BitmapPalette aPalette(16);
137 for (size_t i = 0; i < aColors.size(); ++i)
139 aPalette[i] = aColors[i];
142 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
143 = vcl::bitmap::getScanlineTransformer(4, aPalette);
145 std::vector<sal_uInt8> aScanLine(3, 0); // 6 * 0.5 BytesPerPixel
146 pScanlineTransformer->startLine(aScanLine.data());
148 for (Color const& aColor : aColors)
150 pScanlineTransformer->writePixel(aColor);
153 std::vector<sal_uInt8> aExpectedBytes{ 0x01, 0x23, 0x45 };
155 for (size_t i = 0; i < aScanLine.size(); ++i)
157 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
160 pScanlineTransformer->startLine(aScanLine.data());
162 for (size_t i = 0; i < aColors.size(); ++i)
164 Color aColor = pScanlineTransformer->readPixel();
165 CPPUNIT_ASSERT_EQUAL(aColors[i], aColor);
169 void ScanlineToolsTest::ScanlineTransformer_1bit_Palette()
171 std::vector<Color> aColors{
172 Color(10, 250, 120), Color(30, 230, 110), Color(50, 210, 100), Color(70, 190, 90),
173 Color(90, 170, 80), Color(110, 150, 70), Color(130, 130, 60), Color(150, 110, 50),
174 Color(170, 90, 40), Color(190, 70, 30), Color(210, 50, 20), Color(230, 30, 10),
175 Color(250, 10, 0),
178 BitmapPalette aPalette(2);
179 aPalette[0] = Color(10, 250, 120);
180 aPalette[1] = Color(110, 150, 70);
182 std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
183 = vcl::bitmap::getScanlineTransformer(1, aPalette);
185 std::vector<sal_uInt8> aScanLine(2, 0); // 13 * 1/8 BytesPerPixel
186 pScanlineTransformer->startLine(aScanLine.data());
188 for (Color const& aColor : aColors)
190 pScanlineTransformer->writePixel(aColor);
193 std::vector<sal_uInt8> aExpectedBytes{
194 // We expect 3x index 0 and 10x index 1 => 000 111111111
195 0x1f, // 0001 1111
196 0xf8 // 1111 1000
199 for (size_t i = 0; i < aScanLine.size(); ++i)
201 CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
204 pScanlineTransformer->startLine(aScanLine.data());
206 std::vector<Color> aColorsExpected{
207 Color(10, 250, 120), Color(10, 250, 120), Color(10, 250, 120), Color(110, 150, 70),
208 Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70),
209 Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70), Color(110, 150, 70),
210 Color(110, 150, 70),
213 for (size_t i = 0; i < aColors.size(); ++i)
215 Color aColor = pScanlineTransformer->readPixel();
216 CPPUNIT_ASSERT_EQUAL(aColorsExpected[i], aColor);
220 } // namespace
222 CPPUNIT_TEST_SUITE_REGISTRATION(ScanlineToolsTest);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */