[Libreoffice-commits] core.git: include/vcl vcl/CppunitTest_vcl_bitmap_test.mk vcl/inc vcl/Library_vcl.mk vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue Mar 16 08:47:28 UTC 2021


 include/vcl/graphicfilter.hxx           |    1 
 vcl/CppunitTest_vcl_bitmap_test.mk      |    8 -
 vcl/Library_vcl.mk                      |    2 
 vcl/inc/filter/BmpReader.hxx            |   26 ++++
 vcl/inc/filter/BmpWriter.hxx            |   29 ++++
 vcl/qa/cppunit/BmpFilterTest.cxx        |  197 ++++++++++++++++++++++++++++++++
 vcl/qa/cppunit/data/BMP_8bit_RLE.bmp    |binary
 vcl/qa/cppunit/data/BMP_A8R8G8B8.bmp    |binary
 vcl/qa/cppunit/data/BMP_Paint_1bit.bmp  |binary
 vcl/qa/cppunit/data/BMP_Paint_24bit.bmp |binary
 vcl/qa/cppunit/data/BMP_Paint_4bit.bmp  |binary
 vcl/qa/cppunit/data/BMP_Paint_8bit.bmp  |binary
 vcl/qa/cppunit/data/BMP_R5G6B5.bmp      |binary
 vcl/qa/cppunit/data/BMP_R8G8B8.bmp      |binary
 vcl/qa/cppunit/data/BMP_RLE.bmp         |binary
 vcl/qa/cppunit/data/BMP_RLE_V2.bmp      |binary
 vcl/qa/cppunit/data/BMP_RLE_V3.bmp      |binary
 vcl/source/filter/bmp/BmpReader.cxx     |   30 ++++
 vcl/source/filter/bmp/BmpWriter.cxx     |   40 ++++++
 vcl/source/filter/graphicfilter.cxx     |   37 ++----
 20 files changed, 345 insertions(+), 25 deletions(-)

New commits:
commit 95bb2a4fe05fe94029047d3165af21b56b7cd3e5
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Mar 16 15:31:20 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Mar 16 09:46:37 2021 +0100

    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 at gmail.com>

diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx
index b9de5bb85de5..d153c9d97648 100644
--- a/include/vcl/graphicfilter.hxx
+++ b/include/vcl/graphicfilter.hxx
@@ -371,6 +371,7 @@ public:
     static ErrCode readPDF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
     static ErrCode readTIFF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
     static ErrCode readWithTypeSerializer(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, OUString aFilterName);
+    static ErrCode readBMP(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
     static ErrCode readTGA(SvStream & rStream, Graphic & rGraphic);
     static ErrCode readPICT(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
     static ErrCode readMET(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_8bit_RLE.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_A8R8G8B8.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_Paint_1bit.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_Paint_24bit.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_Paint_4bit.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_Paint_8bit.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_R5G6B5.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_R8G8B8.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_RLE.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_RLE_V2.bmp 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
Binary files /dev/null and b/vcl/qa/cppunit/data/BMP_RLE_V3.bmp 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))


More information about the Libreoffice-commits mailing list