nss: upgrade to release 3.73
[LibreOffice.git] / vcl / qa / cppunit / BitmapExTest.cxx
blob23f40f0013cd28645071a2b179b0593126473005
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 <vcl/bitmapex.hxx>
15 #include <basegfx/matrix/b2dhommatrix.hxx>
16 #include <bitmapwriteaccess.hxx>
17 #include <svdata.hxx>
18 #include <salinst.hxx>
20 namespace
22 class BitmapExTest : public CppUnit::TestFixture
24 void testGetPixelColor24_8();
25 void testGetPixelColor32();
26 void testTransformBitmapEx();
28 CPPUNIT_TEST_SUITE(BitmapExTest);
29 CPPUNIT_TEST(testGetPixelColor24_8);
30 CPPUNIT_TEST(testGetPixelColor32);
31 CPPUNIT_TEST(testTransformBitmapEx);
32 CPPUNIT_TEST_SUITE_END();
35 void BitmapExTest::testGetPixelColor24_8()
37 Bitmap aBitmap(Size(3, 3), 24);
39 BitmapScopedWriteAccess pWriteAccess(aBitmap);
40 pWriteAccess->Erase(Color(0x00, 0x00, 0xFF, 0x00));
42 AlphaMask aMask(Size(3, 3));
44 AlphaScopedWriteAccess pWriteAccess(aMask);
45 pWriteAccess->Erase(Color(0x00, 0xAA, 0xAA, 0xAA));
48 BitmapEx aBitmapEx(aBitmap, aMask);
50 CPPUNIT_ASSERT_EQUAL(Color(0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0));
53 void BitmapExTest::testGetPixelColor32()
55 // Check backend capabilities and return from the test successfully
56 // if the backend doesn't support 32-bit bitmap
57 auto pBackendCapabilities = ImplGetSVData()->mpDefInst->GetBackendCapabilities();
58 if (!pBackendCapabilities->mbSupportsBitmap32)
59 return;
61 Bitmap aBitmap(Size(3, 3), 32);
63 BitmapScopedWriteAccess pWriteAccess(aBitmap);
64 pWriteAccess->Erase(Color(0xAA, 0x00, 0xFF, 0x00));
67 BitmapEx aBitmapEx(aBitmap);
69 CPPUNIT_ASSERT_EQUAL(Color(0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0));
72 void BitmapExTest::testTransformBitmapEx()
74 Bitmap aBitmap(Size(16, 16), 24);
76 BitmapScopedWriteAccess pWriteAccess(aBitmap);
77 pWriteAccess->Erase(COL_WHITE);
78 for (int i = 0; i < 8; ++i)
80 for (int j = 0; j < 8; ++j)
82 pWriteAccess->SetPixel(i, j, COL_BLACK);
86 BitmapEx aBitmapEx(aBitmap);
88 basegfx::B2DHomMatrix aMatrix;
89 aMatrix.rotate(M_PI / 2);
90 BitmapEx aTransformed = aBitmapEx.TransformBitmapEx(16, 16, aMatrix);
91 aBitmap = aTransformed.GetBitmap();
92 Bitmap::ScopedReadAccess pAccess(aBitmap);
93 for (int i = 0; i < 16; ++i)
95 for (int j = 0; j < 16; ++j)
97 BitmapColor aColor = pAccess->GetPixel(i, j);
98 std::stringstream ss;
99 ss << "Color is expected to be white or black, is '" << aColor.AsRGBHexString() << "'";
100 // Without the accompanying fix in place, this test would have failed with:
101 // - Expression: aColor == COL_WHITE || aColor == COL_BLACK
102 // - Color is expected to be white or black, is 'bfbfbf'
103 // i.e. smoothing introduced noise for a simple 90 deg rotation.
104 CPPUNIT_ASSERT_MESSAGE(ss.str(), aColor == COL_WHITE || aColor == COL_BLACK);
109 } // namespace
111 CPPUNIT_TEST_SUITE_REGISTRATION(BitmapExTest);
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */