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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Mar 18 03:03:18 UTC 2021


 vcl/CppunitTest_vcl_bitmap_test.mk  |    1 
 vcl/qa/cppunit/XpmFilterTest.cxx    |   76 ++++++++++
 vcl/qa/cppunit/data/XPM_1.xpm       |   15 ++
 vcl/qa/cppunit/data/XPM_4.xpm       |   23 +++
 vcl/qa/cppunit/data/XPM_8.xpm       |  263 ++++++++++++++++++++++++++++++++++++
 vcl/source/filter/graphicfilter.cxx |    2 
 vcl/source/filter/ixpm/xpmread.cxx  |    3 
 vcl/workben/fftester.cxx            |    2 
 vcl/workben/xpmfuzzer.cxx           |    2 
 9 files changed, 383 insertions(+), 4 deletions(-)

New commits:
commit 80da19ae298b4b4d8802906f88fde0c0f9348765
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Mar 17 14:20:43 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Mar 18 04:02:36 2021 +0100

    vcl: test for reading the XPM format
    
    Change-Id: I416a1c02d737dba716b55a7eb902181c3cff22b6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112598
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/CppunitTest_vcl_bitmap_test.mk b/vcl/CppunitTest_vcl_bitmap_test.mk
index 187bb6871845..3e28b96b62e9 100644
--- a/vcl/CppunitTest_vcl_bitmap_test.mk
+++ b/vcl/CppunitTest_vcl_bitmap_test.mk
@@ -17,6 +17,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_bitmap_test, \
     vcl/qa/cppunit/BitmapScaleTest \
     vcl/qa/cppunit/BitmapFilterTest \
     vcl/qa/cppunit/BmpFilterTest \
+    vcl/qa/cppunit/XpmFilterTest \
 ))
 
 $(eval $(call gb_CppunitTest_use_externals,vcl_bitmap_test,\
diff --git a/vcl/source/filter/ixpm/xpmread.hxx b/vcl/inc/filter/XpmReader.hxx
similarity index 100%
rename from vcl/source/filter/ixpm/xpmread.hxx
rename to vcl/inc/filter/XpmReader.hxx
diff --git a/vcl/qa/cppunit/XpmFilterTest.cxx b/vcl/qa/cppunit/XpmFilterTest.cxx
new file mode 100644
index 000000000000..121dc62a4fd6
--- /dev/null
+++ b/vcl/qa/cppunit/XpmFilterTest.cxx
@@ -0,0 +1,76 @@
+/* -*- 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/XpmReader.hxx>
+#include <unotools/tempfile.hxx>
+
+class XpmFilterTest : public test::BootstrapFixture
+{
+public:
+    OUString maDataUrl;
+    OUString getFullUrl(std::u16string_view sFileName)
+    {
+        return m_directories.getURLFromSrc(maDataUrl) + sFileName;
+    }
+    XpmFilterTest()
+        : maDataUrl(u"/vcl/qa/cppunit/data/")
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(XpmFilterTest, testXPM_8bit)
+{
+    SvFileStream aFileStream(getFullUrl(u"XPM_8.xpm"), StreamMode::READ);
+    Graphic aGraphic;
+    CPPUNIT_ASSERT(ImportXPM(aFileStream, aGraphic));
+    auto aBitmap = aGraphic.GetBitmapEx();
+    CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Height());
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), aBitmap.GetBitCount());
+    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(XpmFilterTest, testXPM_4bit)
+{
+    SvFileStream aFileStream(getFullUrl(u"XPM_4.xpm"), StreamMode::READ);
+    Graphic aGraphic;
+    CPPUNIT_ASSERT(ImportXPM(aFileStream, aGraphic));
+    auto aBitmap = aGraphic.GetBitmapEx();
+    CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Height());
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), aBitmap.GetBitCount());
+    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(XpmFilterTest, testXPM_1bit)
+{
+    SvFileStream aFileStream(getFullUrl(u"XPM_1.xpm"), StreamMode::READ);
+    Graphic aGraphic;
+    CPPUNIT_ASSERT(ImportXPM(aFileStream, aGraphic));
+    auto aBitmap = aGraphic.GetBitmapEx();
+    CPPUNIT_ASSERT_EQUAL(tools::Long(10), aBitmap.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(10), aBitmap.GetSizePixel().Height());
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), aBitmap.GetBitCount());
+    CPPUNIT_ASSERT_EQUAL(Color(0xffffff), aBitmap.GetPixelColor(0, 0));
+    CPPUNIT_ASSERT_EQUAL(Color(0x72d1c8), aBitmap.GetPixelColor(1, 1));
+    CPPUNIT_ASSERT_EQUAL(Color(0x72d1c8), aBitmap.GetPixelColor(8, 8));
+    CPPUNIT_ASSERT_EQUAL(Color(0xffffff), aBitmap.GetPixelColor(9, 9));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/data/XPM_1.xpm b/vcl/qa/cppunit/data/XPM_1.xpm
new file mode 100644
index 000000000000..7b9b94359c56
--- /dev/null
+++ b/vcl/qa/cppunit/data/XPM_1.xpm
@@ -0,0 +1,15 @@
+/* XPM */
+static char * sample_xpm[] = {
+"10 10 2 1",
+" 	c #FFFFFF",
+".	c #72D1C8",
+"          ",
+" ........ ",
+" ........ ",
+" ........ ",
+" ........ ",
+" ........ ",
+" ........ ",
+" ........ ",
+" ........ ",
+"          "};
diff --git a/vcl/qa/cppunit/data/XPM_4.xpm b/vcl/qa/cppunit/data/XPM_4.xpm
new file mode 100644
index 000000000000..f958aa9a1f60
--- /dev/null
+++ b/vcl/qa/cppunit/data/XPM_4.xpm
@@ -0,0 +1,23 @@
+/* XPM */
+static char * XPM_4_xpm[] = {
+"4 4 16 1",
+" 	c #000000",
+".	c #800000",
+"+	c #008000",
+"@	c #808000",
+"#	c #000080",
+"$	c #800080",
+"%	c #008080",
+"&	c #808080",
+"*	c #C0C0C0",
+"=	c #FF0000",
+"-	c #00FF00",
+";	c #FFFF00",
+">	c #0000FF",
+",	c #FF00FF",
+"'	c #00FFFF",
+")	c #FFFFFF",
+">>==",
+">>==",
+";;--",
+";;--"};
diff --git a/vcl/qa/cppunit/data/XPM_8.xpm b/vcl/qa/cppunit/data/XPM_8.xpm
new file mode 100644
index 000000000000..82c354dfd197
--- /dev/null
+++ b/vcl/qa/cppunit/data/XPM_8.xpm
@@ -0,0 +1,263 @@
+/* XPM */
+static char * XPM_4_xpm[] = {
+"4 4 256 2",
+"  	c #000000",
+". 	c #800000",
+"+ 	c #008000",
+"@ 	c #808000",
+"# 	c #000080",
+"$ 	c #800080",
+"% 	c #008080",
+"& 	c #C0C0C0",
+"* 	c #C0DCC0",
+"= 	c #A6CAF0",
+"- 	c #402000",
+"; 	c #602000",
+"> 	c #802000",
+", 	c #A02000",
+"' 	c #C02000",
+") 	c #E02000",
+"! 	c #004000",
+"~ 	c #204000",
+"{ 	c #404000",
+"] 	c #604000",
+"^ 	c #804000",
+"/ 	c #A04000",
+"( 	c #C04000",
+"_ 	c #E04000",
+": 	c #006000",
+"< 	c #206000",
+"[ 	c #406000",
+"} 	c #606000",
+"| 	c #806000",
+"1 	c #A06000",
+"2 	c #C06000",
+"3 	c #E06000",
+"4 	c #008000",
+"5 	c #208000",
+"6 	c #408000",
+"7 	c #608000",
+"8 	c #808000",
+"9 	c #A08000",
+"0 	c #C08000",
+"a 	c #E08000",
+"b 	c #00A000",
+"c 	c #20A000",
+"d 	c #40A000",
+"e 	c #60A000",
+"f 	c #80A000",
+"g 	c #A0A000",
+"h 	c #C0A000",
+"i 	c #E0A000",
+"j 	c #00C000",
+"k 	c #20C000",
+"l 	c #40C000",
+"m 	c #60C000",
+"n 	c #80C000",
+"o 	c #A0C000",
+"p 	c #C0C000",
+"q 	c #E0C000",
+"r 	c #00E000",
+"s 	c #20E000",
+"t 	c #40E000",
+"u 	c #60E000",
+"v 	c #80E000",
+"w 	c #A0E000",
+"x 	c #C0E000",
+"y 	c #E0E000",
+"z 	c #000040",
+"A 	c #200040",
+"B 	c #400040",
+"C 	c #600040",
+"D 	c #800040",
+"E 	c #A00040",
+"F 	c #C00040",
+"G 	c #E00040",
+"H 	c #002040",
+"I 	c #202040",
+"J 	c #402040",
+"K 	c #602040",
+"L 	c #802040",
+"M 	c #A02040",
+"N 	c #C02040",
+"O 	c #E02040",
+"P 	c #004040",
+"Q 	c #204040",
+"R 	c #404040",
+"S 	c #604040",
+"T 	c #804040",
+"U 	c #A04040",
+"V 	c #C04040",
+"W 	c #E04040",
+"X 	c #006040",
+"Y 	c #206040",
+"Z 	c #406040",
+"` 	c #606040",
+" .	c #806040",
+"..	c #A06040",
+"+.	c #C06040",
+"@.	c #E06040",
+"#.	c #008040",
+"$.	c #208040",
+"%.	c #408040",
+"&.	c #608040",
+"*.	c #808040",
+"=.	c #A08040",
+"-.	c #C08040",
+";.	c #E08040",
+">.	c #00A040",
+",.	c #20A040",
+"'.	c #40A040",
+").	c #60A040",
+"!.	c #80A040",
+"~.	c #A0A040",
+"{.	c #C0A040",
+"].	c #E0A040",
+"^.	c #00C040",
+"/.	c #20C040",
+"(.	c #40C040",
+"_.	c #60C040",
+":.	c #80C040",
+"<.	c #A0C040",
+"[.	c #C0C040",
+"}.	c #E0C040",
+"|.	c #00E040",
+"1.	c #20E040",
+"2.	c #40E040",
+"3.	c #60E040",
+"4.	c #80E040",
+"5.	c #A0E040",
+"6.	c #C0E040",
+"7.	c #E0E040",
+"8.	c #000080",
+"9.	c #200080",
+"0.	c #400080",
+"a.	c #600080",
+"b.	c #800080",
+"c.	c #A00080",
+"d.	c #C00080",
+"e.	c #E00080",
+"f.	c #002080",
+"g.	c #202080",
+"h.	c #402080",
+"i.	c #602080",
+"j.	c #802080",
+"k.	c #A02080",
+"l.	c #C02080",
+"m.	c #E02080",
+"n.	c #004080",
+"o.	c #204080",
+"p.	c #404080",
+"q.	c #604080",
+"r.	c #804080",
+"s.	c #A04080",
+"t.	c #C04080",
+"u.	c #E04080",
+"v.	c #006080",
+"w.	c #206080",
+"x.	c #406080",
+"y.	c #606080",
+"z.	c #806080",
+"A.	c #A06080",
+"B.	c #C06080",
+"C.	c #E06080",
+"D.	c #008080",
+"E.	c #208080",
+"F.	c #408080",
+"G.	c #608080",
+"H.	c #808080",
+"I.	c #A08080",
+"J.	c #C08080",
+"K.	c #E08080",
+"L.	c #00A080",
+"M.	c #20A080",
+"N.	c #40A080",
+"O.	c #60A080",
+"P.	c #80A080",
+"Q.	c #A0A080",
+"R.	c #C0A080",
+"S.	c #E0A080",
+"T.	c #00C080",
+"U.	c #20C080",
+"V.	c #40C080",
+"W.	c #60C080",
+"X.	c #80C080",
+"Y.	c #A0C080",
+"Z.	c #C0C080",
+"`.	c #E0C080",
+" +	c #00E080",
+".+	c #20E080",
+"++	c #40E080",
+"@+	c #60E080",
+"#+	c #80E080",
+"$+	c #A0E080",
+"%+	c #C0E080",
+"&+	c #E0E080",
+"*+	c #0000C0",
+"=+	c #2000C0",
+"-+	c #4000C0",
+";+	c #6000C0",
+">+	c #8000C0",
+",+	c #A000C0",
+"'+	c #C000C0",
+")+	c #E000C0",
+"!+	c #0020C0",
+"~+	c #2020C0",
+"{+	c #4020C0",
+"]+	c #6020C0",
+"^+	c #8020C0",
+"/+	c #A020C0",
+"(+	c #C020C0",
+"_+	c #E020C0",
+":+	c #0040C0",
+"<+	c #2040C0",
+"[+	c #4040C0",
+"}+	c #6040C0",
+"|+	c #8040C0",
+"1+	c #A040C0",
+"2+	c #C040C0",
+"3+	c #E040C0",
+"4+	c #0060C0",
+"5+	c #2060C0",
+"6+	c #4060C0",
+"7+	c #6060C0",
+"8+	c #8060C0",
+"9+	c #A060C0",
+"0+	c #C060C0",
+"a+	c #E060C0",
+"b+	c #0080C0",
+"c+	c #2080C0",
+"d+	c #4080C0",
+"e+	c #6080C0",
+"f+	c #8080C0",
+"g+	c #A080C0",
+"h+	c #C080C0",
+"i+	c #E080C0",
+"j+	c #00A0C0",
+"k+	c #20A0C0",
+"l+	c #40A0C0",
+"m+	c #60A0C0",
+"n+	c #80A0C0",
+"o+	c #A0A0C0",
+"p+	c #C0A0C0",
+"q+	c #E0A0C0",
+"r+	c #00C0C0",
+"s+	c #20C0C0",
+"t+	c #40C0C0",
+"u+	c #60C0C0",
+"v+	c #80C0C0",
+"w+	c #A0C0C0",
+"x+	c #FFFBF0",
+"y+	c #A0A0A4",
+"z+	c #808080",
+"A+	c #FF0000",
+"B+	c #00FF00",
+"C+	c #FFFF00",
+"D+	c #0000FF",
+"E+	c #FF00FF",
+"F+	c #00FFFF",
+"G+	c #FFFFFF",
+"D+D+A+A+",
+"D+D+A+A+",
+"C+C+B+B+",
+"C+C+B+B+"};
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index be3e97bda2ef..cd29c5088a0e 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -45,7 +45,7 @@
 #include <vcl/pdfread.hxx>
 #include "jpeg/jpeg.hxx"
 #include "ixbm/xbmread.hxx"
-#include "ixpm/xpmread.hxx"
+#include <filter/XpmReader.hxx>
 #include <filter/TiffReader.hxx>
 #include <filter/TiffWriter.hxx>
 #include <filter/TgaReader.hxx>
diff --git a/vcl/source/filter/ixpm/xpmread.cxx b/vcl/source/filter/ixpm/xpmread.cxx
index 24e9cacb4fbe..77399dbdfd93 100644
--- a/vcl/source/filter/ixpm/xpmread.cxx
+++ b/vcl/source/filter/ixpm/xpmread.cxx
@@ -17,6 +17,8 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <filter/XpmReader.hxx>
+
 #include <vcl/graph.hxx>
 #include <tools/stream.hxx>
 
@@ -24,7 +26,6 @@
 #include <graphic/GraphicReader.hxx>
 
 #include "rgbtable.hxx"
-#include "xpmread.hxx"
 
 #include <cstring>
 #include <array>
diff --git a/vcl/workben/fftester.cxx b/vcl/workben/fftester.cxx
index 7d165d5a5957..cc39309ed91a 100644
--- a/vcl/workben/fftester.cxx
+++ b/vcl/workben/fftester.cxx
@@ -57,6 +57,7 @@
 #include <filter/PcdReader.hxx>
 #include <filter/PbmReader.hxx>
 #include <filter/DxfReader.hxx>
+#include <filter/XpmReader.hxx>
 #include <osl/file.hxx>
 #include <osl/module.hxx>
 #include <tools/stream.hxx>
@@ -64,7 +65,6 @@
 
 #include "../source/filter/igif/gifread.hxx"
 #include "../source/filter/ixbm/xbmread.hxx"
-#include "../source/filter/ixpm/xpmread.hxx"
 #include "../source/filter/jpeg/jpeg.hxx"
 
 using namespace ::com::sun::star::uno;
diff --git a/vcl/workben/xpmfuzzer.cxx b/vcl/workben/xpmfuzzer.cxx
index 700761d1725f..bd9413fb522f 100644
--- a/vcl/workben/xpmfuzzer.cxx
+++ b/vcl/workben/xpmfuzzer.cxx
@@ -8,7 +8,7 @@
  */
 
 #include <tools/stream.hxx>
-#include <../source/filter/ixpm/xpmread.hxx>
+#include <filter/XpmReader.hxx>
 #include "commonfuzzer.hxx"
 
 #include <config_features.h>


More information about the Libreoffice-commits mailing list