nss: upgrade to release 3.73
[LibreOffice.git] / vcl / qa / cppunit / png / PngFilterTest.cxx
blobeda7d830fca4b74d87271cdf935febeffd1a38c4
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <test/bootstrapfixture.hxx>
21 #include <tools/stream.hxx>
22 #include <vcl/filter/PngImageReader.hxx>
23 #include <vcl/bitmapaccess.hxx>
24 #include <vcl/alpha.hxx>
26 using namespace css;
28 class PngFilterTest : public test::BootstrapFixture
30 OUString maDataUrl;
32 OUString getFullUrl(const OUString& sFileName)
34 return m_directories.getURLFromSrc(maDataUrl) + sFileName;
37 public:
38 PngFilterTest()
39 : BootstrapFixture(true, false)
40 , maDataUrl("/vcl/qa/cppunit/png/data/")
44 void testPng();
46 CPPUNIT_TEST_SUITE(PngFilterTest);
47 CPPUNIT_TEST(testPng);
48 CPPUNIT_TEST_SUITE_END();
51 void PngFilterTest::testPng()
53 for (const OUString& aFileName : { OUString("rect-1bit-pal.png") })
55 SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ);
57 vcl::PngImageReader aPngReader(aFileStream);
58 BitmapEx aBitmapEx;
59 aPngReader.read(aBitmapEx);
61 Bitmap aBitmap = aBitmapEx.GetBitmap();
63 Bitmap::ScopedReadAccess pAccess(aBitmap);
64 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAccess->Width());
65 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAccess->Height());
67 if (pAccess->GetBitCount() == 24 || pAccess->GetBitCount() == 32)
69 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(0, 0));
70 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(3, 3));
71 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(3, 0));
72 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(0, 3));
74 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x00, 0x00), pAccess->GetPixel(1, 1));
75 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x00, 0x00), pAccess->GetPixel(1, 2));
76 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x00, 0x00), pAccess->GetPixel(2, 1));
77 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x00, 0x00), pAccess->GetPixel(2, 2));
79 else
81 CPPUNIT_ASSERT_MESSAGE("Bitmap is not 24 or 32 bit.", false);
85 for (const OUString& aFileName :
86 { OUString("color-rect-8bit-RGB.png"), OUString("color-rect-4bit-pal.png") })
88 SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ);
90 vcl::PngImageReader aPngReader(aFileStream);
91 BitmapEx aBitmapEx;
92 aPngReader.read(aBitmapEx);
94 Bitmap aBitmap = aBitmapEx.GetBitmap();
96 Bitmap::ScopedReadAccess pAccess(aBitmap);
97 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAccess->Width());
98 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAccess->Height());
99 if (pAccess->GetBitCount() == 24 || pAccess->GetBitCount() == 32)
101 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(0, 0));
102 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(3, 3));
103 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(3, 0));
104 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(0, 3));
106 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0x00, 0x00, 0x00), pAccess->GetPixel(1, 1));
107 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0xFF, 0x00, 0x00), pAccess->GetPixel(1, 2));
108 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0xFF, 0x00), pAccess->GetPixel(2, 1));
109 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0x00, 0x00), pAccess->GetPixel(2, 2));
111 else
113 CPPUNIT_ASSERT_MESSAGE("Bitmap is not 24 or 32 bit.", false);
117 for (const OUString& aFileName : { OUString("alpha-rect-8bit-RGBA.png") })
119 SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ);
121 vcl::PngImageReader aPngReader(aFileStream);
122 BitmapEx aBitmapEx;
123 aPngReader.read(aBitmapEx);
125 Bitmap aBitmap = aBitmapEx.GetBitmap();
127 Bitmap::ScopedReadAccess pAccess(aBitmap);
128 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAccess->Width());
129 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAccess->Height());
131 if (pAccess->GetBitCount() == 24)
133 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(0, 0));
134 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(3, 3));
135 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(3, 0));
136 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x00), pAccess->GetPixel(0, 3));
138 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0x00, 0x00, 0x00), pAccess->GetPixel(1, 1));
139 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0xFF, 0x00, 0x00), pAccess->GetPixel(1, 2));
140 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0xFF, 0x00), pAccess->GetPixel(2, 1));
141 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0x00, 0x00), pAccess->GetPixel(2, 2));
143 AlphaMask aAlpha = aBitmapEx.GetAlpha();
145 AlphaMask::ScopedReadAccess pAlphaAccess(aAlpha);
146 CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), pAlphaAccess->GetBitCount());
147 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAlphaAccess->Width());
148 CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAlphaAccess->Height());
150 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x80, 0x00),
151 pAlphaAccess->GetPixel(0, 0));
152 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x80, 0x00),
153 pAlphaAccess->GetPixel(3, 3));
154 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x80, 0x00),
155 pAlphaAccess->GetPixel(3, 0));
156 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x80, 0x00),
157 pAlphaAccess->GetPixel(0, 3));
159 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x40, 0x00),
160 pAlphaAccess->GetPixel(1, 1));
161 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0xC0, 0x00),
162 pAlphaAccess->GetPixel(1, 2));
163 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0xC0, 0x00),
164 pAlphaAccess->GetPixel(2, 1));
165 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x40, 0x00),
166 pAlphaAccess->GetPixel(2, 2));
169 else if (pAccess->GetBitCount() == 32)
171 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x80), pAccess->GetPixel(0, 0));
172 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x80), pAccess->GetPixel(3, 3));
173 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x80), pAccess->GetPixel(3, 0));
174 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0xFF, 0x80), pAccess->GetPixel(0, 3));
176 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0x00, 0x00, 0x40), pAccess->GetPixel(1, 1));
177 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0xFF, 0x00, 0xC0), pAccess->GetPixel(1, 2));
178 CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0xFF, 0xC0), pAccess->GetPixel(2, 1));
179 CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xFF, 0x00, 0x40), pAccess->GetPixel(2, 2));
181 else
183 CPPUNIT_ASSERT_MESSAGE("Bitmap is not 24 or 32 bit.", false);
189 CPPUNIT_TEST_SUITE_REGISTRATION(PngFilterTest);
191 CPPUNIT_PLUGIN_IMPLEMENT();
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */