diff options
Diffstat (limited to 'filter/source/graphicfilter/epbm')
-rw-r--r-- | filter/source/graphicfilter/epbm/epbm.cxx | 214 | ||||
-rw-r--r-- | filter/source/graphicfilter/epbm/exports.map | 7 | ||||
-rw-r--r-- | filter/source/graphicfilter/epbm/makefile.mk | 69 |
3 files changed, 290 insertions, 0 deletions
diff --git a/filter/source/graphicfilter/epbm/epbm.cxx b/filter/source/graphicfilter/epbm/epbm.cxx new file mode 100644 index 000000000000..b4f5b9b680ce --- /dev/null +++ b/filter/source/graphicfilter/epbm/epbm.cxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" + +#include <vcl/svapp.hxx> +#include <vcl/graph.hxx> +#include <vcl/bmpacc.hxx> +#include <vcl/msgbox.hxx> +#include <svl/solar.hrc> +#include <svtools/fltcall.hxx> +#include <svtools/FilterConfigItem.hxx> + +//============================ PBMWriter ================================== + +class PBMWriter { + +private: + + SvStream* mpOStm; // Die auszugebende PBM-Datei + USHORT mpOStmOldModus; + + BOOL mbStatus; + sal_Int32 mnMode; // 0 -> raw, 1-> ascii + BitmapReadAccess* mpAcc; + ULONG mnWidth, mnHeight; // Bildausmass in Pixeln + + BOOL ImplWriteHeader(); + void ImplWriteBody(); + void ImplWriteNumber( sal_Int32 ); + + com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator; + +public: + PBMWriter(); + ~PBMWriter(); + + BOOL WritePBM( const Graphic& rGraphic, SvStream& rPBM, FilterConfigItem* pFilterConfigItem ); +}; + +//=================== Methoden von PBMWriter ============================== + +PBMWriter::PBMWriter() : + mbStatus ( TRUE ), + mpAcc ( NULL ) +{ +} + +// ------------------------------------------------------------------------ + +PBMWriter::~PBMWriter() +{ +} + +// ------------------------------------------------------------------------ + +BOOL PBMWriter::WritePBM( const Graphic& rGraphic, SvStream& rPBM, FilterConfigItem* pFilterConfigItem ) +{ + + mpOStm = &rPBM; + + if ( pFilterConfigItem ) + { + mnMode = pFilterConfigItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FileFormat" ) ), 0 ); + + xStatusIndicator = pFilterConfigItem->GetStatusIndicator(); + if ( xStatusIndicator.is() ) + { + rtl::OUString aMsg; + xStatusIndicator->start( aMsg, 100 ); + } + } + + BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); + Bitmap aBmp = aBmpEx.GetBitmap(); + aBmp.Convert( BMP_CONVERSION_1BIT_THRESHOLD ); + + mpOStmOldModus = mpOStm->GetNumberFormatInt(); + mpOStm->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); + + mpAcc = aBmp.AcquireReadAccess(); + if( mpAcc ) + { + if ( ImplWriteHeader() ) + ImplWriteBody(); + + aBmp.ReleaseAccess( mpAcc ); + } + else + mbStatus = FALSE; + + mpOStm->SetNumberFormatInt( mpOStmOldModus ); + + if ( xStatusIndicator.is() ) + xStatusIndicator->end(); + + return mbStatus; +} + +// ------------------------------------------------------------------------ + +BOOL PBMWriter::ImplWriteHeader() +{ + mnWidth = mpAcc->Width(); + mnHeight = mpAcc->Height(); + if ( mnWidth && mnHeight ) + { + if ( mnMode == 0 ) + *mpOStm << "P4\x0a"; + else + *mpOStm << "P1\x0a"; + + ImplWriteNumber( mnWidth ); + *mpOStm << (BYTE)32; + ImplWriteNumber( mnHeight ); + *mpOStm << (BYTE)10; + } + else mbStatus = FALSE; + return mbStatus; +} + +// ------------------------------------------------------------------------ + +void PBMWriter::ImplWriteBody() +{ + if ( mnMode == 0 ) + { + BYTE nBYTE = 0; + for ( ULONG y = 0; y < mnHeight; y++ ) + { + ULONG x; + for ( x = 0; x < mnWidth; x++ ) + { + nBYTE <<= 1; + if (!(mpAcc->GetPixel( y, x ) & 1 ) ) + nBYTE++; + if ( ( x & 7 ) == 7 ) + *mpOStm << nBYTE; + } + if ( ( x & 7 ) != 0 ) + *mpOStm << (BYTE)( nBYTE << ( ( x ^ 7 ) + 1 ) ); + } + } + else + { + int nxCount; + for ( ULONG y = 0; y < mnHeight; y++ ) + { + nxCount = 70; + for ( ULONG x = 0; x < mnWidth; x++ ) + { + if (!( --nxCount ) ) + { + nxCount = 69; + *mpOStm << (BYTE)10; + } + *mpOStm << (BYTE)( ( mpAcc->GetPixel( y, x ) ^ 1 ) + '0' ) ; + } + *mpOStm << (BYTE)10; + } + } +} + +// ------------------------------------------------------------------------ +// eine Dezimalzahl im ASCII format wird in den Stream geschrieben + +void PBMWriter::ImplWriteNumber( sal_Int32 nNumber ) +{ + const ByteString aNum( ByteString::CreateFromInt32( nNumber ) ); + + for( sal_Int16 n = 0, nLen = aNum.Len(); n < nLen; n++ ) + *mpOStm << aNum.GetChar( n ); + +} + +// ------------------------------------------------------------------------ + +// --------------------- +// - exported function - +// --------------------- + +extern "C" BOOL __LOADONCALLAPI GraphicExport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pFilterConfigItem, BOOL ) +{ + PBMWriter aPBMWriter; + + return aPBMWriter.WritePBM( rGraphic, rStream, pFilterConfigItem ); +} + +// ------------------------------------------------------------------------ diff --git a/filter/source/graphicfilter/epbm/exports.map b/filter/source/graphicfilter/epbm/exports.map new file mode 100644 index 000000000000..d4e28c44700c --- /dev/null +++ b/filter/source/graphicfilter/epbm/exports.map @@ -0,0 +1,7 @@ +UDK_3_0_0 { + global: + GraphicExport; + + local: + *; +}; diff --git a/filter/source/graphicfilter/epbm/makefile.mk b/filter/source/graphicfilter/epbm/makefile.mk new file mode 100644 index 000000000000..609eae204aa4 --- /dev/null +++ b/filter/source/graphicfilter/epbm/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=filter +TARGET=epbm +TARGET2=epb +DEPTARGET=vepbm + +# --- Settings ----------------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Allgemein ---------------------------------------------------------- + +.IF "$(editdebug)"!="" || "$(EDITDEBUG)"!="" +CDEFS+= -DEDITDEBUG +.ENDIF + +.IF "$(L10N_framework)"=="" +SLOFILES = $(SLO)$/epbm.obj +.ENDIF +# ========================================================================== + +.IF "$(L10N_framework)"=="" +SHL1TARGET= epb$(DLLPOSTFIX) +SHL1IMPLIB= epbm +SHL1STDLIBS= $(TOOLSLIB) $(VCLLIB) $(CPPULIB) $(SVTOOLLIB) $(SALLIB) + +SHL1LIBS= $(SLB)$/epbm.lib + +.IF "$(GUI)" != "UNX" +.IF "$(COM)" != "GCC" +SHL1OBJS= $(SLO)$/epbm.obj +.ENDIF +.ENDIF + +SHL1VERSIONMAP=exports.map +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) +.ENDIF +# ========================================================================== + +.INCLUDE : target.mk |