From 1093c21ed9736368ecfb8f5c7935db31256671f0 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sun, 14 Feb 2021 23:20:28 +0900 Subject: Move RAS and PCX reader from filter module into VCL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id846abf257b598489a59ebf9b62b19840a950322 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111015 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- filter/CppunitTest_filter_pcx_test.mk | 38 -- filter/CppunitTest_filter_ras_test.mk | 38 -- filter/Library_gie.mk | 2 - filter/Module_filter.mk | 2 - filter/qa/cppunit/data/pcx/fail/.gitignore | 0 .../qa/cppunit/data/pcx/fail/CVE-2007-3741-1.pcx | Bin 41066 -> 0 bytes .../qa/cppunit/data/pcx/fail/CVE-2007-3741-2.pcx | Bin 41136 -> 0 bytes .../qa/cppunit/data/pcx/fail/CVE-2007-3741-3.pcx | Bin 41107 -> 0 bytes .../qa/cppunit/data/pcx/fail/CVE-2008-1097-1.pcx | Bin 91531 -> 0 bytes filter/qa/cppunit/data/pcx/fail/hang-1.pcx | Bin 897 -> 0 bytes .../qa/cppunit/data/pcx/indeterminate/.gitignore | 1 - filter/qa/cppunit/data/pcx/pass/.gitignore | 0 filter/qa/cppunit/data/pcx/pass/rhbz469075-1.pcx | Bin 58596 -> 0 bytes filter/qa/cppunit/data/ras/fail/.gitignore | 0 .../qa/cppunit/data/ras/fail/CVE-2007-2356-1.ras | Bin 4000 -> 0 bytes .../qa/cppunit/data/ras/fail/CVE-2008-1097-1.ras | Bin 92752 -> 0 bytes filter/qa/cppunit/data/ras/fail/crash-1.ras | Bin 913 -> 0 bytes filter/qa/cppunit/data/ras/fail/hang-1.ras | Bin 40 -> 0 bytes .../qa/cppunit/data/ras/indeterminate/.gitignore | 1 - filter/qa/cppunit/data/ras/pass/.gitignore | 0 filter/qa/cppunit/data/ras/pass/marbles.ras | Bin 4262290 -> 0 bytes filter/qa/cppunit/filters-pcx-test.cxx | 67 ---- filter/qa/cppunit/filters-ras-test.cxx | 67 ---- .../internalgraphicfilters/pcx_Import.xcu | 21 +- .../internalgraphicfilters/ras_Import.xcu | 21 +- filter/source/graphicfilter/ipcx/ipcx.cxx | 411 -------------------- filter/source/graphicfilter/iras/iras.cxx | 414 --------------------- include/vcl/graphicfilter.hxx | 4 + solenv/clang-format/excludelist | 12 +- vcl/CppunitTest_vcl_filters_test.mk | 6 +- vcl/Library_vcl.mk | 2 + vcl/inc/filter/PcxReader.hxx | 26 ++ vcl/inc/filter/RasReader.hxx | 26 ++ .../cppunit/graphicfilter/data/pcx/fail/.gitignore | 0 .../data/pcx/fail/CVE-2007-3741-1.pcx | Bin 0 -> 41066 bytes .../data/pcx/fail/CVE-2007-3741-2.pcx | Bin 0 -> 41136 bytes .../data/pcx/fail/CVE-2007-3741-3.pcx | Bin 0 -> 41107 bytes .../data/pcx/fail/CVE-2008-1097-1.pcx | Bin 0 -> 91531 bytes .../cppunit/graphicfilter/data/pcx/fail/hang-1.pcx | Bin 0 -> 897 bytes .../data/pcx/indeterminate/.gitignore | 1 + .../cppunit/graphicfilter/data/pcx/pass/.gitignore | 0 .../graphicfilter/data/pcx/pass/rhbz469075-1.pcx | Bin 0 -> 58596 bytes .../cppunit/graphicfilter/data/ras/fail/.gitignore | 0 .../data/ras/fail/CVE-2007-2356-1.ras | Bin 0 -> 4000 bytes .../data/ras/fail/CVE-2008-1097-1.ras | Bin 0 -> 92752 bytes .../graphicfilter/data/ras/fail/crash-1.ras | Bin 0 -> 913 bytes .../cppunit/graphicfilter/data/ras/fail/hang-1.ras | Bin 0 -> 40 bytes .../data/ras/indeterminate/.gitignore | 1 + .../cppunit/graphicfilter/data/ras/pass/.gitignore | 0 .../graphicfilter/data/ras/pass/marbles.ras | Bin 0 -> 4262290 bytes vcl/qa/cppunit/graphicfilter/filters-pcx-test.cxx | 61 +++ vcl/qa/cppunit/graphicfilter/filters-ras-test.cxx | 61 +++ vcl/source/filter/FilterConfigCache.cxx | 12 +- vcl/source/filter/graphicfilter.cxx | 38 +- vcl/source/filter/ipcx/ipcx.cxx | 411 ++++++++++++++++++++ vcl/source/filter/iras/iras.cxx | 414 +++++++++++++++++++++ vcl/workben/fftester.cxx | 24 +- vcl/workben/pcxfuzzer.cxx | 5 +- vcl/workben/rasfuzzer.cxx | 5 +- 59 files changed, 1079 insertions(+), 1113 deletions(-) delete mode 100644 filter/CppunitTest_filter_pcx_test.mk delete mode 100644 filter/CppunitTest_filter_ras_test.mk delete mode 100644 filter/qa/cppunit/data/pcx/fail/.gitignore delete mode 100644 filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-1.pcx delete mode 100644 filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-2.pcx delete mode 100644 filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-3.pcx delete mode 100644 filter/qa/cppunit/data/pcx/fail/CVE-2008-1097-1.pcx delete mode 100644 filter/qa/cppunit/data/pcx/fail/hang-1.pcx delete mode 100644 filter/qa/cppunit/data/pcx/indeterminate/.gitignore delete mode 100644 filter/qa/cppunit/data/pcx/pass/.gitignore delete mode 100644 filter/qa/cppunit/data/pcx/pass/rhbz469075-1.pcx delete mode 100644 filter/qa/cppunit/data/ras/fail/.gitignore delete mode 100644 filter/qa/cppunit/data/ras/fail/CVE-2007-2356-1.ras delete mode 100644 filter/qa/cppunit/data/ras/fail/CVE-2008-1097-1.ras delete mode 100644 filter/qa/cppunit/data/ras/fail/crash-1.ras delete mode 100644 filter/qa/cppunit/data/ras/fail/hang-1.ras delete mode 100644 filter/qa/cppunit/data/ras/indeterminate/.gitignore delete mode 100644 filter/qa/cppunit/data/ras/pass/.gitignore delete mode 100644 filter/qa/cppunit/data/ras/pass/marbles.ras delete mode 100644 filter/qa/cppunit/filters-pcx-test.cxx delete mode 100644 filter/qa/cppunit/filters-ras-test.cxx delete mode 100644 filter/source/graphicfilter/ipcx/ipcx.cxx delete mode 100644 filter/source/graphicfilter/iras/iras.cxx create mode 100644 vcl/inc/filter/PcxReader.hxx create mode 100644 vcl/inc/filter/RasReader.hxx create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/fail/.gitignore create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-1.pcx create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-2.pcx create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-3.pcx create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2008-1097-1.pcx create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/fail/hang-1.pcx create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/indeterminate/.gitignore create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/pass/.gitignore create mode 100644 vcl/qa/cppunit/graphicfilter/data/pcx/pass/rhbz469075-1.pcx create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/fail/.gitignore create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2007-2356-1.ras create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2008-1097-1.ras create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/fail/crash-1.ras create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/fail/hang-1.ras create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/indeterminate/.gitignore create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/pass/.gitignore create mode 100644 vcl/qa/cppunit/graphicfilter/data/ras/pass/marbles.ras create mode 100644 vcl/qa/cppunit/graphicfilter/filters-pcx-test.cxx create mode 100644 vcl/qa/cppunit/graphicfilter/filters-ras-test.cxx create mode 100644 vcl/source/filter/ipcx/ipcx.cxx create mode 100644 vcl/source/filter/iras/iras.cxx diff --git a/filter/CppunitTest_filter_pcx_test.mk b/filter/CppunitTest_filter_pcx_test.mk deleted file mode 100644 index 12334d75ad42..000000000000 --- a/filter/CppunitTest_filter_pcx_test.mk +++ /dev/null @@ -1,38 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# 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/. -# - -$(eval $(call gb_CppunitTest_CppunitTest,filter_pcx_test)) - -$(eval $(call gb_CppunitTest_use_external,filter_pcx_test,boost_headers)) - -$(eval $(call gb_CppunitTest_add_exception_objects,filter_pcx_test, \ - filter/qa/cppunit/filters-pcx-test \ -)) - -$(eval $(call gb_CppunitTest_use_libraries,filter_pcx_test, \ - gie \ - sal \ - test \ - tl \ - unotest \ - vcl \ -)) - -$(eval $(call gb_CppunitTest_use_sdk_api,filter_pcx_test)) - -$(eval $(call gb_CppunitTest_use_ure,filter_pcx_test)) -$(eval $(call gb_CppunitTest_use_vcl,filter_pcx_test)) - -$(eval $(call gb_CppunitTest_use_components,filter_pcx_test,\ - configmgr/source/configmgr \ -)) - -$(eval $(call gb_CppunitTest_use_configuration,filter_pcx_test)) - -# vim: set noet sw=4 ts=4: diff --git a/filter/CppunitTest_filter_ras_test.mk b/filter/CppunitTest_filter_ras_test.mk deleted file mode 100644 index 50f6852a7b2b..000000000000 --- a/filter/CppunitTest_filter_ras_test.mk +++ /dev/null @@ -1,38 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# 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/. -# - -$(eval $(call gb_CppunitTest_CppunitTest,filter_ras_test)) - -$(eval $(call gb_CppunitTest_use_external,filter_ras_test,boost_headers)) - -$(eval $(call gb_CppunitTest_add_exception_objects,filter_ras_test, \ - filter/qa/cppunit/filters-ras-test \ -)) - -$(eval $(call gb_CppunitTest_use_libraries,filter_ras_test, \ - gie \ - sal \ - test \ - tl \ - unotest \ - vcl \ -)) - -$(eval $(call gb_CppunitTest_use_sdk_api,filter_ras_test)) - -$(eval $(call gb_CppunitTest_use_ure,filter_ras_test)) -$(eval $(call gb_CppunitTest_use_vcl,filter_ras_test)) - -$(eval $(call gb_CppunitTest_use_components,filter_ras_test,\ - configmgr/source/configmgr \ -)) - -$(eval $(call gb_CppunitTest_use_configuration,filter_ras_test)) - -# vim: set noet sw=4 ts=4: diff --git a/filter/Library_gie.mk b/filter/Library_gie.mk index 73120a524ac3..54a1e1fb00db 100644 --- a/filter/Library_gie.mk +++ b/filter/Library_gie.mk @@ -52,8 +52,6 @@ $(eval $(call gb_Library_add_exception_objects,gie,\ filter/source/graphicfilter/egif/egif \ filter/source/graphicfilter/eps/eps \ filter/source/graphicfilter/egif/giflzwc \ - filter/source/graphicfilter/ipcx/ipcx \ - filter/source/graphicfilter/iras/iras \ filter/source/graphicfilter/ieps/ieps \ filter/source/graphicfilter/ipsd/ipsd \ filter/source/graphicfilter/ipbm/ipbm \ diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk index 36ba307c12fb..548e6f27c690 100644 --- a/filter/Module_filter.mk +++ b/filter/Module_filter.mk @@ -58,10 +58,8 @@ $(eval $(call gb_Module_add_check_targets,filter,\ CppunitTest_filter_dxf_test \ CppunitTest_filter_eps_test \ CppunitTest_filter_pcd_test \ - CppunitTest_filter_pcx_test \ CppunitTest_filter_ppm_test \ CppunitTest_filter_psd_test \ - CppunitTest_filter_ras_test \ CppunitTest_filter_svg \ )) endif diff --git a/filter/qa/cppunit/data/pcx/fail/.gitignore b/filter/qa/cppunit/data/pcx/fail/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-1.pcx b/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-1.pcx deleted file mode 100644 index 915f38aec2e3..000000000000 Binary files a/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-1.pcx and /dev/null differ diff --git a/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-2.pcx b/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-2.pcx deleted file mode 100644 index 9c8a751a486d..000000000000 Binary files a/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-2.pcx and /dev/null differ diff --git a/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-3.pcx b/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-3.pcx deleted file mode 100644 index 41175653a4ca..000000000000 Binary files a/filter/qa/cppunit/data/pcx/fail/CVE-2007-3741-3.pcx and /dev/null differ diff --git a/filter/qa/cppunit/data/pcx/fail/CVE-2008-1097-1.pcx b/filter/qa/cppunit/data/pcx/fail/CVE-2008-1097-1.pcx deleted file mode 100644 index c55c64ed9a8a..000000000000 Binary files a/filter/qa/cppunit/data/pcx/fail/CVE-2008-1097-1.pcx and /dev/null differ diff --git a/filter/qa/cppunit/data/pcx/fail/hang-1.pcx b/filter/qa/cppunit/data/pcx/fail/hang-1.pcx deleted file mode 100644 index 73798ea56160..000000000000 Binary files a/filter/qa/cppunit/data/pcx/fail/hang-1.pcx and /dev/null differ diff --git a/filter/qa/cppunit/data/pcx/indeterminate/.gitignore b/filter/qa/cppunit/data/pcx/indeterminate/.gitignore deleted file mode 100644 index f73b09798145..000000000000 --- a/filter/qa/cppunit/data/pcx/indeterminate/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.pcx-* diff --git a/filter/qa/cppunit/data/pcx/pass/.gitignore b/filter/qa/cppunit/data/pcx/pass/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/filter/qa/cppunit/data/pcx/pass/rhbz469075-1.pcx b/filter/qa/cppunit/data/pcx/pass/rhbz469075-1.pcx deleted file mode 100644 index d928c08908ba..000000000000 Binary files a/filter/qa/cppunit/data/pcx/pass/rhbz469075-1.pcx and /dev/null differ diff --git a/filter/qa/cppunit/data/ras/fail/.gitignore b/filter/qa/cppunit/data/ras/fail/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/filter/qa/cppunit/data/ras/fail/CVE-2007-2356-1.ras b/filter/qa/cppunit/data/ras/fail/CVE-2007-2356-1.ras deleted file mode 100644 index c00c27016b57..000000000000 Binary files a/filter/qa/cppunit/data/ras/fail/CVE-2007-2356-1.ras and /dev/null differ diff --git a/filter/qa/cppunit/data/ras/fail/CVE-2008-1097-1.ras b/filter/qa/cppunit/data/ras/fail/CVE-2008-1097-1.ras deleted file mode 100644 index effd654ac5e4..000000000000 Binary files a/filter/qa/cppunit/data/ras/fail/CVE-2008-1097-1.ras and /dev/null differ diff --git a/filter/qa/cppunit/data/ras/fail/crash-1.ras b/filter/qa/cppunit/data/ras/fail/crash-1.ras deleted file mode 100644 index d1abbaefcbae..000000000000 Binary files a/filter/qa/cppunit/data/ras/fail/crash-1.ras and /dev/null differ diff --git a/filter/qa/cppunit/data/ras/fail/hang-1.ras b/filter/qa/cppunit/data/ras/fail/hang-1.ras deleted file mode 100644 index 44dec67607b4..000000000000 Binary files a/filter/qa/cppunit/data/ras/fail/hang-1.ras and /dev/null differ diff --git a/filter/qa/cppunit/data/ras/indeterminate/.gitignore b/filter/qa/cppunit/data/ras/indeterminate/.gitignore deleted file mode 100644 index 60147ad08a9d..000000000000 --- a/filter/qa/cppunit/data/ras/indeterminate/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.ras-* diff --git a/filter/qa/cppunit/data/ras/pass/.gitignore b/filter/qa/cppunit/data/ras/pass/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/filter/qa/cppunit/data/ras/pass/marbles.ras b/filter/qa/cppunit/data/ras/pass/marbles.ras deleted file mode 100644 index 9b3fb0d853b6..000000000000 Binary files a/filter/qa/cppunit/data/ras/pass/marbles.ras and /dev/null differ diff --git a/filter/qa/cppunit/filters-pcx-test.cxx b/filter/qa/cppunit/filters-pcx-test.cxx deleted file mode 100644 index 3a28e24626fa..000000000000 --- a/filter/qa/cppunit/filters-pcx-test.cxx +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- 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 -#include -#include -#include -#include - -extern "C" -{ - SAL_DLLPUBLIC_EXPORT bool SAL_CALL - ipxGraphicImport(SvStream & rStream, Graphic & rGraphic, - FilterConfigItem*); -} - -using namespace ::com::sun::star; - -/* 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 ipxGraphicImport(aFileStream, aGraphic, nullptr); -} - -void PcxFilterTest::testCVEs() -{ - testDir(OUString(), - m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/pcx/")); -} - -CPPUNIT_TEST_SUITE_REGISTRATION(PcxFilterTest); - -CPPUNIT_PLUGIN_IMPLEMENT(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/qa/cppunit/filters-ras-test.cxx b/filter/qa/cppunit/filters-ras-test.cxx deleted file mode 100644 index 2f3b678e4e0a..000000000000 --- a/filter/qa/cppunit/filters-ras-test.cxx +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- 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 -#include -#include -#include -#include - -extern "C" -{ - SAL_DLLPUBLIC_EXPORT bool SAL_CALL - iraGraphicImport(SvStream & rStream, Graphic & rGraphic, - FilterConfigItem*); -} - -using namespace ::com::sun::star; - -/* 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 iraGraphicImport(aFileStream, aGraphic, nullptr); -} - -void RasFilterTest::testCVEs() -{ - testDir(OUString(), - m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/ras/")); -} - -CPPUNIT_TEST_SUITE_REGISTRATION(RasFilterTest); - -CPPUNIT_PLUGIN_IMPLEMENT(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/config/fragments/internalgraphicfilters/pcx_Import.xcu b/filter/source/config/fragments/internalgraphicfilters/pcx_Import.xcu index 4f8eb67340e4..da49344d4e60 100644 --- a/filter/source/config/fragments/internalgraphicfilters/pcx_Import.xcu +++ b/filter/source/config/fragments/internalgraphicfilters/pcx_Import.xcu @@ -15,13 +15,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - - pcx_Zsoft_Paintbrush - ipx - PCX - Zsoft Paintbrush - - - PCX - Zsoft Paintbrush - - IMPORT - + + + pcx_Zsoft_Paintbrush + SVPCX + PCX - Zsoft Paintbrush + + + PCX - Zsoft Paintbrush + + IMPORT + diff --git a/filter/source/config/fragments/internalgraphicfilters/ras_Import.xcu b/filter/source/config/fragments/internalgraphicfilters/ras_Import.xcu index 95108022b03a..7e9a3b2bbc07 100644 --- a/filter/source/config/fragments/internalgraphicfilters/ras_Import.xcu +++ b/filter/source/config/fragments/internalgraphicfilters/ras_Import.xcu @@ -15,13 +15,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - - ras_Sun_Rasterfile - ira - RAS - Sun Rasterfile - - - RAS - Sun Raster Image - - IMPORT - + + + ras_Sun_Rasterfile + SVRAS + RAS - Sun Rasterfile + + + RAS - Sun Raster Image + + IMPORT + diff --git a/filter/source/graphicfilter/ipcx/ipcx.cxx b/filter/source/graphicfilter/ipcx/ipcx.cxx deleted file mode 100644 index 67cbc947fefc..000000000000 --- a/filter/source/graphicfilter/ipcx/ipcx.cxx +++ /dev/null @@ -1,411 +0,0 @@ -/* -*- 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 -#include -#include -#include - -class FilterConfigItem; - -//============================ PCXReader ================================== - -namespace { - -class PCXReader { - -private: - - SvStream& m_rPCX; // the PCX file to read - - std::unique_ptr mpBitmap; - std::vector 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 - 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(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(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 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(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(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 ================ - -extern "C" SAL_DLLPUBLIC_EXPORT bool -ipxGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) -{ - 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/filter/source/graphicfilter/iras/iras.cxx b/filter/source/graphicfilter/iras/iras.cxx deleted file mode 100644 index 5205d6253e22..000000000000 --- a/filter/source/graphicfilter/iras/iras.cxx +++ /dev/null @@ -1,414 +0,0 @@ -/* -*- 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 -#include -#include -#include - -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 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 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( 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(mnWidth, mnHeight, nBitSize) || o3tl::checked_multiply(nBitSize, mnDepth, nBitSize)) - return false; - if (m_rRAS.remainingSize() * nMaxCompression < static_cast(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(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 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(nIndex) << ", colormap len is: " - << rvPalette.size()); - nIndex = nSanitizedIndex; - } - return rvPalette[nIndex]; - } -} - -bool RASReader::ImplReadBody(vcl::bitmap::RawBitmap& rBitmap, std::vector 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 ================ - -extern "C" SAL_DLLPUBLIC_EXPORT bool -iraGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) -{ - bool bRet = false; - - try - { - RASReader aRASReader(rStream); - bRet = aRASReader.ReadRAS(rGraphic ); - } - catch (...) - { - } - - return bRet; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx index 3e7ebd385827..17632d2759a4 100644 --- a/include/vcl/graphicfilter.hxx +++ b/include/vcl/graphicfilter.hxx @@ -82,6 +82,8 @@ namespace o3tl #define IMP_TGA "SVTGA" #define IMP_PICT "SVPICT" #define IMP_MET "SVMET" +#define IMP_RAS "SVRAS" +#define IMP_PCX "SVPCX" #define EXP_BMP "SVBMP" #define EXP_SVMETAFILE "SVMETAFILE" #define EXP_WMF "SVWMF" @@ -366,6 +368,8 @@ public: 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); + static ErrCode readRAS(SvStream & rStream, Graphic & rGraphic); + static ErrCode readPCX(SvStream & rStream, Graphic & rGraphic); private: OUString aFilterPath; diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 7705f0281316..5b288d1687b7 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -3900,10 +3900,8 @@ filter/inc/strings.hxx filter/qa/cppunit/filters-dxf-test.cxx filter/qa/cppunit/filters-eps-test.cxx filter/qa/cppunit/filters-pcd-test.cxx -filter/qa/cppunit/filters-pcx-test.cxx filter/qa/cppunit/filters-ppm-test.cxx filter/qa/cppunit/filters-psd-test.cxx -filter/qa/cppunit/filters-ras-test.cxx filter/qa/cppunit/msfilter-test.cxx filter/qa/cppunit/priority-test.cxx filter/qa/cppunit/xslt-test.cxx @@ -3973,9 +3971,7 @@ filter/source/graphicfilter/idxf/idxf.cxx filter/source/graphicfilter/ieps/ieps.cxx filter/source/graphicfilter/ipbm/ipbm.cxx filter/source/graphicfilter/ipcd/ipcd.cxx -filter/source/graphicfilter/ipcx/ipcx.cxx filter/source/graphicfilter/ipsd/ipsd.cxx -filter/source/graphicfilter/iras/iras.cxx filter/source/msfilter/countryid.cxx filter/source/msfilter/dffpropset.cxx filter/source/msfilter/escherex.cxx @@ -14819,10 +14815,12 @@ vcl/qa/cppunit/dndtest.cxx vcl/qa/cppunit/errorhandler.cxx vcl/qa/cppunit/font.cxx vcl/qa/cppunit/fontmetric.cxx +vcl/qa/cppunit/graphicfilter/filters-met-test.cxx +vcl/qa/cppunit/graphicfilter/filters-pcx-test.cxx +vcl/qa/cppunit/graphicfilter/filters-pict-test.cxx +vcl/qa/cppunit/graphicfilter/filters-ras-test.cxx vcl/qa/cppunit/graphicfilter/filters-test.cxx vcl/qa/cppunit/graphicfilter/filters-tga-test.cxx -vcl/qa/cppunit/graphicfilter/filters-pict-test.cxx -vcl/qa/cppunit/graphicfilter/filters-met-test.cxx vcl/qa/cppunit/lifecycle.cxx vcl/qa/cppunit/svm/svmtest.cxx vcl/qa/cppunit/timer.cxx @@ -14932,9 +14930,11 @@ vcl/source/filter/igif/decode.cxx vcl/source/filter/igif/decode.hxx vcl/source/filter/igif/gifread.cxx vcl/source/filter/imet/ios2met.cxx +vcl/source/filter/ipcx/ipcx.cxx vcl/source/filter/ipict/ipict.cxx vcl/source/filter/ipict/shape.cxx vcl/source/filter/ipict/shape.hxx +vcl/source/filter/iras/iras.cxx vcl/source/filter/ixbm/xbmread.cxx vcl/source/filter/ixpm/rgbtable.hxx vcl/source/filter/ixpm/xpmread.cxx 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_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_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 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-1.pcx 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-2.pcx 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2007-3741-3.pcx 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/CVE-2008-1097-1.pcx 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/pcx/fail/hang-1.pcx 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 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/pcx/pass/rhbz469075-1.pcx 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 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2007-2356-1.ras 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/ras/fail/CVE-2008-1097-1.ras 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/ras/fail/crash-1.ras 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/ras/fail/hang-1.ras 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 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 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/ras/pass/marbles.ras 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 +#include +#include +#include +#include +#include + +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 +#include +#include +#include +#include +#include + +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 #include #include +#include +#include #include #include #include @@ -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(maLibrary.getFunctionSymbol("ipdGraphicImport")); else if (maFormatName == "ips") mpfnImport = reinterpret_cast(maLibrary.getFunctionSymbol("ipsGraphicImport")); - else if (maFormatName == "ipx") - mpfnImport = reinterpret_cast(maLibrary.getFunctionSymbol("ipxGraphicImport")); - else if (maFormatName == "ira") - mpfnImport = reinterpret_cast(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 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 +#include +#include +#include +#include + +class FilterConfigItem; + +//============================ PCXReader ================================== + +namespace { + +class PCXReader { + +private: + + SvStream& m_rPCX; // the PCX file to read + + std::unique_ptr mpBitmap; + std::vector 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 + 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(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(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 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(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(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 +#include +#include +#include +#include + +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 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 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( 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(mnWidth, mnHeight, nBitSize) || o3tl::checked_multiply(nBitSize, mnDepth, nBitSize)) + return false; + if (m_rRAS.remainingSize() * nMaxCompression < static_cast(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(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 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(nIndex) << ", colormap len is: " + << rvPalette.size()); + nIndex = nSanitizedIndex; + } + return rvPalette[nIndex]; + } +} + +bool RASReader::ImplReadBody(vcl::bitmap::RawBitmap& rBitmap, std::vector 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 #include #include +#include +#include #include #include #include @@ -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( - aLibrary.getFunctionSymbol("ipxGraphicImport")); - aLibrary.release(); - } Graphic aGraphic; SvFileStream aFileStream(out, StreamMode::READ); - ret = static_cast((*pfnImport)(aFileStream, aGraphic, nullptr)); + ret = static_cast(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( - aLibrary.getFunctionSymbol("iraGraphicImport")); - aLibrary.release(); - } Graphic aGraphic; SvFileStream aFileStream(out, StreamMode::READ); - ret = static_cast((*pfnImport)(aFileStream, aGraphic, nullptr)); + ret = static_cast(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 #include #include "commonfuzzer.hxx" +#include #include #include @@ -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(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 #include #include "commonfuzzer.hxx" +#include #include #include @@ -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(data), size, StreamMode::READ); Graphic aGraphic; - (void)iraGraphicImport(aStream, aGraphic, nullptr); + (void)ImportRasGraphic(aStream, aGraphic); return 0; } -- cgit