summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-02-14 23:20:28 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-02-17 04:02:13 +0100
commit1093c21ed9736368ecfb8f5c7935db31256671f0 (patch)
treefe315c5464ee54d79f8c8b5253a62337832f2313 /vcl
parente916e8c1816a17408cba52787035ffd9fbae5789 (diff)
Move RAS and PCX reader from filter module into VCL
Change-Id: Id846abf257b598489a59ebf9b62b19840a950322 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111015 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/CppunitTest_vcl_filters_test.mk6
-rw-r--r--vcl/Library_vcl.mk2
-rw-r--r--vcl/inc/filter/PcxReader.hxx26
-rw-r--r--vcl/inc/filter/RasReader.hxx26
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/fail/.gitignore0
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-1.pcxbin0 -> 41066 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-2.pcxbin0 -> 41136 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-3.pcxbin0 -> 41107 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2008-1097-1.pcxbin0 -> 91531 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/fail/hang-1.pcxbin0 -> 897 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/indeterminate/.gitignore1
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/pass/.gitignore0
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/pcx/pass/rhbz469075-1.pcxbin0 -> 58596 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/fail/.gitignore0
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2007-2356-1.rasbin0 -> 4000 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2008-1097-1.rasbin0 -> 92752 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/fail/crash-1.rasbin0 -> 913 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/fail/hang-1.rasbin0 -> 40 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/indeterminate/.gitignore1
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/pass/.gitignore0
-rw-r--r--vcl/qa/cppunit/graphicfilter/data/ras/pass/marbles.rasbin0 -> 4262290 bytes
-rw-r--r--vcl/qa/cppunit/graphicfilter/filters-pcx-test.cxx61
-rw-r--r--vcl/qa/cppunit/graphicfilter/filters-ras-test.cxx61
-rw-r--r--vcl/source/filter/FilterConfigCache.cxx12
-rw-r--r--vcl/source/filter/graphicfilter.cxx38
-rw-r--r--vcl/source/filter/ipcx/ipcx.cxx411
-rw-r--r--vcl/source/filter/iras/iras.cxx414
-rw-r--r--vcl/workben/fftester.cxx24
-rw-r--r--vcl/workben/pcxfuzzer.cxx5
-rw-r--r--vcl/workben/rasfuzzer.cxx5
30 files changed, 1047 insertions, 46 deletions
diff --git a/vcl/CppunitTest_vcl_filters_test.mk b/vcl/CppunitTest_vcl_filters_test.mk
index b643a2580791..87a5da8e9284 100644
--- a/vcl/CppunitTest_vcl_filters_test.mk
+++ b/vcl/CppunitTest_vcl_filters_test.mk
@@ -10,11 +10,13 @@
$(eval $(call gb_CppunitTest_CppunitTest,vcl_filters_test))
$(eval $(call gb_CppunitTest_add_exception_objects,vcl_filters_test, \
+ vcl/qa/cppunit/graphicfilter/filters-met-test \
+ vcl/qa/cppunit/graphicfilter/filters-pcx-test \
+ vcl/qa/cppunit/graphicfilter/filters-pict-test \
+ vcl/qa/cppunit/graphicfilter/filters-ras-test \
vcl/qa/cppunit/graphicfilter/filters-test \
vcl/qa/cppunit/graphicfilter/filters-tiff-test \
vcl/qa/cppunit/graphicfilter/filters-tga-test \
- vcl/qa/cppunit/graphicfilter/filters-pict-test \
- vcl/qa/cppunit/graphicfilter/filters-met-test \
))
$(eval $(call gb_CppunitTest_set_include,vcl_filters_test,\
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index a5e624f80c0a..08815ddc95e1 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -438,10 +438,12 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/filter/igif/decode \
vcl/source/filter/igif/gifread \
vcl/source/filter/imet/ios2met \
+ vcl/source/filter/ipcx/ipcx \
vcl/source/filter/ipict/ipict \
vcl/source/filter/ipict/shape \
vcl/source/filter/ipdf/pdfread \
vcl/source/filter/ipdf/pdfdocument \
+ vcl/source/filter/iras/iras \
vcl/source/filter/itga/itga \
vcl/source/filter/itiff/ccidecom \
vcl/source/filter/itiff/itiff \
diff --git a/vcl/inc/filter/PcxReader.hxx b/vcl/inc/filter/PcxReader.hxx
new file mode 100644
index 000000000000..73e182c62895
--- /dev/null
+++ b/vcl/inc/filter/PcxReader.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 ImportPcxGraphic(SvStream& rStream, Graphic& rGraphic);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/filter/RasReader.hxx b/vcl/inc/filter/RasReader.hxx
new file mode 100644
index 000000000000..ea658cb317c0
--- /dev/null
+++ b/vcl/inc/filter/RasReader.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 ImportRasGraphic(SvStream& rStream, Graphic& rGraphic);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/fail/.gitignore b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/.gitignore
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/.gitignore
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-1.pcx b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-1.pcx
new file mode 100644
index 000000000000..915f38aec2e3
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-1.pcx
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-2.pcx b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-2.pcx
new file mode 100644
index 000000000000..9c8a751a486d
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-2.pcx
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-3.pcx b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-3.pcx
new file mode 100644
index 000000000000..41175653a4ca
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-3.pcx
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2008-1097-1.pcx b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2008-1097-1.pcx
new file mode 100644
index 000000000000..c55c64ed9a8a
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2008-1097-1.pcx
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/fail/hang-1.pcx b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/hang-1.pcx
new file mode 100644
index 000000000000..73798ea56160
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/hang-1.pcx
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/indeterminate/.gitignore b/vcl/qa/cppunit/graphicfilter/data/pcx/indeterminate/.gitignore
new file mode 100644
index 000000000000..f73b09798145
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/indeterminate/.gitignore
@@ -0,0 +1 @@
+*.pcx-*
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/pass/.gitignore b/vcl/qa/cppunit/graphicfilter/data/pcx/pass/.gitignore
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/pass/.gitignore
diff --git a/vcl/qa/cppunit/graphicfilter/data/pcx/pass/rhbz469075-1.pcx b/vcl/qa/cppunit/graphicfilter/data/pcx/pass/rhbz469075-1.pcx
new file mode 100644
index 000000000000..d928c08908ba
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/pcx/pass/rhbz469075-1.pcx
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/fail/.gitignore b/vcl/qa/cppunit/graphicfilter/data/ras/fail/.gitignore
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/fail/.gitignore
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2007-2356-1.ras b/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2007-2356-1.ras
new file mode 100644
index 000000000000..c00c27016b57
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2007-2356-1.ras
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2008-1097-1.ras b/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2008-1097-1.ras
new file mode 100644
index 000000000000..effd654ac5e4
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2008-1097-1.ras
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/fail/crash-1.ras b/vcl/qa/cppunit/graphicfilter/data/ras/fail/crash-1.ras
new file mode 100644
index 000000000000..d1abbaefcbae
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/fail/crash-1.ras
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/fail/hang-1.ras b/vcl/qa/cppunit/graphicfilter/data/ras/fail/hang-1.ras
new file mode 100644
index 000000000000..44dec67607b4
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/fail/hang-1.ras
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/indeterminate/.gitignore b/vcl/qa/cppunit/graphicfilter/data/ras/indeterminate/.gitignore
new file mode 100644
index 000000000000..60147ad08a9d
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/indeterminate/.gitignore
@@ -0,0 +1 @@
+*.ras-*
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/pass/.gitignore b/vcl/qa/cppunit/graphicfilter/data/ras/pass/.gitignore
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/pass/.gitignore
diff --git a/vcl/qa/cppunit/graphicfilter/data/ras/pass/marbles.ras b/vcl/qa/cppunit/graphicfilter/data/ras/pass/marbles.ras
new file mode 100644
index 000000000000..9b3fb0d853b6
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/data/ras/pass/marbles.ras
Binary files differ
diff --git a/vcl/qa/cppunit/graphicfilter/filters-pcx-test.cxx b/vcl/qa/cppunit/graphicfilter/filters-pcx-test.cxx
new file mode 100644
index 000000000000..5297631517da
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/filters-pcx-test.cxx
@@ -0,0 +1,61 @@
+/* -*- 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 <unotest/filters-test.hxx>
+#include <test/bootstrapfixture.hxx>
+#include <vcl/FilterConfigItem.hxx>
+#include <tools/stream.hxx>
+#include <vcl/graph.hxx>
+#include <filter/PcxReader.hxx>
+
+using namespace css;
+
+/* Implementation of Filters test */
+
+class PcxFilterTest
+ : public test::FiltersTest
+ , public test::BootstrapFixture
+{
+public:
+ PcxFilterTest() : BootstrapFixture(true, false) {}
+
+ virtual bool load(const OUString &,
+ const OUString &rURL, const OUString &,
+ SfxFilterFlags, SotClipboardFormatId, unsigned int) override;
+
+ /**
+ * Ensure CVEs remain unbroken
+ */
+ void testCVEs();
+
+ CPPUNIT_TEST_SUITE(PcxFilterTest);
+ CPPUNIT_TEST(testCVEs);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+bool PcxFilterTest::load(const OUString &,
+ const OUString &rURL, const OUString &,
+ SfxFilterFlags, SotClipboardFormatId, unsigned int)
+{
+ SvFileStream aFileStream(rURL, StreamMode::READ);
+ Graphic aGraphic;
+ return ImportPcxGraphic(aFileStream, aGraphic);
+}
+
+void PcxFilterTest::testCVEs()
+{
+#ifndef DISABLE_CVE_TESTS
+ testDir(OUString(),
+ m_directories.getURLFromSrc(u"/vcl/qa/cppunit/graphicfilter/data/pcx/"));
+#endif
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PcxFilterTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/graphicfilter/filters-ras-test.cxx b/vcl/qa/cppunit/graphicfilter/filters-ras-test.cxx
new file mode 100644
index 000000000000..d986c7d0dbf1
--- /dev/null
+++ b/vcl/qa/cppunit/graphicfilter/filters-ras-test.cxx
@@ -0,0 +1,61 @@
+/* -*- 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 <unotest/filters-test.hxx>
+#include <test/bootstrapfixture.hxx>
+#include <vcl/FilterConfigItem.hxx>
+#include <tools/stream.hxx>
+#include <vcl/graph.hxx>
+#include <filter/RasReader.hxx>
+
+using namespace css;
+
+/* Implementation of Filters test */
+
+class RasFilterTest
+ : public test::FiltersTest
+ , public test::BootstrapFixture
+{
+public:
+ RasFilterTest() : BootstrapFixture(true, false) {}
+
+ virtual bool load(const OUString &,
+ const OUString &rURL, const OUString &,
+ SfxFilterFlags, SotClipboardFormatId, unsigned int) override;
+
+ /**
+ * Ensure CVEs remain unbroken
+ */
+ void testCVEs();
+
+ CPPUNIT_TEST_SUITE(RasFilterTest);
+ CPPUNIT_TEST(testCVEs);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+bool RasFilterTest::load(const OUString &,
+ const OUString &rURL, const OUString &,
+ SfxFilterFlags, SotClipboardFormatId, unsigned int)
+{
+ SvFileStream aFileStream(rURL, StreamMode::READ);
+ Graphic aGraphic;
+ return ImportRasGraphic(aFileStream, aGraphic);
+}
+
+void RasFilterTest::testCVEs()
+{
+#ifndef DISABLE_CVE_TESTS
+ testDir(OUString(),
+ m_directories.getURLFromSrc(u"/vcl/qa/cppunit/graphicfilter/data/ras/"));
+#endif
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(RasFilterTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/FilterConfigCache.cxx b/vcl/source/filter/FilterConfigCache.cxx
index a004e693641d..2263c36b6dbe 100644
--- a/vcl/source/filter/FilterConfigCache.cxx
+++ b/vcl/source/filter/FilterConfigCache.cxx
@@ -43,7 +43,7 @@ const char* FilterConfigCache::FilterConfigCacheEntry::InternalPixelFilterNameLi
{
IMP_BMP, IMP_GIF, IMP_PNG, IMP_JPEG, IMP_XBM, IMP_XPM,
EXP_BMP, EXP_JPEG, EXP_PNG, IMP_MOV, IMP_TIFF, EXP_TIFF,
- IMP_TGA, IMP_PICT, IMP_MET, nullptr
+ IMP_TGA, IMP_PICT, IMP_MET, IMP_RAS, IMP_PCX, nullptr
};
const char* FilterConfigCache::FilterConfigCacheEntry::InternalVectorFilterNameList[] =
@@ -54,8 +54,8 @@ const char* FilterConfigCache::FilterConfigCacheEntry::InternalVectorFilterNameL
const char* FilterConfigCache::FilterConfigCacheEntry::ExternalPixelFilterNameList[] =
{
- "egi", "icd", "ipd", "ipx", "ipb", "epb", "epg",
- "epp", "ira", "era", "exp", nullptr
+ "egi", "icd", "ipd", "ipb", "epb", "epg",
+ "epp", nullptr
};
void FilterConfigCache::FilterConfigCacheEntry::CreateFilterName( const OUString& rUserDataEntry )
@@ -235,12 +235,11 @@ const char* FilterConfigCache::InternalFilterListForSvxLight[] =
"pct","1","SVPICT",
"pcd","1","icd",
"psd","1","ipd",
- "pcx","1","ipx",
+ "pcx","1","SVPCX",
"pbm","1","ipb",
"pgm","1","ipb",
"ppm","1","ipb",
- "ras","1","ira",
- "ras","2","era",
+ "ras","1","SVRAS",
"svm","1","SVMETAFILE",
"svm","2","SVMETAFILE",
"tga","1","SVTGA",
@@ -252,7 +251,6 @@ const char* FilterConfigCache::InternalFilterListForSvxLight[] =
"wmf","2","SVWMF",
"xbm","1","SVIXBM",
"xpm","1","SVIXPM",
- "xpm","2","exp",
"svg","1","SVISVG",
"svg","2","SVESVG",
nullptr
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 7b394dcd90b5..e80291e6a3e0 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -52,6 +52,8 @@
#include <filter/TgaReader.hxx>
#include <filter/PictReader.hxx>
#include <filter/MetReader.hxx>
+#include <filter/RasReader.hxx>
+#include <filter/PcxReader.hxx>
#include <osl/module.hxx>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/awt/Size.hpp>
@@ -647,8 +649,6 @@ extern "C" bool idxGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterCo
extern "C" bool ipbGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
extern "C" bool ipdGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
extern "C" bool ipsGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
-extern "C" bool ipxGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
-extern "C" bool iraGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
#endif
@@ -667,10 +667,6 @@ PFilterCall ImpFilterLibCacheEntry::GetImportFunction()
mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("ipdGraphicImport"));
else if (maFormatName == "ips")
mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("ipsGraphicImport"));
- else if (maFormatName == "ipx")
- mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("ipxGraphicImport"));
- else if (maFormatName == "ira")
- mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("iraGraphicImport"));
#else
if (maFormatName == "icd")
mpfnImport = icdGraphicImport;
@@ -682,10 +678,6 @@ PFilterCall ImpFilterLibCacheEntry::GetImportFunction()
mpfnImport = ipdGraphicImport;
else if (maFormatName == "ips")
mpfnImport = ipsGraphicImport;
- else if (maFormatName == "ipx")
- mpfnImport = ipxGraphicImport;
- else if (maFormatName == "ira")
- mpfnImport = iraGraphicImport;
#endif
}
@@ -1415,7 +1407,7 @@ void GraphicFilter::preload()
sal_Int32 nTokenCount = comphelper::string::getTokenCount(aFilterPath, ';');
ImpFilterLibCache& rCache = Cache::get();
static const std::initializer_list<std::u16string_view> aFilterNames = {
- u"icd", u"idx", u"ipb", u"ipd", u"ips", u"ipx", u"ira",
+ u"icd", u"idx", u"ipb", u"ipd", u"ips",
};
// Load library for each filter.
@@ -1729,6 +1721,22 @@ ErrCode GraphicFilter::readMET(SvStream & rStream, Graphic & rGraphic, GfxLinkTy
return ERRCODE_GRFILTER_FILTERERROR;
}
+ErrCode GraphicFilter::readRAS(SvStream & rStream, Graphic & rGraphic)
+{
+ if (ImportRasGraphic(rStream, rGraphic))
+ return ERRCODE_NONE;
+ else
+ return ERRCODE_GRFILTER_FILTERERROR;
+}
+
+ErrCode GraphicFilter::readPCX(SvStream & rStream, Graphic & rGraphic)
+{
+ if (ImportPcxGraphic(rStream, rGraphic))
+ return ERRCODE_NONE;
+ else
+ return ERRCODE_GRFILTER_FILTERERROR;
+}
+
ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, SvStream& rIStream,
sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, GraphicFilterImportFlags nImportFlags,
const css::uno::Sequence< css::beans::PropertyValue >* /*pFilterData*/,
@@ -1854,6 +1862,14 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
{
nStatus = readMET(rIStream, rGraphic, eLinkType);
}
+ else if (aFilterName.equalsIgnoreAsciiCase(IMP_RAS))
+ {
+ nStatus = readRAS(rIStream, rGraphic);
+ }
+ else if (aFilterName.equalsIgnoreAsciiCase(IMP_PCX))
+ {
+ nStatus = readPCX(rIStream, rGraphic);
+ }
else
nStatus = ERRCODE_GRFILTER_FILTERERROR;
}
diff --git a/vcl/source/filter/ipcx/ipcx.cxx b/vcl/source/filter/ipcx/ipcx.cxx
new file mode 100644
index 000000000000..413ba95f4256
--- /dev/null
+++ b/vcl/source/filter/ipcx/ipcx.cxx
@@ -0,0 +1,411 @@
+/* -*- 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 <memory>
+#include <vcl/graph.hxx>
+#include <vcl/BitmapTools.hxx>
+#include <tools/stream.hxx>
+#include <filter/PcxReader.hxx>
+
+class FilterConfigItem;
+
+//============================ PCXReader ==================================
+
+namespace {
+
+class PCXReader {
+
+private:
+
+ SvStream& m_rPCX; // the PCX file to read
+
+ std::unique_ptr<vcl::bitmap::RawBitmap> mpBitmap;
+ std::vector<Color> mvPalette;
+ sal_uInt8 nVersion; // PCX-Version
+ sal_uInt8 nEncoding; // compression type
+ sal_uInt16 nBitsPerPlanePix; // bits per plane per pixel
+ sal_uInt16 nPlanes; // no of planes
+ sal_uInt16 nBytesPerPlaneLin; // bytes per plane line
+
+ sal_uInt32 nWidth, nHeight; // dimension in pixel
+ sal_uInt16 nResX, nResY; // resolution in pixel per inch or 0,0
+ sal_uInt16 nDestBitsPerPixel; // bits per pixel in destination bitmap 1,4,8 or 24
+ std::unique_ptr<sal_uInt8[]>
+ pPalette;
+ bool bStatus; // from now on do not read status from stream ( SJ )
+
+
+ void ImplReadBody();
+ void ImplReadPalette( unsigned int nCol );
+ void ImplReadHeader();
+
+public:
+ explicit PCXReader(SvStream &rStream);
+ bool ReadPCX(Graphic & rGraphic );
+ // Reads a PCX file from the stream and fills the GDIMetaFile
+};
+
+}
+
+//=================== methods of PCXReader ==============================
+
+PCXReader::PCXReader(SvStream &rStream)
+ : m_rPCX(rStream)
+ , nVersion(0)
+ , nEncoding(0)
+ , nBitsPerPlanePix(0)
+ , nPlanes(0)
+ , nBytesPerPlaneLin(0)
+ , nWidth(0)
+ , nHeight(0)
+ , nResX(0)
+ , nResY(0)
+ , nDestBitsPerPixel(0)
+ , pPalette(new sal_uInt8[ 768 ])
+ , bStatus(false)
+{
+}
+
+bool PCXReader::ReadPCX(Graphic & rGraphic)
+{
+ if ( m_rPCX.GetError() )
+ return false;
+
+ m_rPCX.SetEndian(SvStreamEndian::LITTLE);
+
+ // read header:
+
+ bStatus = true;
+
+ ImplReadHeader();
+
+ // sanity check there is enough data before trying allocation
+ if (bStatus && nBytesPerPlaneLin > m_rPCX.remainingSize() / nPlanes)
+ {
+ bStatus = false;
+ }
+
+ if (bStatus)
+ {
+ sal_uInt32 nResult;
+ bStatus = !o3tl::checked_multiply(nWidth, nHeight, nResult) && nResult <= SAL_MAX_INT32/2/3;
+ }
+
+ // Write BMP header and conditionally (maybe invalid for now) color palette:
+ if (bStatus)
+ {
+ mpBitmap.reset( new vcl::bitmap::RawBitmap( Size( nWidth, nHeight ), 24 ) );
+
+ if ( nDestBitsPerPixel <= 8 )
+ {
+ sal_uInt16 nColors = 1 << nDestBitsPerPixel;
+ sal_uInt8* pPal = pPalette.get();
+ mvPalette.resize( nColors );
+ for ( sal_uInt16 i = 0; i < nColors; i++, pPal += 3 )
+ {
+ mvPalette[i] = Color( pPal[ 0 ], pPal[ 1 ], pPal[ 2 ] );
+ }
+ }
+
+ // read bitmap data
+ ImplReadBody();
+
+ // If an extended color palette exists at the end of the file, then read it and
+ // and write again in palette:
+ if ( nDestBitsPerPixel == 8 && bStatus )
+ {
+ sal_uInt8* pPal = pPalette.get();
+ m_rPCX.SeekRel(1);
+ ImplReadPalette(256);
+ mvPalette.resize( 256 );
+ for ( sal_uInt16 i = 0; i < 256; i++, pPal += 3 )
+ {
+ mvPalette[i] = Color( pPal[ 0 ], pPal[ 1 ], pPal[ 2 ] );
+ }
+ }
+
+ if ( bStatus )
+ {
+ rGraphic = vcl::bitmap::CreateFromData(std::move(*mpBitmap));
+ return true;
+ }
+ }
+ return false;
+}
+
+void PCXReader::ImplReadHeader()
+{
+ sal_uInt8 nbyte(0);
+ m_rPCX.ReadUChar( nbyte ).ReadUChar( nVersion ).ReadUChar( nEncoding );
+ if ( nbyte!=0x0a || (nVersion != 0 && nVersion != 2 && nVersion != 3 && nVersion != 5) || nEncoding > 1 )
+ {
+ bStatus = false;
+ return;
+ }
+
+ nbyte = 0;
+ m_rPCX.ReadUChar( nbyte ); nBitsPerPlanePix = static_cast<sal_uInt16>(nbyte);
+ sal_uInt16 nMinX(0),nMinY(0),nMaxX(0),nMaxY(0);
+ m_rPCX.ReadUInt16( nMinX ).ReadUInt16( nMinY ).ReadUInt16( nMaxX ).ReadUInt16( nMaxY );
+
+ if ((nMinX > nMaxX) || (nMinY > nMaxY))
+ {
+ bStatus = false;
+ return;
+ }
+
+ nWidth = nMaxX-nMinX+1;
+ nHeight = nMaxY-nMinY+1;
+
+ m_rPCX.ReadUInt16( nResX );
+ m_rPCX.ReadUInt16( nResY );
+ if ( nResX >= nWidth || nResY >= nHeight || ( nResX != nResY ) )
+ nResX = nResY = 0;
+
+ ImplReadPalette( 16 );
+
+ m_rPCX.SeekRel( 1 );
+ nbyte = 0;
+ m_rPCX.ReadUChar( nbyte ); nPlanes = static_cast<sal_uInt16>(nbyte);
+ sal_uInt16 nushort(0);
+ m_rPCX.ReadUInt16( nushort ); nBytesPerPlaneLin = nushort;
+ sal_uInt16 nPaletteInfo;
+ m_rPCX.ReadUInt16( nPaletteInfo );
+
+ m_rPCX.SeekRel( 58 );
+
+ nDestBitsPerPixel = nBitsPerPlanePix * nPlanes;
+ if (nDestBitsPerPixel == 2 || nDestBitsPerPixel == 3) nDestBitsPerPixel = 4;
+
+ if ( ( nDestBitsPerPixel != 1 && nDestBitsPerPixel != 4 && nDestBitsPerPixel != 8 && nDestBitsPerPixel != 24 )
+ || nPlanes > 4 || nBytesPerPlaneLin < ( ( nWidth * nBitsPerPlanePix+7 ) >> 3 ) )
+ {
+ bStatus = false;
+ return;
+ }
+
+ // If the bitmap has only 2 colors, the palette is most often invalid and it is always(?)
+ // a black and white image:
+ if ( nPlanes == 1 && nBitsPerPlanePix == 1 )
+ {
+ pPalette[ 0 ] = pPalette[ 1 ] = pPalette[ 2 ] = 0x00;
+ pPalette[ 3 ] = pPalette[ 4 ] = pPalette[ 5 ] = 0xff;
+ }
+}
+
+void PCXReader::ImplReadBody()
+{
+ std::unique_ptr<sal_uInt8[]> pPlane[ 4 ];
+ sal_uInt8 * pDest;
+ sal_uInt32 i, ny, nLastPercent = 0, nPercent;
+ sal_uInt16 nCount, nx, np;
+ sal_uInt8 nDat = 0, nCol = 0;
+
+ for( np = 0; np < nPlanes; np++ )
+ pPlane[ np ].reset(new sal_uInt8[ nBytesPerPlaneLin ]);
+
+ nCount = 0;
+ for ( ny = 0; ny < nHeight; ny++ )
+ {
+ if (!m_rPCX.good())
+ {
+ bStatus = false;
+ break;
+ }
+ nPercent = ny * 60 / nHeight + 10;
+ if ( ny == 0 || nLastPercent + 4 <= nPercent )
+ {
+ nLastPercent = nPercent;
+ }
+ for ( np = 0; np < nPlanes; np++)
+ {
+ if ( nEncoding == 0)
+ m_rPCX.ReadBytes( static_cast<void *>(pPlane[ np ].get()), nBytesPerPlaneLin );
+ else
+ {
+ pDest = pPlane[ np ].get();
+ nx = nBytesPerPlaneLin;
+ while ( nCount > 0 && nx > 0)
+ {
+ *(pDest++) = nDat;
+ nx--;
+ nCount--;
+ }
+ while (nx > 0 && m_rPCX.good())
+ {
+ m_rPCX.ReadUChar( nDat );
+ if ( ( nDat & 0xc0 ) == 0xc0 )
+ {
+ nCount =static_cast<sal_uInt64>(nDat) & 0x003f;
+ m_rPCX.ReadUChar( nDat );
+ if ( nCount < nx )
+ {
+ nx -= nCount;
+ while ( nCount > 0)
+ {
+ *(pDest++) = nDat;
+ nCount--;
+ }
+ }
+ else
+ {
+ nCount -= nx;
+ do
+ {
+ *(pDest++) = nDat;
+ nx--;
+ }
+ while ( nx > 0 );
+ break;
+ }
+ }
+ else
+ {
+ *(pDest++) = nDat;
+ nx--;
+ }
+ }
+ }
+ }
+ sal_uInt8 *pSource1 = pPlane[ 0 ].get();
+ sal_uInt8 *pSource2 = pPlane[ 1 ].get();
+ sal_uInt8 *pSource3 = pPlane[ 2 ].get();
+ sal_uInt8 *pSource4 = pPlane[ 3 ].get();
+ switch ( nBitsPerPlanePix + ( nPlanes << 8 ) )
+ {
+ // 2 colors
+ case 0x101 :
+ for ( i = 0; i < nWidth; i++ )
+ {
+ sal_uInt32 nShift = ( i & 7 ) ^ 7;
+ if ( nShift == 0 )
+ mpBitmap->SetPixel( ny, i, mvPalette[*(pSource1++) & 1] );
+ else
+ mpBitmap->SetPixel( ny, i, mvPalette[(*pSource1 >> nShift ) & 1] );
+ }
+ break;
+ // 4 colors
+ case 0x102 :
+ for ( i = 0; i < nWidth; i++ )
+ {
+ switch( i & 3 )
+ {
+ case 0 :
+ nCol = *pSource1 >> 6;
+ break;
+ case 1 :
+ nCol = ( *pSource1 >> 4 ) & 0x03 ;
+ break;
+ case 2 :
+ nCol = ( *pSource1 >> 2 ) & 0x03;
+ break;
+ case 3 :
+ nCol = ( *pSource1++ ) & 0x03;
+ break;
+ }
+ mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
+ }
+ break;
+ // 256 colors
+ case 0x108 :
+ for ( i = 0; i < nWidth; i++ )
+ {
+ mpBitmap->SetPixel( ny, i, mvPalette[*pSource1++] );
+ }
+ break;
+ // 8 colors
+ case 0x301 :
+ for ( i = 0; i < nWidth; i++ )
+ {
+ sal_uInt32 nShift = ( i & 7 ) ^ 7;
+ if ( nShift == 0 )
+ {
+ nCol = ( *pSource1++ & 1) + ( ( *pSource2++ << 1 ) & 2 ) + ( ( *pSource3++ << 2 ) & 4 );
+ mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
+ }
+ else
+ {
+ nCol = sal::static_int_cast< sal_uInt8 >(
+ ( ( *pSource1 >> nShift ) & 1) + ( ( ( *pSource2 >> nShift ) << 1 ) & 2 ) +
+ ( ( ( *pSource3 >> nShift ) << 2 ) & 4 ));
+ mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
+ }
+ }
+ break;
+ // 16 colors
+ case 0x401 :
+ for ( i = 0; i < nWidth; i++ )
+ {
+ sal_uInt32 nShift = ( i & 7 ) ^ 7;
+ if ( nShift == 0 )
+ {
+ nCol = ( *pSource1++ & 1) + ( ( *pSource2++ << 1 ) & 2 ) + ( ( *pSource3++ << 2 ) & 4 ) +
+ ( ( *pSource4++ << 3 ) & 8 );
+ mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
+ }
+ else
+ {
+ nCol = sal::static_int_cast< sal_uInt8 >(
+ ( ( *pSource1 >> nShift ) & 1) + ( ( ( *pSource2 >> nShift ) << 1 ) & 2 ) +
+ ( ( ( *pSource3 >> nShift ) << 2 ) & 4 ) + ( ( ( *pSource4 >> nShift ) << 3 ) & 8 ));
+ mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
+ }
+ }
+ break;
+ // 16m colors
+ case 0x308 :
+ for ( i = 0; i < nWidth; i++ )
+ {
+ mpBitmap->SetPixel( ny, i, Color( *pSource1++, *pSource2++, *pSource3++ ) );
+
+ }
+ break;
+ default :
+ bStatus = false;
+ break;
+ }
+ }
+}
+
+void PCXReader::ImplReadPalette( unsigned int nCol )
+{
+ sal_uInt8 r, g, b;
+ sal_uInt8* pPtr = pPalette.get();
+ for ( unsigned int i = 0; i < nCol; i++ )
+ {
+ m_rPCX.ReadUChar( r ).ReadUChar( g ).ReadUChar( b );
+ *pPtr++ = r;
+ *pPtr++ = g;
+ *pPtr++ = b;
+ }
+}
+
+//================== GraphicImport - the exported function ================
+
+bool ImportPcxGraphic(SvStream & rStream, Graphic & rGraphic)
+{
+ PCXReader aPCXReader(rStream);
+ bool bRetValue = aPCXReader.ReadPCX(rGraphic);
+ if ( !bRetValue )
+ rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
+ return bRetValue;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/iras/iras.cxx b/vcl/source/filter/iras/iras.cxx
new file mode 100644
index 000000000000..415e3224d6fb
--- /dev/null
+++ b/vcl/source/filter/iras/iras.cxx
@@ -0,0 +1,414 @@
+/* -*- 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 <vcl/graph.hxx>
+#include <vcl/BitmapTools.hxx>
+#include <sal/log.hxx>
+#include <tools/stream.hxx>
+#include <filter/RasReader.hxx>
+
+class FilterConfigItem;
+
+#define RAS_TYPE_OLD 0x00000000 // supported formats by this filter
+#define RAS_TYPE_STANDARD 0x00000001
+#define RAS_TYPE_BYTE_ENCODED 0x00000002
+#define RAS_TYPE_RGB_FORMAT 0x00000003
+
+#define RAS_COLOR_NO_MAP 0x00000000
+#define RAS_COLOR_RGB_MAP 0x00000001
+#define RAS_COLOR_RAW_MAP 0x00000002
+
+#define SUNRASTER_MAGICNUMBER 0x59a66a95
+
+//============================ RASReader ==================================
+
+namespace {
+
+class RASReader {
+
+private:
+
+ SvStream& m_rRAS; // the RAS file to be read in
+
+ bool mbStatus;
+ sal_Int32 mnWidth, mnHeight; // image dimensions in pixels
+ sal_uInt16 mnDstBitsPerPix;
+ sal_uInt16 mnDstColors;
+ sal_Int32 mnDepth, mnImageDatSize, mnType;
+ sal_Int32 mnColorMapType, mnColorMapSize;
+ sal_uInt8 mnRepCount, mnRepVal; // RLE Decoding
+
+ bool ImplReadBody(vcl::bitmap::RawBitmap&, std::vector<Color> const & rvPalette);
+ bool ImplReadHeader();
+ sal_uInt8 ImplGetByte();
+
+public:
+ explicit RASReader(SvStream &rRAS);
+ bool ReadRAS(Graphic & rGraphic);
+};
+
+}
+
+//=================== Methods of RASReader ==============================
+
+RASReader::RASReader(SvStream &rRAS)
+ : m_rRAS(rRAS)
+ , mbStatus(true)
+ , mnWidth(0)
+ , mnHeight(0)
+ , mnDstBitsPerPix(0)
+ , mnDstColors(0)
+ , mnDepth(0)
+ , mnImageDatSize(0)
+ , mnType(0)
+ , mnColorMapType(0)
+ , mnColorMapSize(0)
+ , mnRepCount(0)
+ , mnRepVal(0)
+{
+}
+
+bool RASReader::ReadRAS(Graphic & rGraphic)
+{
+ sal_uInt32 nMagicNumber;
+
+ if ( m_rRAS.GetError() )
+ return false;
+
+ m_rRAS.SetEndian( SvStreamEndian::BIG );
+ m_rRAS.ReadUInt32( nMagicNumber );
+ if ( nMagicNumber != SUNRASTER_MAGICNUMBER )
+ return false;
+
+ // Kopf einlesen:
+
+ mbStatus = ImplReadHeader();
+ if ( !mbStatus )
+ return false;
+
+ std::vector<Color> aPalette;
+ bool bOk = true;
+
+ if ( mnDstBitsPerPix <= 8 ) // pallets pictures
+ {
+ bool bPalette(false);
+
+ if ( mnColorMapType == RAS_COLOR_RAW_MAP ) // RAW color map is skipped
+ {
+ sal_uInt64 nCurPos = m_rRAS.Tell();
+ bOk = checkSeek(m_rRAS, nCurPos + mnColorMapSize);
+ }
+ else if ( mnColorMapType == RAS_COLOR_RGB_MAP ) // we can read out the RGB
+ {
+ mnDstColors = static_cast<sal_uInt16>( mnColorMapSize / 3 );
+
+ if ( ( 1 << mnDstBitsPerPix ) < mnDstColors )
+ return false;
+
+ if ( ( mnDstColors >= 2 ) && ( ( mnColorMapSize % 3 ) == 0 ) )
+ {
+ aPalette.resize(mnDstColors);
+ sal_uInt16 i;
+ sal_uInt8 nRed[256], nGreen[256], nBlue[256];
+ for ( i = 0; i < mnDstColors; i++ ) m_rRAS.ReadUChar( nRed[ i ] );
+ for ( i = 0; i < mnDstColors; i++ ) m_rRAS.ReadUChar( nGreen[ i ] );
+ for ( i = 0; i < mnDstColors; i++ ) m_rRAS.ReadUChar( nBlue[ i ] );
+ for ( i = 0; i < mnDstColors; i++ )
+ {
+ aPalette[i] = Color(nRed[ i ], nGreen[ i ], nBlue[ i ]);
+ }
+ bPalette = true;
+ }
+ else
+ return false;
+
+ }
+ else if ( mnColorMapType != RAS_COLOR_NO_MAP ) // everything else is not standard
+ return false;
+
+ if (!bPalette)
+ {
+ mnDstColors = 1 << mnDstBitsPerPix;
+ aPalette.resize(mnDstColors);
+ for ( sal_uInt16 i = 0; i < mnDstColors; i++ )
+ {
+ sal_uInt8 nCount = 255 - ( 255 * i / ( mnDstColors - 1 ) );
+ aPalette[i] = Color(nCount, nCount, nCount);
+ }
+ }
+ }
+ else
+ {
+ if ( mnColorMapType != RAS_COLOR_NO_MAP ) // when graphic has more than 256 colors and a color map we skip
+ { // the colormap
+ sal_uInt64 nCurPos = m_rRAS.Tell();
+ bOk = checkSeek(m_rRAS, nCurPos + mnColorMapSize);
+ }
+ }
+
+ if (!bOk)
+ return false;
+
+ //The RLE packets are typically three bytes in size:
+ //The first byte is a Flag Value indicating the type of RLE packet.
+ //The second byte is the Run Count.
+ //The third byte is the Run Value.
+ //
+ //for the sake of simplicity we'll assume that RAS_TYPE_BYTE_ENCODED can
+ //describe data 255 times larger than the data stored
+ size_t nMaxCompression = mnType != RAS_TYPE_BYTE_ENCODED ? 1 : 255;
+ sal_Int32 nBitSize;
+ if (o3tl::checked_multiply<sal_Int32>(mnWidth, mnHeight, nBitSize) || o3tl::checked_multiply<sal_Int32>(nBitSize, mnDepth, nBitSize))
+ return false;
+ if (m_rRAS.remainingSize() * nMaxCompression < static_cast<sal_uInt32>(nBitSize) / 8)
+ return false;
+
+ vcl::bitmap::RawBitmap aBmp(Size(mnWidth, mnHeight), 24);
+
+ // read in the bitmap data
+ mbStatus = ImplReadBody(aBmp, aPalette);
+
+ if ( mbStatus )
+ rGraphic = vcl::bitmap::CreateFromData(std::move(aBmp));
+
+ return mbStatus;
+}
+
+bool RASReader::ImplReadHeader()
+{
+ m_rRAS.ReadInt32(mnWidth).ReadInt32(mnHeight).ReadInt32(mnDepth).ReadInt32(mnImageDatSize).ReadInt32(mnType).ReadInt32(mnColorMapType).ReadInt32(mnColorMapSize);
+
+ if (!m_rRAS.good() || mnWidth <= 0 || mnHeight <= 0 || mnImageDatSize <= 0)
+ mbStatus = false;
+
+ switch ( mnDepth )
+ {
+ case 24 :
+ case 8 :
+ case 1 :
+ mnDstBitsPerPix = static_cast<sal_uInt16>(mnDepth);
+ break;
+ case 32 :
+ mnDstBitsPerPix = 24;
+ break;
+
+ default :
+ mbStatus = false;
+ }
+
+ switch ( mnType )
+ {
+ case RAS_TYPE_OLD :
+ case RAS_TYPE_STANDARD :
+ case RAS_TYPE_RGB_FORMAT :
+ case RAS_TYPE_BYTE_ENCODED : // this type will be supported later
+ break;
+
+ default:
+ mbStatus = false;
+ }
+ return mbStatus;
+}
+
+namespace
+{
+ const Color& SanitizePaletteIndex(std::vector<Color> const & rvPalette, sal_uInt8 nIndex)
+ {
+ if (nIndex >= rvPalette.size())
+ {
+ auto nSanitizedIndex = nIndex % rvPalette.size();
+ SAL_WARN_IF(nIndex != nSanitizedIndex, "filter.ras", "invalid colormap index: "
+ << static_cast<unsigned int>(nIndex) << ", colormap len is: "
+ << rvPalette.size());
+ nIndex = nSanitizedIndex;
+ }
+ return rvPalette[nIndex];
+ }
+}
+
+bool RASReader::ImplReadBody(vcl::bitmap::RawBitmap& rBitmap, std::vector<Color> const & rvPalette)
+{
+ sal_Int32 x, y;
+ sal_uInt8 nRed, nGreen, nBlue;
+ switch ( mnDstBitsPerPix )
+ {
+ case 1 :
+ {
+ sal_uInt8 nDat = 0;
+ for (y = 0; y < mnHeight && mbStatus; ++y)
+ {
+ for (x = 0; x < mnWidth && mbStatus; ++x)
+ {
+ if (!(x & 7))
+ {
+ nDat = ImplGetByte();
+ if (!m_rRAS.good())
+ mbStatus = false;
+ }
+ rBitmap.SetPixel(y, x, SanitizePaletteIndex(rvPalette,
+ sal::static_int_cast< sal_uInt8 >(
+ nDat >> ( ( x & 7 ) ^ 7 ))));
+ }
+ if (!( ( x - 1 ) & 0x8 ) )
+ {
+ ImplGetByte(); // WORD ALIGNMENT ???
+ if (!m_rRAS.good())
+ mbStatus = false;
+ }
+ }
+ break;
+ }
+
+ case 8 :
+ for (y = 0; y < mnHeight && mbStatus; ++y)
+ {
+ for (x = 0; x < mnWidth && mbStatus; ++x)
+ {
+ sal_uInt8 nDat = ImplGetByte();
+ rBitmap.SetPixel(y, x, SanitizePaletteIndex(rvPalette, nDat));
+ if (!m_rRAS.good())
+ mbStatus = false;
+ }
+ if ( x & 1 )
+ {
+ ImplGetByte(); // WORD ALIGNMENT ???
+ if (!m_rRAS.good())
+ mbStatus = false;
+ }
+ }
+ break;
+
+ case 24 :
+ switch ( mnDepth )
+ {
+
+ case 24 :
+ for (y = 0; y < mnHeight && mbStatus; ++y)
+ {
+ for (x = 0; x < mnWidth && mbStatus; ++x)
+ {
+ if ( mnType == RAS_TYPE_RGB_FORMAT )
+ {
+ nRed = ImplGetByte();
+ nGreen = ImplGetByte();
+ nBlue = ImplGetByte();
+ }
+ else
+ {
+ nBlue = ImplGetByte();
+ nGreen = ImplGetByte();
+ nRed = ImplGetByte();
+ }
+ rBitmap.SetPixel(y, x, Color(nRed, nGreen, nBlue));
+ if (!m_rRAS.good())
+ mbStatus = false;
+ }
+ if ( x & 1 )
+ {
+ ImplGetByte(); // WORD ALIGNMENT ???
+ if (!m_rRAS.good())
+ mbStatus = false;
+ }
+ }
+ break;
+
+ case 32 :
+ for (y = 0; y < mnHeight && mbStatus; ++y)
+ {
+ for (x = 0; x < mnWidth && mbStatus; ++x)
+ {
+ ImplGetByte(); // pad byte > nil
+ if ( mnType == RAS_TYPE_RGB_FORMAT )
+ {
+ nRed = ImplGetByte();
+ nGreen = ImplGetByte();
+ nBlue = ImplGetByte();
+ }
+ else
+ {
+ nBlue = ImplGetByte();
+ nGreen = ImplGetByte();
+ nRed = ImplGetByte();
+ }
+ rBitmap.SetPixel(y, x, Color(nRed, nGreen, nBlue));
+ if (!m_rRAS.good())
+ mbStatus = false;
+ }
+ }
+ break;
+ }
+ break;
+
+ default:
+ mbStatus = false;
+ break;
+ }
+ return mbStatus;
+}
+
+sal_uInt8 RASReader::ImplGetByte()
+{
+ sal_uInt8 nRetVal;
+ if ( mnType != RAS_TYPE_BYTE_ENCODED )
+ {
+ m_rRAS.ReadUChar( nRetVal );
+ return nRetVal;
+ }
+ else
+ {
+ if ( mnRepCount )
+ {
+ mnRepCount--;
+ return mnRepVal;
+ }
+ else
+ {
+ m_rRAS.ReadUChar( nRetVal );
+ if ( nRetVal != 0x80 )
+ return nRetVal;
+ m_rRAS.ReadUChar( nRetVal );
+ if ( nRetVal == 0 )
+ return 0x80;
+ mnRepCount = nRetVal ;
+ m_rRAS.ReadUChar( mnRepVal );
+ return mnRepVal;
+ }
+ }
+}
+
+//================== GraphicImport - the exported function ================
+
+bool ImportRasGraphic( SvStream & rStream, Graphic & rGraphic)
+{
+ bool bRet = false;
+
+ try
+ {
+ RASReader aRASReader(rStream);
+ bRet = aRASReader.ReadRAS(rGraphic );
+ }
+ catch (...)
+ {
+ }
+
+ return bRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/workben/fftester.cxx b/vcl/workben/fftester.cxx
index a3f5d1d3d4f7..893565e457d3 100644
--- a/vcl/workben/fftester.cxx
+++ b/vcl/workben/fftester.cxx
@@ -46,6 +46,8 @@
#include <filter/TgaReader.hxx>
#include <filter/PictReader.hxx>
#include <filter/MetReader.hxx>
+#include <filter/RasReader.hxx>
+#include <filter/PcxReader.hxx>
#include <osl/file.hxx>
#include <osl/module.hxx>
#include <tools/stream.hxx>
@@ -249,33 +251,15 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
}
else if (strcmp(argv[2], "pcx") == 0)
{
- static PFilterCall pfnImport(nullptr);
- if (!pfnImport)
- {
- osl::Module aLibrary;
- aLibrary.loadRelative(&thisModule, "libgielo.so");
- pfnImport = reinterpret_cast<PFilterCall>(
- aLibrary.getFunctionSymbol("ipxGraphicImport"));
- aLibrary.release();
- }
Graphic aGraphic;
SvFileStream aFileStream(out, StreamMode::READ);
- ret = static_cast<int>((*pfnImport)(aFileStream, aGraphic, nullptr));
+ ret = static_cast<int>(ImportPcxGraphic(aFileStream, aGraphic));
}
else if (strcmp(argv[2], "ras") == 0)
{
- static PFilterCall pfnImport(nullptr);
- if (!pfnImport)
- {
- osl::Module aLibrary;
- aLibrary.loadRelative(&thisModule, "libgielo.so");
- pfnImport = reinterpret_cast<PFilterCall>(
- aLibrary.getFunctionSymbol("iraGraphicImport"));
- aLibrary.release();
- }
Graphic aGraphic;
SvFileStream aFileStream(out, StreamMode::READ);
- ret = static_cast<int>((*pfnImport)(aFileStream, aGraphic, nullptr));
+ ret = static_cast<int>(ImportRasGraphic(aFileStream, aGraphic));
}
else if (strcmp(argv[2], "tga") == 0)
{
diff --git a/vcl/workben/pcxfuzzer.cxx b/vcl/workben/pcxfuzzer.cxx
index e2b72fb7e765..2785cf4c4eec 100644
--- a/vcl/workben/pcxfuzzer.cxx
+++ b/vcl/workben/pcxfuzzer.cxx
@@ -10,6 +10,7 @@
#include <tools/stream.hxx>
#include <vcl/FilterConfigItem.hxx>
#include "commonfuzzer.hxx"
+#include <filter/PcxReader.hxx>
#include <config_features.h>
#include <osl/detail/component-mapping.h>
@@ -39,8 +40,6 @@ extern "C" void* lo_get_custom_widget_func(const char*)
return nullptr;
}
-extern "C" bool ipxGraphicImport(SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem);
-
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
{
TypicalFuzzerInitialize(argc, argv);
@@ -51,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
SvMemoryStream aStream(const_cast<uint8_t*>(data), size, StreamMode::READ);
Graphic aGraphic;
- (void)ipxGraphicImport(aStream, aGraphic, nullptr);
+ (void)ImportPcxGraphic(aStream, aGraphic);
return 0;
}
diff --git a/vcl/workben/rasfuzzer.cxx b/vcl/workben/rasfuzzer.cxx
index 734180b5998b..84678eace5be 100644
--- a/vcl/workben/rasfuzzer.cxx
+++ b/vcl/workben/rasfuzzer.cxx
@@ -10,6 +10,7 @@
#include <tools/stream.hxx>
#include <vcl/FilterConfigItem.hxx>
#include "commonfuzzer.hxx"
+#include <filter/RasReader.hxx>
#include <config_features.h>
#include <osl/detail/component-mapping.h>
@@ -39,8 +40,6 @@ extern "C" void* lo_get_custom_widget_func(const char*)
return nullptr;
}
-extern "C" bool iraGraphicImport(SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem);
-
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
{
TypicalFuzzerInitialize(argc, argv);
@@ -51,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
SvMemoryStream aStream(const_cast<uint8_t*>(data), size, StreamMode::READ);
Graphic aGraphic;
- (void)iraGraphicImport(aStream, aGraphic, nullptr);
+ (void)ImportRasGraphic(aStream, aGraphic);
return 0;
}