summaryrefslogtreecommitdiff
path: root/vcl
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
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')
-rw-r--r--vcl/CppunitTest_vcl_bitmap_test.mk8
-rw-r--r--vcl/Library_vcl.mk2
-rw-r--r--vcl/inc/filter/BmpReader.hxx26
-rw-r--r--vcl/inc/filter/BmpWriter.hxx29
-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
-rw-r--r--vcl/source/filter/bmp/BmpReader.cxx30
-rw-r--r--vcl/source/filter/bmp/BmpWriter.cxx40
-rw-r--r--vcl/source/filter/graphicfilter.cxx37
19 files changed, 344 insertions, 25 deletions
diff --git a/vcl/CppunitTest_vcl_bitmap_test.mk b/vcl/CppunitTest_vcl_bitmap_test.mk
index dca63852a8af..187bb6871845 100644
--- a/vcl/CppunitTest_vcl_bitmap_test.mk
+++ b/vcl/CppunitTest_vcl_bitmap_test.mk
@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_bitmap_test, \
vcl/qa/cppunit/ScanlineToolsTest \
vcl/qa/cppunit/BitmapScaleTest \
vcl/qa/cppunit/BitmapFilterTest \
+ vcl/qa/cppunit/BmpFilterTest \
))
$(eval $(call gb_CppunitTest_use_externals,vcl_bitmap_test,\
@@ -52,12 +53,7 @@ $(eval $(call gb_CppunitTest_use_sdk_api,vcl_bitmap_test))
$(eval $(call gb_CppunitTest_use_ure,vcl_bitmap_test))
$(eval $(call gb_CppunitTest_use_vcl,vcl_bitmap_test))
-$(eval $(call gb_CppunitTest_use_components,vcl_bitmap_test,\
- configmgr/source/configmgr \
- i18npool/util/i18npool \
- ucb/source/core/ucb1 \
- unotools/util/utl \
-))
+$(eval $(call gb_CppunitTest_use_rdb,vcl_bitmap_test,services))
$(eval $(call gb_CppunitTest_use_configuration,vcl_bitmap_test))
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 17ddf83fe961..4ffb346ca2e1 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -427,6 +427,8 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/components/dtranscomp \
vcl/source/components/factory \
vcl/source/components/fontident \
+ vcl/source/filter/bmp/BmpReader \
+ vcl/source/filter/bmp/BmpWriter \
vcl/source/filter/egif/egif \
vcl/source/filter/egif/giflzwc \
vcl/source/filter/eps/eps \
diff --git a/vcl/inc/filter/BmpReader.hxx b/vcl/inc/filter/BmpReader.hxx
new file mode 100644
index 000000000000..4b6733eeb7f9
--- /dev/null
+++ b/vcl/inc/filter/BmpReader.hxx
@@ -0,0 +1,26 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <vcl/graph.hxx>
+
+VCL_DLLPUBLIC bool BmpReader(SvStream& rStream, Graphic& rGraphic);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/filter/BmpWriter.hxx b/vcl/inc/filter/BmpWriter.hxx
new file mode 100644
index 000000000000..cc9f2a3547dd
--- /dev/null
+++ b/vcl/inc/filter/BmpWriter.hxx
@@ -0,0 +1,29 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <tools/stream.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/FilterConfigItem.hxx>
+
+VCL_DLLPUBLIC bool BmpWriter(SvStream& rStream, Graphic& rGraphic,
+ FilterConfigItem* pFilterConfigItem);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
diff --git a/vcl/source/filter/bmp/BmpReader.cxx b/vcl/source/filter/bmp/BmpReader.cxx
new file mode 100644
index 000000000000..3d2b6a463c46
--- /dev/null
+++ b/vcl/source/filter/bmp/BmpReader.cxx
@@ -0,0 +1,30 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <filter/BmpReader.hxx>
+#include <vcl/TypeSerializer.hxx>
+
+bool BmpReader(SvStream& rStream, Graphic& rGraphic)
+{
+ TypeSerializer aSerializer(rStream);
+ aSerializer.readGraphic(rGraphic);
+ return !rStream.GetError();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/bmp/BmpWriter.cxx b/vcl/source/filter/bmp/BmpWriter.cxx
new file mode 100644
index 000000000000..e061124b89f3
--- /dev/null
+++ b/vcl/source/filter/bmp/BmpWriter.cxx
@@ -0,0 +1,40 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <filter/BmpWriter.hxx>
+#include <vcl/dibtools.hxx>
+
+bool BmpWriter(SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pFilterConfigItem)
+{
+ BitmapEx aBitmap = rGraphic.GetBitmapEx();
+ sal_Int32 nColor = pFilterConfigItem->ReadInt32("Color", 0);
+
+ auto nColorRes = static_cast<BmpConversion>(nColor);
+ if (nColorRes != BmpConversion::NNONE && nColorRes <= BmpConversion::N24Bit)
+ {
+ if (!aBitmap.Convert(nColorRes))
+ aBitmap = rGraphic.GetBitmapEx();
+ }
+ bool bRleCoding = pFilterConfigItem->ReadBool("RLE_Coding", true);
+ WriteDIB(aBitmap, rStream, bRleCoding);
+
+ return rStream.good();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index e482f0f5d213..be3e97bda2ef 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -29,7 +29,6 @@
#include <tools/stream.hxx>
#include <tools/urlobj.hxx>
#include <tools/zcodec.hxx>
-#include <vcl/dibtools.hxx>
#include <fltcall.hxx>
#include <vcl/salctype.hxx>
#include <vcl/filter/PngImageReader.hxx>
@@ -61,6 +60,8 @@
#include <filter/PbmReader.hxx>
#include <filter/DxfReader.hxx>
#include <filter/GifWriter.hxx>
+#include <filter/BmpReader.hxx>
+#include <filter/BmpWriter.hxx>
#include <osl/module.hxx>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/awt/Size.hpp>
@@ -1147,11 +1148,7 @@ ErrCode GraphicFilter::readWithTypeSerializer(SvStream & rStream, Graphic & rGra
if (!rStream.GetError())
{
- if (aFilterName.equalsIgnoreAsciiCase(IMP_BMP))
- {
- rLinkType = GfxLinkType::NativeBmp;
- }
- else if (aFilterName.equalsIgnoreAsciiCase(IMP_MOV))
+ if (aFilterName.equalsIgnoreAsciiCase(IMP_MOV))
{
rGraphic.SetDefaultType();
rStream.Seek(STREAM_SEEK_TO_END);
@@ -1162,6 +1159,17 @@ ErrCode GraphicFilter::readWithTypeSerializer(SvStream & rStream, Graphic & rGra
return aReturnCode;
}
+ErrCode GraphicFilter::readBMP(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType)
+{
+ if (BmpReader(rStream, rGraphic))
+ {
+ rLinkType = GfxLinkType::NativeBmp;
+ return ERRCODE_NONE;
+ }
+ else
+ return ERRCODE_GRFILTER_FILTERERROR;
+}
+
ErrCode GraphicFilter::readTGA(SvStream & rStream, Graphic & rGraphic)
{
if (ImportTgaGraphic(rStream, rGraphic))
@@ -1339,7 +1347,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
}
else if (aFilterName.equalsIgnoreAsciiCase(IMP_BMP))
{
- nStatus = readWithTypeSerializer(rIStream, rGraphic, eLinkType, aFilterName);
+ nStatus = readBMP(rIStream, rGraphic, eLinkType);
}
else if (aFilterName.equalsIgnoreAsciiCase(IMP_SVMETAFILE))
{
@@ -1545,18 +1553,9 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r
{
if( aFilterName.equalsIgnoreAsciiCase( EXP_BMP ) )
{
- BitmapEx aBmp( aGraphic.GetBitmapEx() );
- BmpConversion nColorRes = static_cast<BmpConversion>(aConfigItem.ReadInt32( "Color", 0 ));
- if ( nColorRes != BmpConversion::NNONE && ( nColorRes <= BmpConversion::N24Bit) )
- {
- if( !aBmp.Convert( nColorRes ) )
- aBmp = aGraphic.GetBitmapEx();
- }
- bool bRleCoding = aConfigItem.ReadBool( "RLE_Coding", true );
- // save RLE encoded?
- WriteDIB(aBmp, rOStm, bRleCoding);
-
- if( rOStm.GetError() )
+ if (!BmpWriter(rOStm, aGraphic, &aConfigItem))
+ nStatus = ERRCODE_GRFILTER_FORMATERROR;
+ if (rOStm.GetError())
nStatus = ERRCODE_GRFILTER_IOERROR;
}
else if (aFilterName.equalsIgnoreAsciiCase(EXP_TIFF))