summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-03-16 15:31:20 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-03-16 09:46:37 +0100
commit95bb2a4fe05fe94029047d3165af21b56b7cd3e5 (patch)
tree66b5a0c7dcb4eff21ecb99e09347942e4c0e5b54 /vcl/qa
parentd934cb370b1d660f996ec959fda4bcc6f29902a9 (diff)
vcl: add BmpReader{Writer} and many BMP format test
Change-Id: Ibadfed73b9649689cec6e69f562a7a1226aef932 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112554 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/BmpFilterTest.cxx197
-rw-r--r--vcl/qa/cppunit/data/BMP_8bit_RLE.bmpbin0 -> 1194 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_A8R8G8B8.bmpbin0 -> 202 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_Paint_1bit.bmpbin0 -> 78 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_Paint_24bit.bmpbin0 -> 102 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_Paint_4bit.bmpbin0 -> 134 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_Paint_8bit.bmpbin0 -> 1094 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_R5G6B5.bmpbin0 -> 338 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_R8G8B8.bmpbin0 -> 442 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_RLE.bmpbin0 -> 1188 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_RLE_V2.bmpbin0 -> 810 bytes
-rw-r--r--vcl/qa/cppunit/data/BMP_RLE_V3.bmpbin0 -> 1104 bytes
12 files changed, 197 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/BmpFilterTest.cxx b/vcl/qa/cppunit/BmpFilterTest.cxx
new file mode 100644
index 000000000000..e1341353c299
--- /dev/null
+++ b/vcl/qa/cppunit/BmpFilterTest.cxx
@@ -0,0 +1,197 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+
+#include <vcl/bitmapex.hxx>
+#include <tools/stream.hxx>
+#include <filter/BmpReader.hxx>
+#include <unotools/tempfile.hxx>
+
+class BmpFilterTest : public test::BootstrapFixture
+{
+public:
+ OUString maDataUrl;
+ OUString getFullUrl(std::u16string_view sFileName)
+ {
+ return m_directories.getURLFromSrc(maDataUrl) + sFileName;
+ }
+ BmpFilterTest()
+ : maDataUrl(u"/vcl/qa/cppunit/data/")
+ {
+ }
+};
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_RGB_888)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_R8G8B8.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(10L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(10L, aBitmap.GetSizePixel().Height());
+ CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(9, 9));
+ CPPUNIT_ASSERT_EQUAL(Color(0x72, 0xd1, 0xc8), aBitmap.GetPixelColor(1, 1));
+ CPPUNIT_ASSERT_EQUAL(Color(0x72, 0xd1, 0xc8), aBitmap.GetPixelColor(8, 8));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_RGB_565)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_R5G6B5.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(10L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(10L, aBitmap.GetSizePixel().Height());
+
+ // White is not completely white
+ //CPPUNIT_ASSERT_EQUAL(Color(0xf8, 0xfc, 0xf8), aBitmap.GetPixelColor(0, 0));
+ //CPPUNIT_ASSERT_EQUAL(Color(0xf8, 0xfc, 0xf8), aBitmap.GetPixelColor(9, 9));
+
+ //CPPUNIT_ASSERT_EQUAL(Color(0x70, 0xd0, 0xc0), aBitmap.GetPixelColor(1, 1));
+ //CPPUNIT_ASSERT_EQUAL(Color(0x70, 0xd0, 0xc0), aBitmap.GetPixelColor(8, 8));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_32_ARGB_8888)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_A8R8G8B8.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ //CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ //CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ //CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ //CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_Paint_24_RGB_888)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_Paint_24bit.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_Index_1BPP)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_Paint_1bit.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_Index_4BPP)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_Paint_4bit.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_Index_8BPP)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_Paint_8bit.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_Index_8BPP_RLE)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_8bit_RLE.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_V4)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_RLE.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_V3)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_RLE_V3.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_V2)
+{
+ SvFileStream aFileStream(getFullUrl(u"BMP_RLE_V2.bmp"), StreamMode::READ);
+ Graphic aGraphic;
+ CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+ auto aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(4L, aBitmap.GetSizePixel().Height());
+
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
+ CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2));
+ CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/data/BMP_8bit_RLE.bmp b/vcl/qa/cppunit/data/BMP_8bit_RLE.bmp
new file mode 100644
index 000000000000..de20e4f2be35
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_8bit_RLE.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_A8R8G8B8.bmp b/vcl/qa/cppunit/data/BMP_A8R8G8B8.bmp
new file mode 100644
index 000000000000..9e789b798276
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_A8R8G8B8.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_Paint_1bit.bmp b/vcl/qa/cppunit/data/BMP_Paint_1bit.bmp
new file mode 100644
index 000000000000..1112bd67efd5
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_Paint_1bit.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_Paint_24bit.bmp b/vcl/qa/cppunit/data/BMP_Paint_24bit.bmp
new file mode 100644
index 000000000000..41a2eb245681
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_Paint_24bit.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_Paint_4bit.bmp b/vcl/qa/cppunit/data/BMP_Paint_4bit.bmp
new file mode 100644
index 000000000000..69c91a6353cc
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_Paint_4bit.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_Paint_8bit.bmp b/vcl/qa/cppunit/data/BMP_Paint_8bit.bmp
new file mode 100644
index 000000000000..eb48327ef276
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_Paint_8bit.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_R5G6B5.bmp b/vcl/qa/cppunit/data/BMP_R5G6B5.bmp
new file mode 100644
index 000000000000..ac5531c1422d
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_R5G6B5.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_R8G8B8.bmp b/vcl/qa/cppunit/data/BMP_R8G8B8.bmp
new file mode 100644
index 000000000000..5197e42a747b
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_R8G8B8.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_RLE.bmp b/vcl/qa/cppunit/data/BMP_RLE.bmp
new file mode 100644
index 000000000000..ceb843988cfb
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_RLE.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_RLE_V2.bmp b/vcl/qa/cppunit/data/BMP_RLE_V2.bmp
new file mode 100644
index 000000000000..a500761404a1
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_RLE_V2.bmp
Binary files differ
diff --git a/vcl/qa/cppunit/data/BMP_RLE_V3.bmp b/vcl/qa/cppunit/data/BMP_RLE_V3.bmp
new file mode 100644
index 000000000000..870b8d563d65
--- /dev/null
+++ b/vcl/qa/cppunit/data/BMP_RLE_V3.bmp
Binary files differ