diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-02-15 10:47:14 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-02-17 05:55:07 +0100 |
commit | 27078ce8cb03f6ba61be5ce75c5231bc8798d6fe (patch) | |
tree | b4ef200aef196b2f773ffaa744658326a39569f2 /filter | |
parent | 68012eaaab9968f6ccfdfc018bcc5befa36a7a2f (diff) |
Move PBM,PPM reader from filter module into VCL
Change-Id: I1ce998575f8d204045fabea184e80e71308a16b8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111019
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'filter')
19 files changed, 33 insertions, 689 deletions
diff --git a/filter/CppunitTest_filter_ppm_test.mk b/filter/CppunitTest_filter_ppm_test.mk deleted file mode 100644 index 273db952300d..000000000000 --- a/filter/CppunitTest_filter_ppm_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_ppm_test)) - -$(eval $(call gb_CppunitTest_use_external,filter_ppm_test,boost_headers)) - -$(eval $(call gb_CppunitTest_add_exception_objects,filter_ppm_test, \ - filter/qa/cppunit/filters-ppm-test \ -)) - -$(eval $(call gb_CppunitTest_use_libraries,filter_ppm_test, \ - gie \ - sal \ - test \ - tl \ - unotest \ - vcl \ -)) - -$(eval $(call gb_CppunitTest_use_sdk_api,filter_ppm_test)) - -$(eval $(call gb_CppunitTest_use_ure,filter_ppm_test)) -$(eval $(call gb_CppunitTest_use_vcl,filter_ppm_test)) - -$(eval $(call gb_CppunitTest_use_components,filter_ppm_test,\ - configmgr/source/configmgr \ -)) - -$(eval $(call gb_CppunitTest_use_configuration,filter_ppm_test)) - -# vim: set noet sw=4 ts=4: diff --git a/filter/Library_gie.mk b/filter/Library_gie.mk index d5ab8b8169a5..e04eb08fda7f 100644 --- a/filter/Library_gie.mk +++ b/filter/Library_gie.mk @@ -51,7 +51,6 @@ $(eval $(call gb_Library_use_libraries,gie,\ $(eval $(call gb_Library_add_exception_objects,gie,\ filter/source/graphicfilter/egif/egif \ filter/source/graphicfilter/egif/giflzwc \ - filter/source/graphicfilter/ipbm/ipbm \ filter/source/graphicfilter/idxf/dxf2mtf \ filter/source/graphicfilter/idxf/dxfblkrd \ filter/source/graphicfilter/idxf/dxfentrd \ diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk index 678c882dce88..607a5fc46d0c 100644 --- a/filter/Module_filter.mk +++ b/filter/Module_filter.mk @@ -56,7 +56,6 @@ $(eval $(call gb_Module_add_check_targets,filter,\ ifneq ($(DISABLE_CVE_TESTS),TRUE) $(eval $(call gb_Module_add_check_targets,filter,\ CppunitTest_filter_dxf_test \ - CppunitTest_filter_ppm_test \ CppunitTest_filter_svg \ )) endif diff --git a/filter/qa/cppunit/data/pbm/fail/.gitignore b/filter/qa/cppunit/data/pbm/fail/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 --- a/filter/qa/cppunit/data/pbm/fail/.gitignore +++ /dev/null diff --git a/filter/qa/cppunit/data/pbm/fail/crash-1.pbm b/filter/qa/cppunit/data/pbm/fail/crash-1.pbm deleted file mode 100644 index 9ddcddfe669c..000000000000 --- a/filter/qa/cppunit/data/pbm/fail/crash-1.pbm +++ /dev/null @@ -1,6 +0,0 @@ -P3 -30000000000000000000000000000000 1 -255 -103 79 59 - 95 7P 55 - 87 67 51 diff --git a/filter/qa/cppunit/data/pbm/fail/hang-1.pbm b/filter/qa/cppunit/data/pbm/fail/hang-1.pbm Binary files differdeleted file mode 100644 index 21742d204c79..000000000000 --- a/filter/qa/cppunit/data/pbm/fail/hang-1.pbm +++ /dev/null diff --git a/filter/qa/cppunit/data/pbm/indeterminate/.gitignore b/filter/qa/cppunit/data/pbm/indeterminate/.gitignore deleted file mode 100644 index e9c5b1765b8f..000000000000 --- a/filter/qa/cppunit/data/pbm/indeterminate/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.ppm-* diff --git a/filter/qa/cppunit/data/pbm/pass/.gitignore b/filter/qa/cppunit/data/pbm/pass/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 --- a/filter/qa/cppunit/data/pbm/pass/.gitignore +++ /dev/null diff --git a/filter/qa/cppunit/data/pbm/pass/rhbz160429-1.pbm b/filter/qa/cppunit/data/pbm/pass/rhbz160429-1.pbm Binary files differdeleted file mode 100644 index d6e3fc6349b8..000000000000 --- a/filter/qa/cppunit/data/pbm/pass/rhbz160429-1.pbm +++ /dev/null diff --git a/filter/qa/cppunit/data/ppm/fail/.gitignore b/filter/qa/cppunit/data/ppm/fail/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 --- a/filter/qa/cppunit/data/ppm/fail/.gitignore +++ /dev/null diff --git a/filter/qa/cppunit/data/ppm/fail/CVE-2008-1097-1.ppm b/filter/qa/cppunit/data/ppm/fail/CVE-2008-1097-1.ppm Binary files differdeleted file mode 100644 index 457289577df7..000000000000 --- a/filter/qa/cppunit/data/ppm/fail/CVE-2008-1097-1.ppm +++ /dev/null diff --git a/filter/qa/cppunit/data/ppm/indeterminate/.gitignore b/filter/qa/cppunit/data/ppm/indeterminate/.gitignore deleted file mode 100644 index e9c5b1765b8f..000000000000 --- a/filter/qa/cppunit/data/ppm/indeterminate/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.ppm-* diff --git a/filter/qa/cppunit/data/ppm/pass/.gitignore b/filter/qa/cppunit/data/ppm/pass/.gitignore deleted file mode 100644 index e69de29bb2d1..000000000000 --- a/filter/qa/cppunit/data/ppm/pass/.gitignore +++ /dev/null diff --git a/filter/qa/cppunit/data/ppm/pass/fdo19811-2.ppm b/filter/qa/cppunit/data/ppm/pass/fdo19811-2.ppm Binary files differdeleted file mode 100644 index 828b9725693e..000000000000 --- a/filter/qa/cppunit/data/ppm/pass/fdo19811-2.ppm +++ /dev/null diff --git a/filter/qa/cppunit/filters-ppm-test.cxx b/filter/qa/cppunit/filters-ppm-test.cxx deleted file mode 100644 index 43ae966a0c57..000000000000 --- a/filter/qa/cppunit/filters-ppm-test.cxx +++ /dev/null @@ -1,70 +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 <unotest/filters-test.hxx> -#include <test/bootstrapfixture.hxx> -#include <vcl/FilterConfigItem.hxx> -#include <tools/stream.hxx> -#include <vcl/graph.hxx> - -extern "C" -{ - SAL_DLLPUBLIC_EXPORT bool SAL_CALL - ipbGraphicImport(SvStream & rStream, Graphic & rGraphic, - FilterConfigItem*); -} - -using namespace ::com::sun::star; - -/* Implementation of Filters test */ - -class PpmFilterTest - : public test::FiltersTest - , public test::BootstrapFixture -{ -public: - PpmFilterTest() : 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(PpmFilterTest); - CPPUNIT_TEST(testCVEs); - CPPUNIT_TEST_SUITE_END(); -}; - -bool PpmFilterTest::load(const OUString &, - const OUString &rURL, const OUString &, - SfxFilterFlags, SotClipboardFormatId, unsigned int) -{ - SvFileStream aFileStream(rURL, StreamMode::READ); - Graphic aGraphic; - return ipbGraphicImport(aFileStream, aGraphic, nullptr); -} - -void PpmFilterTest::testCVEs() -{ - testDir(OUString(), - m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/ppm/")); - - testDir(OUString(), - m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/pbm/")); -} - -CPPUNIT_TEST_SUITE_REGISTRATION(PpmFilterTest); - -CPPUNIT_PLUGIN_IMPLEMENT(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/config/fragments/internalgraphicfilters/pbm_Import.xcu b/filter/source/config/fragments/internalgraphicfilters/pbm_Import.xcu index 49db4b3c7eb4..0e7f0b9402b5 100644 --- a/filter/source/config/fragments/internalgraphicfilters/pbm_Import.xcu +++ b/filter/source/config/fragments/internalgraphicfilters/pbm_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 . --> - <node oor:name="pbm_Import" oor:op="replace" > - <prop oor:name="Type"><value>pbm_Portable_Bitmap</value></prop> - <prop oor:name="FormatName"><value>ipb</value></prop> - <prop oor:name="RealFilterName"><value>PBM - Portable Bitmap</value></prop> - <prop oor:name="UIComponent"/> - <prop oor:name="UIName"> - <value xml:lang="en-US">PBM - Portable Bitmap</value> - </prop> - <prop oor:name="Flags"><value>IMPORT</value></prop> - </node> + +<node oor:name="pbm_Import" oor:op="replace" > + <prop oor:name="Type"><value>pbm_Portable_Bitmap</value></prop> + <prop oor:name="FormatName"><value>SVPBM</value></prop> + <prop oor:name="RealFilterName"><value>PBM - Portable Bitmap</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UIName"> + <value xml:lang="en-US">PBM - Portable Bitmap</value> + </prop> + <prop oor:name="Flags"><value>IMPORT</value></prop> +</node> diff --git a/filter/source/config/fragments/internalgraphicfilters/pgm_Import.xcu b/filter/source/config/fragments/internalgraphicfilters/pgm_Import.xcu index 2e1d4bb27f68..0356e69543f5 100644 --- a/filter/source/config/fragments/internalgraphicfilters/pgm_Import.xcu +++ b/filter/source/config/fragments/internalgraphicfilters/pgm_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 . --> - <node oor:name="pgm_Import" oor:op="replace" > - <prop oor:name="Type"><value>pgm_Portable_Graymap</value></prop> - <prop oor:name="FormatName"><value>ipb</value></prop> - <prop oor:name="RealFilterName"><value>PGM - Portable Graymap</value></prop> - <prop oor:name="UIComponent"/> - <prop oor:name="UIName"> - <value xml:lang="en-US">PGM - Portable Graymap</value> - </prop> - <prop oor:name="Flags"><value>IMPORT</value></prop> - </node> + +<node oor:name="pgm_Import" oor:op="replace" > + <prop oor:name="Type"><value>pgm_Portable_Graymap</value></prop> + <prop oor:name="FormatName"><value>SVPBM</value></prop> + <prop oor:name="RealFilterName"><value>PGM - Portable Graymap</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UIName"> + <value xml:lang="en-US">PGM - Portable Graymap</value> + </prop> + <prop oor:name="Flags"><value>IMPORT</value></prop> +</node> diff --git a/filter/source/config/fragments/internalgraphicfilters/ppm_Import.xcu b/filter/source/config/fragments/internalgraphicfilters/ppm_Import.xcu index c2213e24f8bc..03134558c806 100644 --- a/filter/source/config/fragments/internalgraphicfilters/ppm_Import.xcu +++ b/filter/source/config/fragments/internalgraphicfilters/ppm_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 . --> - <node oor:name="ppm_Import" oor:op="replace" > - <prop oor:name="Type"><value>ppm_Portable_Pixelmap</value></prop> - <prop oor:name="FormatName"><value>ipb</value></prop> - <prop oor:name="RealFilterName"><value>PPM - Portable Pixelmap</value></prop> - <prop oor:name="UIComponent"/> - <prop oor:name="UIName"> - <value xml:lang="en-US">PPM - Portable Pixelmap</value> - </prop> - <prop oor:name="Flags"><value>IMPORT</value></prop> - </node> + +<node oor:name="ppm_Import" oor:op="replace" > + <prop oor:name="Type"><value>ppm_Portable_Pixelmap</value></prop> + <prop oor:name="FormatName"><value>SVPBM</value></prop> + <prop oor:name="RealFilterName"><value>PPM - Portable Pixelmap</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UIName"> + <value xml:lang="en-US">PPM - Portable Pixelmap</value> + </prop> + <prop oor:name="Flags"><value>IMPORT</value></prop> +</node> diff --git a/filter/source/graphicfilter/ipbm/ipbm.cxx b/filter/source/graphicfilter/ipbm/ipbm.cxx deleted file mode 100644 index 4c12c18523fd..000000000000 --- a/filter/source/graphicfilter/ipbm/ipbm.cxx +++ /dev/null @@ -1,541 +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 <sal/config.h> -#include <o3tl/safeint.hxx> -#include <vcl/FilterConfigItem.hxx> -#include <vcl/graph.hxx> -#include <vcl/BitmapTools.hxx> -#include <tools/stream.hxx> - -//============================ PBMReader ================================== - -namespace { - -class PBMReader { - -private: - - SvStream& mrPBM; // the PBM file to read - - bool mbStatus; - bool mbRemark; // sal_False if the stream is in a comment - bool mbRaw; // RAW/ASCII MODE - sal_uInt8 mnMode; // 0->PBM, 1->PGM, 2->PPM - std::unique_ptr<vcl::bitmap::RawBitmap> mpRawBmp; - std::vector<Color> mvPalette; - sal_Int32 mnWidth, mnHeight; // dimensions in pixel - sal_uInt16 mnCol; - sal_uInt64 mnMaxVal; // max value in the <missing comment> - bool ImplReadBody(); - bool ImplReadHeader(); - -public: - explicit PBMReader(SvStream & rPBM); - bool ReadPBM(Graphic & rGraphic ); -}; - -} - -//=================== Methods of PBMReader ============================== - -PBMReader::PBMReader(SvStream & rPBM) - : mrPBM(rPBM) - , mbStatus(true) - , mbRemark(false) - , mbRaw(true) - , mnMode(0) - , mnWidth(0) - , mnHeight(0) - , mnCol(0) - , mnMaxVal(0) -{ -} - -bool PBMReader::ReadPBM(Graphic & rGraphic ) -{ - if ( mrPBM.GetError() ) - return false; - - mrPBM.SetEndian( SvStreamEndian::LITTLE ); - - // read header: - - mbStatus = ImplReadHeader(); - if ( !mbStatus ) - return false; - - if ( ( mnMaxVal == 0 ) || ( mnWidth <= 0 ) || ( mnHeight <= 0 ) ) - return false; - - sal_uInt32 nPixelsRequired; - if (o3tl::checked_multiply<sal_uInt32>(mnWidth, mnHeight, nPixelsRequired)) - return false; - const auto nRemainingSize = mrPBM.remainingSize(); - - // 0->PBM, 1->PGM, 2->PPM - switch ( mnMode ) - { - case 0: - { - if (nRemainingSize < nPixelsRequired / 8) - return false; - - mpRawBmp.reset( new vcl::bitmap::RawBitmap( Size( mnWidth, mnHeight ), 24 ) ); - mvPalette.resize( 2 ); - mvPalette[0] = Color( 0xff, 0xff, 0xff ); - mvPalette[1] = Color( 0x00, 0x00, 0x00 ); - break; - } - case 1 : - if (nRemainingSize < nPixelsRequired) - return false; - - mpRawBmp.reset( new vcl::bitmap::RawBitmap( Size( mnWidth, mnHeight ), 24 ) ); - mnCol = static_cast<sal_uInt16>(mnMaxVal) + 1; - if ( mnCol > 256 ) - mnCol = 256; - - mvPalette.resize( 256 ); - for ( sal_uInt16 i = 0; i < mnCol; i++ ) - { - sal_uInt16 nCount = 255 * i / mnCol; - mvPalette[i] = Color( static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount) ); - } - break; - case 2 : - if (nRemainingSize / 3 < nPixelsRequired) - return false; - - mpRawBmp.reset( new vcl::bitmap::RawBitmap( Size( mnWidth, mnHeight ), 24 ) ); - break; - } - - // read bitmap data - mbStatus = ImplReadBody(); - - if ( mbStatus ) - rGraphic = vcl::bitmap::CreateFromData(std::move(*mpRawBmp)); - - return mbStatus; -} - -bool PBMReader::ImplReadHeader() -{ - sal_uInt8 nID[ 2 ]; - sal_uInt8 nDat; - sal_uInt8 nMax, nCount = 0; - bool bFinished = false; - - mrPBM.ReadUChar( nID[ 0 ] ).ReadUChar( nID[ 1 ] ); - if ( nID[ 0 ] != 'P' ) - return false; - mnMaxVal = mnWidth = mnHeight = 0; - switch ( nID[ 1 ] ) - { - case '1' : - mbRaw = false; - [[fallthrough]]; - case '4' : - mnMode = 0; - nMax = 2; // number of parameters in Header - mnMaxVal = 1; - break; - case '2' : - mbRaw = false; - [[fallthrough]]; - case '5' : - mnMode = 1; - nMax = 3; - break; - case '3' : - mbRaw = false; - [[fallthrough]]; - case '6' : - mnMode = 2; - nMax = 3; - break; - default: - return false; - } - while ( !bFinished ) - { - if (!mrPBM.good()) - return false; - - mrPBM.ReadUChar( nDat ); - - if ( nDat == '#' ) - { - mbRemark = true; - continue; - } - else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) ) - { - mbRemark = false; - nDat = 0x20; - } - if ( mbRemark ) - continue; - - if ( ( nDat == 0x20 ) || ( nDat == 0x09 ) ) - { - if ( ( nCount == 0 ) && mnWidth ) - nCount++; - else if ( ( nCount == 1 ) && mnHeight ) - { - if ( ++nCount == nMax ) - bFinished = true; - } - else if ( ( nCount == 2 ) && mnMaxVal ) - { - bFinished = true; - } - continue; - } - if ( ( nDat >= '0' ) && ( nDat <= '9' ) ) - { - nDat -= '0'; - if ( nCount == 0 ) - { - if (mnWidth > SAL_MAX_INT32 / 10) - { - return false; - } - mnWidth *= 10; - if (nDat > SAL_MAX_INT32 - mnWidth) - { - return false; - } - mnWidth += nDat; - } - else if ( nCount == 1 ) - { - if (mnHeight > SAL_MAX_INT32 / 10) - { - return false; - } - mnHeight *= 10; - if (nDat > SAL_MAX_INT32 - mnHeight) - { - return false; - } - mnHeight += nDat; - } - else if ( nCount == 2 ) - { - if (mnMaxVal > std::numeric_limits<sal_uInt64>::max() / 10) - { - return false; - } - mnMaxVal *= 10; - if (nDat > std::numeric_limits<sal_uInt64>::max() - mnMaxVal) - { - return false; - } - mnMaxVal += nDat; - } - } - else - return false; - } - return mbStatus; -} - -bool PBMReader::ImplReadBody() -{ - sal_uInt8 nDat = 0, nCount; - sal_uInt64 nGrey, nRGB[3]; - sal_Int32 nWidth = 0; - sal_Int32 nHeight = 0; - - if ( mbRaw ) - { - signed char nShift = 0; - switch ( mnMode ) - { - - // PBM - case 0 : - while ( nHeight != mnHeight ) - { - if (!mrPBM.good()) - return false; - - if ( --nShift < 0 ) - { - mrPBM.ReadUChar( nDat ); - nShift = 7; - } - mpRawBmp->SetPixel( nHeight, nWidth, mvPalette[(nDat >> nShift) & 0x01] ); - if ( ++nWidth == mnWidth ) - { - nShift = 0; - nWidth = 0; - nHeight++; - } - } - break; - - // PGM - case 1 : - while ( nHeight != mnHeight ) - { - if (!mrPBM.good()) - return false; - - mrPBM.ReadUChar( nDat ); - mpRawBmp->SetPixel( nHeight, nWidth++, mvPalette[nDat]); - - if ( nWidth == mnWidth ) - { - nWidth = 0; - nHeight++; - } - } - break; - - // PPM - case 2 : - while ( nHeight != mnHeight ) - { - if (!mrPBM.good()) - return false; - - sal_uInt8 nR, nG, nB; - sal_uInt8 nRed, nGreen, nBlue; - mrPBM.ReadUChar( nR ).ReadUChar( nG ).ReadUChar( nB ); - nRed = 255 * nR / mnMaxVal; - nGreen = 255 * nG / mnMaxVal; - nBlue = 255 * nB / mnMaxVal; - mpRawBmp->SetPixel( nHeight, nWidth++, Color( nRed, nGreen, nBlue ) ); - if ( nWidth == mnWidth ) - { - nWidth = 0; - nHeight++; - } - } - break; - } - } - else - { - bool bPara = false; - bool bFinished = false; - - switch ( mnMode ) - { - // PBM - case 0 : - while ( !bFinished ) - { - if (!mrPBM.good()) - return false; - - mrPBM.ReadUChar( nDat ); - - if ( nDat == '#' ) - { - mbRemark = true; - continue; - } - else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) ) - { - mbRemark = false; - continue; - } - if ( mbRemark || nDat == 0x20 || nDat == 0x09 ) - continue; - - if ( nDat == '0' || nDat == '1' ) - { - mpRawBmp->SetPixel( nHeight, nWidth, mvPalette[static_cast<sal_uInt8>(nDat - '0')] ); - nWidth++; - if ( nWidth == mnWidth ) - { - nWidth = 0; - if ( ++nHeight == mnHeight ) - bFinished = true; - } - } - else - return false; - } - break; - - // PGM - case 1 : - - bPara = false; - nCount = 0; - nGrey = 0; - - while ( !bFinished ) - { - if ( nCount ) - { - nCount--; - if ( nGrey <= mnMaxVal ) - nGrey = 255 * nGrey / mnMaxVal; - mpRawBmp->SetPixel( nHeight, nWidth++, mvPalette[static_cast<sal_uInt8>(nGrey)] ); - nGrey = 0; - if ( nWidth == mnWidth ) - { - nWidth = 0; - if ( ++nHeight == mnHeight ) - bFinished = true; - } - continue; - } - - if (!mrPBM.good()) - return false; - - mrPBM.ReadUChar( nDat ); - - if ( nDat == '#' ) - { - mbRemark = true; - if ( bPara ) - { - bPara = false; - nCount++; - } - continue; - } - else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) ) - { - mbRemark = false; - if ( bPara ) - { - bPara = false; - nCount++; - } - continue; - } - - if ( nDat == 0x20 || nDat == 0x09 ) - { - if ( bPara ) - { - bPara = false; - nCount++; - } - continue; - } - if ( nDat >= '0' && nDat <= '9' ) - { - bPara = true; - nGrey *= 10; - nGrey += nDat-'0'; - continue; - } - else - return false; - } - break; - - - // PPM - case 2 : - - bPara = false; - nCount = 0; - nRGB[ 0 ] = nRGB[ 1 ] = nRGB[ 2 ] = 0; - - while ( !bFinished ) - { - if ( nCount == 3 ) - { - nCount = 0; - mpRawBmp->SetPixel( nHeight, nWidth++, Color( static_cast< sal_uInt8 >( ( nRGB[ 0 ] * 255 ) / mnMaxVal ), - static_cast< sal_uInt8 >( ( nRGB[ 1 ] * 255 ) / mnMaxVal ), - static_cast< sal_uInt8 >( ( nRGB[ 2 ] * 255 ) / mnMaxVal ) ) ); - nRGB[ 0 ] = nRGB[ 1 ] = nRGB[ 2 ] = 0; - if ( nWidth == mnWidth ) - { - nWidth = 0; - if ( ++nHeight == mnHeight ) - bFinished = true; - } - continue; - } - - if (!mrPBM.good()) - return false; - - mrPBM.ReadUChar( nDat ); - - if ( nDat == '#' ) - { - mbRemark = true; - if ( bPara ) - { - bPara = false; - nCount++; - } - continue; - } - else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) ) - { - mbRemark = false; - if ( bPara ) - { - bPara = false; - nCount++; - } - continue; - } - - if ( nDat == 0x20 || nDat == 0x09 ) - { - if ( bPara ) - { - bPara = false; - nCount++; - } - continue; - } - if ( nDat >= '0' && nDat <= '9' ) - { - bPara = true; - nRGB[ nCount ] *= 10; - nRGB[ nCount ] += nDat-'0'; - continue; - } - else - return false; - } - break; - } - } - return mbStatus; -} - -//================== GraphicImport - the exported function ================ - -extern "C" SAL_DLLPUBLIC_EXPORT bool -ipbGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) -{ - PBMReader aPBMReader(rStream); - - return aPBMReader.ReadPBM(rGraphic ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |