diff options
Diffstat (limited to 'filter/source/graphicfilter/egif')
-rw-r--r-- | filter/source/graphicfilter/egif/dlgegif.cxx | 111 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/dlgegif.hrc | 39 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/dlgegif.hxx | 74 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/dlgegif.src | 121 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/egif.cxx | 632 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/egifstr.src | 42 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/exports.map | 8 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/giflzwc.cxx | 259 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/giflzwc.hxx | 68 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/makefile.mk | 82 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/strings.hrc | 31 |
11 files changed, 1467 insertions, 0 deletions
diff --git a/filter/source/graphicfilter/egif/dlgegif.cxx b/filter/source/graphicfilter/egif/dlgegif.cxx new file mode 100644 index 000000000000..c3d61dd29383 --- /dev/null +++ b/filter/source/graphicfilter/egif/dlgegif.cxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dlgegif.cxx,v $ + * $Revision: 1.9 $ + * + * 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" +#ifndef GCC +#endif +#include <tools/ref.hxx> +#include <svtools/FilterConfigItem.hxx> +#include <vcl/msgbox.hxx> +#include "dlgegif.hxx" +#include "dlgegif.hrc" +#include "strings.hrc" + +/************************************************************************* +|* +|* Ctor +|* +\************************************************************************/ + +DlgExportEGIF::DlgExportEGIF( FltCallDialogParameter& rPara ) : + ModalDialog ( rPara.pWindow, ResId( DLG_EXPORT_GIF, *rPara.pResMgr ) ), + rFltCallPara ( rPara ), + aCbxInterlaced ( this, ResId( CBX_INTERLACED, *rPara.pResMgr ) ), + aCbxTranslucent ( this, ResId( CBX_TRANSLUCENT, *rPara.pResMgr ) ), + aGrpMode ( this, ResId( GRP_MODE, *rPara.pResMgr ) ), + aGrpDraw ( this, ResId( GRP_DRAW, *rPara.pResMgr ) ), + aBtnOK ( this, ResId( BTN_OK, *rPara.pResMgr ) ), + aBtnCancel ( this, ResId( BTN_CANCEL, *rPara.pResMgr ) ), + aBtnHelp ( this, ResId( BTN_HELP, *rPara.pResMgr ) ), + pMgr ( rPara.pResMgr ) +{ + FreeResource(); + + String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Export/GIF" ) ); + pConfigItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData ); + + String aInterlaceStr( ResId( KEY_INTER, *pMgr ) ); + String aTranslucentStr( ResId( KEY_TRANS, *pMgr ) ); + // Config-Parameter lesen + sal_Bool bInterlaced = pConfigItem->ReadInt32( aInterlaceStr, 1 ) != 0; + sal_Bool bTranslucent = pConfigItem->ReadInt32( aTranslucentStr, 1 ) != 0; + + aCbxInterlaced.Check( bInterlaced ); + aCbxTranslucent.Check( bTranslucent ); + + aBtnOK.SetClickHdl( LINK( this, DlgExportEGIF, OK ) ); +} + +DlgExportEGIF::~DlgExportEGIF() +{ + delete pConfigItem; +} + +/************************************************************************* +|* +|* Speichert eingestellte Werte in ini-Datei +|* +\************************************************************************/ + +IMPL_LINK( DlgExportEGIF, OK, void *, EMPTYARG ) +{ + + // Config-Parameter schreiben + String aInterlaceStr( ResId( KEY_INTER, *pMgr ) ); + String aTranslucentStr( ResId( KEY_TRANS, *pMgr ) ); + + sal_Int32 nValue = 0; + if ( aCbxInterlaced.IsChecked() ) + nValue++; + pConfigItem->WriteInt32( aInterlaceStr, nValue ); + + nValue = 0; + if ( aCbxTranslucent.IsChecked() ) + nValue++; + pConfigItem->WriteInt32( aTranslucentStr, nValue ); + rFltCallPara.aFilterData = pConfigItem->GetFilterData(); + EndDialog( RET_OK ); + + return 0; +} + + + diff --git a/filter/source/graphicfilter/egif/dlgegif.hrc b/filter/source/graphicfilter/egif/dlgegif.hrc new file mode 100644 index 000000000000..4cf48b4ad8ef --- /dev/null +++ b/filter/source/graphicfilter/egif/dlgegif.hrc @@ -0,0 +1,39 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dlgegif.hrc,v $ + * $Revision: 1.3 $ + * + * 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. + * + ************************************************************************/ +#include "filter.hrc" + +#define BTN_OK 1 +#define BTN_CANCEL 1 +#define BTN_HELP 1 +#define FI_DESCR 1 +#define GRP_MODE 1 +#define GRP_DRAW 2 +#define CBX_INTERLACED 1 +#define CBX_TRANSLUCENT 2 diff --git a/filter/source/graphicfilter/egif/dlgegif.hxx b/filter/source/graphicfilter/egif/dlgegif.hxx new file mode 100644 index 000000000000..d6c93ba862b4 --- /dev/null +++ b/filter/source/graphicfilter/egif/dlgegif.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dlgegif.hxx,v $ + * $Revision: 1.6 $ + * + * 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. + * + ************************************************************************/ + + +#ifndef _DLGEGIF_HXX_ +#define _DLGEGIF_HXX_ + +#include <svtools/fltcall.hxx> +#include <vcl/dialog.hxx> +#include <vcl/button.hxx> +#include <vcl/fixed.hxx> + +/************************************************************************* +|* +|* Dialog zum Einstellen von Filteroptionen +|* +\************************************************************************/ + +class FilterConfigItem; +class ResMgr; + +class DlgExportEGIF : public ModalDialog +{ +private: + + FltCallDialogParameter& rFltCallPara; + + CheckBox aCbxInterlaced; + CheckBox aCbxTranslucent; + FixedLine aGrpMode; + FixedLine aGrpDraw; + OKButton aBtnOK; + CancelButton aBtnCancel; + HelpButton aBtnHelp; + + FilterConfigItem* pConfigItem; + ResMgr* pMgr; + + DECL_LINK( OK, void * ); + +public: + DlgExportEGIF( FltCallDialogParameter& rPara ); + ~DlgExportEGIF(); +}; + +#endif // _DLGEGIF_HXX_ + diff --git a/filter/source/graphicfilter/egif/dlgegif.src b/filter/source/graphicfilter/egif/dlgegif.src new file mode 100644 index 000000000000..c9e1bdbf6a1a --- /dev/null +++ b/filter/source/graphicfilter/egif/dlgegif.src @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dlgegif.src,v $ + * $Revision: 1.30 $ + * + * 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. + * + ************************************************************************/ + +#include "dlgegif.hrc" +ModalDialog DLG_EXPORT_GIF +{ + OutputSize = TRUE ; + SVLook = TRUE ; + Size = MAP_APPFONT ( 169 , 70 ) ; + Moveable = TRUE ; + Closeable = TRUE ; + Text [ en-US ] = "GIF Options" ; + OKButton BTN_OK + { + Pos = MAP_APPFONT ( 113 , 6 ) ; + Size = MAP_APPFONT ( 50 , 14 ) ; + TabStop = TRUE ; + DefButton = TRUE ; + }; + CancelButton BTN_CANCEL + { + Pos = MAP_APPFONT ( 113 , 23 ) ; + Size = MAP_APPFONT ( 50 , 14 ) ; + TabStop = TRUE ; + }; + HelpButton BTN_HELP + { + Pos = MAP_APPFONT ( 113 , 43 ) ; + Size = MAP_APPFONT ( 50 , 14 ) ; + TabStop = TRUE ; + }; + FixedLine GRP_MODE + { + Pos = MAP_APPFONT ( 6 , 3 ) ; + Size = MAP_APPFONT ( 100 , 8 ) ; + Text [ en-US ] = "Mode" ; + }; + CheckBox CBX_INTERLACED + { + Pos = MAP_APPFONT ( 12 , 14 ) ; + Size = MAP_APPFONT ( 86 , 12 ) ; + TabStop = TRUE ; + Text [ en-US ] = "~Interlaced" ; + }; + FixedLine GRP_DRAW + { + Pos = MAP_APPFONT ( 6 , 32 ) ; + Size = MAP_APPFONT ( 100 , 8 ) ; + Text [ en-US ] = "Drawing objects" ; + }; + CheckBox CBX_TRANSLUCENT + { + Pos = MAP_APPFONT ( 12 , 43 ) ; + Size = MAP_APPFONT ( 86 , 12 ) ; + TabStop = TRUE ; + Text [ en-US ] = "Save ~transparency" ; + }; +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/filter/source/graphicfilter/egif/egif.cxx b/filter/source/graphicfilter/egif/egif.cxx new file mode 100644 index 000000000000..ec26e87319ae --- /dev/null +++ b/filter/source/graphicfilter/egif/egif.cxx @@ -0,0 +1,632 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: egif.cxx,v $ + * $Revision: 1.10 $ + * + * 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/graph.hxx> +#include <vcl/svapp.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/window.hxx> +#include <svl/solar.hrc> +#include <svtools/fltcall.hxx> +#include <svtools/FilterConfigItem.hxx> +#include "giflzwc.hxx" +#include "strings.hrc" +#include "dlgegif.hrc" +#include "dlgegif.hxx" + +// ------------- +// - GIFWriter - +// ------------- + +class GIFWriter +{ + Bitmap aAccBmp; + BitmapReadAccess* pAcc; + SvStream* pGIF; + ULONG nMinPercent; + ULONG nMaxPercent; + ULONG nLastPercent; + long nActX; + long nActY; + sal_Int32 nInterlaced; + BOOL bStatus; + BOOL bTransparent; + + void MayCallback( ULONG nPercent ); + void WriteSignature( BOOL bGIF89a ); + void WriteGlobalHeader( const Size& rSize ); + void WriteLoopExtension( const Animation& rAnimation ); + void WriteLogSizeExtension( const Size& rSize100 ); + void WriteImageExtension( long nTimer, Disposal eDisposal ); + void WriteLocalHeader(); + void WritePalette(); + void WriteAccess(); + void WriteTerminator(); + + BOOL CreateAccess( const BitmapEx& rBmpEx ); + void DestroyAccess(); + + void WriteAnimation( const Animation& rAnimation ); + void WriteBitmapEx( const BitmapEx& rBmpEx, const Point& rPoint, BOOL bExtended, + long nTimer = 0, Disposal eDisposal = DISPOSE_NOT ); + + com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator; + +public: + + GIFWriter() {} + ~GIFWriter() {} + + BOOL WriteGIF( const Graphic& rGraphic, SvStream& rGIF, + FilterConfigItem* pConfigItem ); +}; + +// ------------------------------------------------------------------------ + +BOOL GIFWriter::WriteGIF( const Graphic& rGraphic, SvStream& rGIF, + FilterConfigItem* pFilterConfigItem ) +{ + if ( pFilterConfigItem ) + { + xStatusIndicator = pFilterConfigItem->GetStatusIndicator(); + if ( xStatusIndicator.is() ) + { + rtl::OUString aMsg; + xStatusIndicator->start( aMsg, 100 ); + } + } + + Size aSize100; + const MapMode aMap( rGraphic.GetPrefMapMode() ); + BOOL bLogSize = ( aMap.GetMapUnit() != MAP_PIXEL ); + + if( bLogSize ) + aSize100 = Application::GetDefaultDevice()->LogicToLogic( rGraphic.GetPrefSize(), aMap, MAP_100TH_MM ); + + pGIF = &rGIF; + bStatus = TRUE; + nLastPercent = 0; + nInterlaced = 0; + pAcc = NULL; + + if ( pFilterConfigItem ) + nInterlaced = pFilterConfigItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Interlaced" ) ), 0 ); + + pGIF->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + + if( rGraphic.IsAnimated() ) + { + const Animation& rAnimation = rGraphic.GetAnimation(); + + WriteSignature( TRUE ); + + if ( bStatus ) + { + WriteGlobalHeader( rAnimation.GetDisplaySizePixel() ); + + if( bStatus ) + { + WriteLoopExtension( rAnimation ); + + if( bStatus ) + WriteAnimation( rAnimation ); + } + } + } + else + { + const BOOL bGrafTrans = rGraphic.IsTransparent(); + + BitmapEx aBmpEx; + + if( bGrafTrans ) + aBmpEx = rGraphic.GetBitmapEx(); + else + aBmpEx = BitmapEx( rGraphic.GetBitmap() ); + + nMinPercent = 0; + nMaxPercent = 100; + + WriteSignature( bGrafTrans || bLogSize ); + + if( bStatus ) + { + WriteGlobalHeader( aBmpEx.GetSizePixel() ); + + if( bStatus ) + WriteBitmapEx( aBmpEx, Point(), bGrafTrans ); + } + } + + if( bStatus ) + { + if( bLogSize ) + WriteLogSizeExtension( aSize100 ); + + WriteTerminator(); + } + + if ( xStatusIndicator.is() ) + xStatusIndicator->end(); + + return bStatus; +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteBitmapEx( const BitmapEx& rBmpEx, const Point& rPoint, + BOOL bExtended, long nTimer, Disposal eDisposal ) +{ + if( CreateAccess( rBmpEx ) ) + { + nActX = rPoint.X(); + nActY = rPoint.Y(); + + if( bExtended ) + WriteImageExtension( nTimer, eDisposal ); + + if( bStatus ) + { + WriteLocalHeader(); + + if( bStatus ) + { + WritePalette(); + + if( bStatus ) + WriteAccess(); + } + } + + DestroyAccess(); + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteAnimation( const Animation& rAnimation ) +{ + const USHORT nCount = rAnimation.Count(); + + if( nCount ) + { + const double fStep = 100. / nCount; + + nMinPercent = 0L; + nMaxPercent = (ULONG) fStep; + + for( USHORT i = 0; i < nCount; i++ ) + { + const AnimationBitmap& rAnimBmp = rAnimation.Get( i ); + + WriteBitmapEx( rAnimBmp.aBmpEx, rAnimBmp.aPosPix, TRUE, + rAnimBmp.nWait, rAnimBmp.eDisposal ); + nMinPercent = nMaxPercent; + nMaxPercent = (ULONG) ( nMaxPercent + fStep ); + } + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::MayCallback( ULONG nPercent ) +{ + if ( xStatusIndicator.is() ) + { + if( nPercent >= nLastPercent + 3 ) + { + nLastPercent = nPercent; + if ( nPercent <= 100 ) + xStatusIndicator->setValue( nPercent ); + } + } +} + +// ------------------------------------------------------------------------ + +BOOL GIFWriter::CreateAccess( const BitmapEx& rBmpEx ) +{ + if( bStatus ) + { + Bitmap aMask( rBmpEx.GetMask() ); + + aAccBmp = rBmpEx.GetBitmap(); + bTransparent = FALSE; + + if( !!aMask ) + { + if( aAccBmp.Convert( BMP_CONVERSION_8BIT_TRANS ) ) + { + aMask.Convert( BMP_CONVERSION_1BIT_THRESHOLD ); + aAccBmp.Replace( aMask, BMP_COL_TRANS ); + bTransparent = TRUE; + } + else + aAccBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); + } + else + aAccBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); + + pAcc = aAccBmp.AcquireReadAccess(); + + if( !pAcc ) + bStatus = FALSE; + } + + return bStatus; +} + +// ------------------------------------------------------------------------ + +void GIFWriter::DestroyAccess() +{ + aAccBmp.ReleaseAccess( pAcc ); + pAcc = NULL; +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteSignature( BOOL bGIF89a ) +{ + if( bStatus ) + { + pGIF->Write( bGIF89a ? "GIF89a" : "GIF87a" , 6 ); + + if( pGIF->GetError() ) + bStatus = FALSE; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteGlobalHeader( const Size& rSize ) +{ + if( bStatus ) + { + // 256 Farben + const UINT16 nWidth = (UINT16) rSize.Width(); + const UINT16 nHeight = (UINT16) rSize.Height(); + const BYTE cFlags = 128 | ( 7 << 4 ); + + // Werte rausschreiben + *pGIF << nWidth; + *pGIF << nHeight; + *pGIF << cFlags; + *pGIF << (BYTE) 0x00; + *pGIF << (BYTE) 0x00; + + // Dummy-Palette mit zwei Eintraegen (Schwarz/Weiss) schreiben; + // dieses nur wegen Photoshop-Bug, da die keine Bilder ohne + // globale Farbpalette lesen koennen + *pGIF << (UINT16) 0; + *pGIF << (UINT16) 255; + *pGIF << (UINT16) 65535; + + if( pGIF->GetError() ) + bStatus = FALSE; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteLoopExtension( const Animation& rAnimation ) +{ + DBG_ASSERT( rAnimation.Count() > 0, "Animation has no bitmaps!" ); + + USHORT nLoopCount = (USHORT) rAnimation.GetLoopCount(); + + // falls nur ein Durchlauf stattfinden soll, + // wird keine LoopExtension geschrieben; + // Default ist dann immer ein Durchlauf + if( nLoopCount != 1 ) + { + // Netscape interpretiert den LoopCount + // als reine Anzahl der _Wiederholungen_ + if( nLoopCount ) + nLoopCount--; + + const BYTE cLoByte = (const BYTE) nLoopCount; + const BYTE cHiByte = (const BYTE) ( nLoopCount >> 8 ); + + *pGIF << (BYTE) 0x21; + *pGIF << (BYTE) 0xff; + *pGIF << (BYTE) 0x0b; + pGIF->Write( "NETSCAPE2.0", 11 ); + *pGIF << (BYTE) 0x03; + *pGIF << (BYTE) 0x01; + *pGIF << cLoByte; + *pGIF << cHiByte; + *pGIF << (BYTE) 0x00; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteLogSizeExtension( const Size& rSize100 ) +{ + // PrefSize in 100th-mm als ApplicationExtension schreiben + if( rSize100.Width() && rSize100.Height() ) + { + *pGIF << (BYTE) 0x21; + *pGIF << (BYTE) 0xff; + *pGIF << (BYTE) 0x0b; + pGIF->Write( "STARDIV 5.0", 11 ); + *pGIF << (BYTE) 0x09; + *pGIF << (BYTE) 0x01; + *pGIF << (UINT32) rSize100.Width(); + *pGIF << (UINT32) rSize100.Height(); + *pGIF << (BYTE) 0x00; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteImageExtension( long nTimer, Disposal eDisposal ) +{ + if( bStatus ) + { + const UINT16 nDelay = (UINT16) nTimer; + BYTE cFlags = 0; + + // Transparent-Flag setzen + if( bTransparent ) + cFlags |= 1; + + // Disposal-Wert setzen + if( eDisposal == DISPOSE_BACK ) + cFlags |= ( 2 << 2 ); + else if( eDisposal == DISPOSE_PREVIOUS ) + cFlags |= ( 3 << 2 ); + + *pGIF << (BYTE) 0x21; + *pGIF << (BYTE) 0xf9; + *pGIF << (BYTE) 0x04; + *pGIF << cFlags; + *pGIF << nDelay; + *pGIF << (BYTE) pAcc->GetBestPaletteIndex( BMP_COL_TRANS ); + *pGIF << (BYTE) 0x00; + + if( pGIF->GetError() ) + bStatus = FALSE; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteLocalHeader() +{ + if( bStatus ) + { + const UINT16 nPosX = (UINT16) nActX; + const UINT16 nPosY = (UINT16) nActY; + const UINT16 nWidth = (UINT16) pAcc->Width(); + const UINT16 nHeight = (UINT16) pAcc->Height(); + BYTE cFlags = (BYTE) ( pAcc->GetBitCount() - 1 ); + + // Interlaced-Flag setzen + if( nInterlaced ) + cFlags |= 0x40; + + // Flag fuer lokale Farbpalette setzen + cFlags |= 0x80; + + // alles rausschreiben + *pGIF << (BYTE) 0x2c; + *pGIF << nPosX; + *pGIF << nPosY; + *pGIF << nWidth; + *pGIF << nHeight; + *pGIF << cFlags; + + if( pGIF->GetError() ) + bStatus = FALSE; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WritePalette() +{ + if( bStatus && pAcc->HasPalette() ) + { + const USHORT nCount = pAcc->GetPaletteEntryCount(); + const USHORT nMaxCount = ( 1 << pAcc->GetBitCount() ); + + for ( USHORT i = 0; i < nCount; i++ ) + { + const BitmapColor& rColor = pAcc->GetPaletteColor( i ); + + *pGIF << rColor.GetRed(); + *pGIF << rColor.GetGreen(); + *pGIF << rColor.GetBlue(); + } + + // Rest mit 0 auffuellen + if( nCount < nMaxCount ) + pGIF->SeekRel( ( nMaxCount - nCount ) * 3 ); + + if( pGIF->GetError() ) + bStatus = FALSE; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteAccess() +{ + GIFLZWCompressor aCompressor; + const long nWidth = pAcc->Width(); + const long nHeight = pAcc->Height(); + BYTE* pBuffer = NULL; + const ULONG nFormat = pAcc->GetScanlineFormat(); + long nY; + long nT; + long i; + BOOL bNative = ( BMP_FORMAT_8BIT_PAL == nFormat ); + + if( !bNative ) + pBuffer = new BYTE[ nWidth ]; + + if( bStatus && ( 8 == pAcc->GetBitCount() ) && pAcc->HasPalette() ) + { + aCompressor.StartCompression( *pGIF, pAcc->GetBitCount() ); + + for( i = 0; i < nHeight; i++ ) + { + if( nInterlaced ) + { + nY = i << 3; + + if( nY >= nHeight ) + { + nT = i - ( ( nHeight + 7 ) >> 3 ); + nY= ( nT << 3 ) + 4; + + if( nY >= nHeight ) + { + nT -= ( nHeight + 3 ) >> 3; + nY = ( nT << 2 ) + 2; + + if ( nY >= nHeight ) + { + nT -= ( ( nHeight + 1 ) >> 2 ); + nY = ( nT << 1 ) + 1; + } + } + } + } + else + nY = i; + + if( bNative ) + aCompressor.Compress( pAcc->GetScanline( nY ), nWidth ); + else + { + for( long nX = 0L; nX < nWidth; nX++ ) + pBuffer[ nX ] = (BYTE) pAcc->GetPixel( nY, nX ); + + aCompressor.Compress( pBuffer, nWidth ); + } + + if ( pGIF->GetError() ) + bStatus = FALSE; + + MayCallback( nMinPercent + ( nMaxPercent - nMinPercent ) * i / nHeight ); + + if( !bStatus ) + break; + } + + aCompressor.EndCompression(); + + if ( pGIF->GetError() ) + bStatus = FALSE; + } + + delete[] pBuffer; +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteTerminator() +{ + if( bStatus ) + { + *pGIF << (BYTE) 0x3b; + + if( pGIF->GetError() ) + bStatus = FALSE; + } +} + +// ------------------------------------------------------------------------ + +extern "C" BOOL __LOADONCALLAPI GraphicExport( SvStream& rStream, Graphic& rGraphic, + FilterConfigItem* pConfigItem, BOOL ) +{ + return GIFWriter().WriteGIF( rGraphic, rStream, pConfigItem ); +} + +// ------------------------------------------------------------------------ + +extern "C" BOOL __LOADONCALLAPI DoExportDialog( FltCallDialogParameter& rPara ) +{ + BOOL bRet = FALSE; + + if ( rPara.pWindow ) + { + ByteString aResMgrName( "egi" ); + ResMgr* pResMgr; + + pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); + + if( pResMgr ) + { + rPara.pResMgr = pResMgr; + bRet = ( DlgExportEGIF( rPara ).Execute() == RET_OK ); + delete pResMgr; + } + else + bRet = TRUE; + } + + return bRet; +} + +// ------------------------------------------------------------------------ +#ifndef GCC +#endif + +#ifdef WIN + +static HINSTANCE hDLLInst = 0; + +extern "C" int CALLBACK LibMain( HINSTANCE hDLL, WORD, WORD nHeap, LPSTR ) +{ +#ifndef WNT + if ( nHeap ) + UnlockData( 0 ); +#endif + + hDLLInst = hDLL; + + return TRUE; +} + +// ------------------------------------------------------------------------ + +extern "C" int CALLBACK WEP( int ) +{ + return 1; +} + +#endif diff --git a/filter/source/graphicfilter/egif/egifstr.src b/filter/source/graphicfilter/egif/egifstr.src new file mode 100644 index 000000000000..b9d63708e5d9 --- /dev/null +++ b/filter/source/graphicfilter/egif/egifstr.src @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: egifstr.src,v $ + * $Revision: 1.4 $ + * + * 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. + * + ************************************************************************/ + + +#include "strings.hrc" + +// Key fuer den Dialog +String KEY_INTER +{ + Text = "Interlaced"; +}; +String KEY_TRANS +{ + Text = "Translucent"; +}; diff --git a/filter/source/graphicfilter/egif/exports.map b/filter/source/graphicfilter/egif/exports.map new file mode 100644 index 000000000000..10820132c0ce --- /dev/null +++ b/filter/source/graphicfilter/egif/exports.map @@ -0,0 +1,8 @@ +GIFEXPORTER_1_0 { + global: + GraphicExport; + DoExportDialog; + + local: + *; +}; diff --git a/filter/source/graphicfilter/egif/giflzwc.cxx b/filter/source/graphicfilter/egif/giflzwc.cxx new file mode 100644 index 000000000000..d6738592336f --- /dev/null +++ b/filter/source/graphicfilter/egif/giflzwc.cxx @@ -0,0 +1,259 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: giflzwc.cxx,v $ + * $Revision: 1.5 $ + * + * 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 <tools/stream.hxx> +#include "giflzwc.hxx" + +// ---------------------------- +// - GIFImageDataOutputStream - +// ---------------------------- + +class GIFImageDataOutputStream +{ +private: + + void FlushBlockBuf(); + inline void FlushBitsBufsFullBytes(); + + SvStream& rStream; + BYTE* pBlockBuf; + BYTE nBlockBufSize; + ULONG nBitsBuf; + USHORT nBitsBufSize; + +public: + + GIFImageDataOutputStream( SvStream & rGIF, BYTE nLZWDataSize ); + ~GIFImageDataOutputStream(); + + inline void WriteBits( USHORT nCode, USHORT nCodeLen ); +}; + +// ------------------------------------------------------------------------ + +inline void GIFImageDataOutputStream::FlushBitsBufsFullBytes() +{ + while (nBitsBufSize>=8) + { + if( nBlockBufSize==255 ) + FlushBlockBuf(); + + pBlockBuf[nBlockBufSize++] = (BYTE) nBitsBuf; + nBitsBuf >>= 8; + nBitsBufSize -= 8; + } +} + +// ------------------------------------------------------------------------ + +inline void GIFImageDataOutputStream::WriteBits( USHORT nCode, USHORT nCodeLen ) +{ + if( nBitsBufSize+nCodeLen>32 ) + FlushBitsBufsFullBytes(); + + nBitsBuf |= (ULONG) nCode << nBitsBufSize; + nBitsBufSize = nBitsBufSize + nCodeLen; +} + +// ------------------------------------------------------------------------ + +GIFImageDataOutputStream::GIFImageDataOutputStream( SvStream & rGIF, BYTE nLZWDataSize ) : + rStream(rGIF) +{ + pBlockBuf = new BYTE[ 255 ]; + nBlockBufSize = 0; + nBitsBufSize = 0; + nBitsBuf = 0; + rStream << nLZWDataSize; +} + +// ------------------------------------------------------------------------ + + +GIFImageDataOutputStream::~GIFImageDataOutputStream() +{ + WriteBits(0,7); + FlushBitsBufsFullBytes(); + FlushBlockBuf(); + rStream << (BYTE)0; + delete[] pBlockBuf; +} + +// ------------------------------------------------------------------------ + +void GIFImageDataOutputStream::FlushBlockBuf() +{ + if( nBlockBufSize ) + { + rStream << (BYTE) nBlockBufSize; + rStream.Write( pBlockBuf,nBlockBufSize ); + nBlockBufSize = 0; + } +} + +// ------------------- +// - GIFLZWCTreeNode - +// ------------------- + +struct GIFLZWCTreeNode +{ + + GIFLZWCTreeNode* pBrother; // naechster Knoten, der den selben Vater hat + GIFLZWCTreeNode* pFirstChild; // erster Sohn + USHORT nCode; // Der Code fuer den String von Pixelwerten, der sich ergibt, wenn + USHORT nValue; // Der Pixelwert +}; + +// -------------------- +// - GIFLZWCompressor - +// -------------------- + +GIFLZWCompressor::GIFLZWCompressor() +{ + pIDOS=NULL; +} + +// ------------------------------------------------------------------------ + +GIFLZWCompressor::~GIFLZWCompressor() +{ + if (pIDOS!=NULL) EndCompression(); +} + +// ------------------------------------------------------------------------ + +void GIFLZWCompressor::StartCompression( SvStream& rGIF, USHORT nPixelSize ) +{ + if( !pIDOS ) + { + USHORT i; + + nDataSize = nPixelSize; + + if( nDataSize < 2 ) + nDataSize=2; + + nClearCode=1<<nDataSize; + nEOICode=nClearCode+1; + nTableSize=nEOICode+1; + nCodeSize=nDataSize+1; + + pIDOS=new GIFImageDataOutputStream(rGIF,(BYTE)nDataSize); + pTable=new GIFLZWCTreeNode[4096]; + + for (i=0; i<4096; i++) + { + pTable[i].pBrother = pTable[i].pFirstChild = NULL; + pTable[i].nValue = (BYTE) ( pTable[i].nCode = i ); + } + + pPrefix = NULL; + pIDOS->WriteBits( nClearCode,nCodeSize ); + } +} + +// ------------------------------------------------------------------------ + +void GIFLZWCompressor::Compress( HPBYTE pSrc, ULONG nSize ) +{ + if( pIDOS ) + { + GIFLZWCTreeNode* p; + USHORT i; + BYTE nV; + + if( !pPrefix && nSize ) + { + pPrefix=pTable+(*pSrc++); + nSize--; + } + + while( nSize ) + { + nSize--; + nV=*pSrc++; + for( p=pPrefix->pFirstChild; p!=NULL; p=p->pBrother ) + { + if (p->nValue==nV) + break; + } + + if( p) + pPrefix=p; + else + { + pIDOS->WriteBits(pPrefix->nCode,nCodeSize); + + if (nTableSize==4096) + { + pIDOS->WriteBits(nClearCode,nCodeSize); + + for (i=0; i<nClearCode; i++) + pTable[i].pFirstChild=NULL; + + nCodeSize=nDataSize+1; + nTableSize=nEOICode+1; + } + else + { + if(nTableSize==(USHORT)(1<<nCodeSize)) + nCodeSize++; + + p=pTable+(nTableSize++); + p->pBrother=pPrefix->pFirstChild; + pPrefix->pFirstChild=p; + p->nValue=nV; + p->pFirstChild=NULL; + } + + pPrefix=pTable+nV; + } + } + } +} + +// ------------------------------------------------------------------------ + +void GIFLZWCompressor::EndCompression() +{ + if( pIDOS ) + { + if( pPrefix ) + pIDOS->WriteBits(pPrefix->nCode,nCodeSize); + + pIDOS->WriteBits( nEOICode,nCodeSize ); + delete[] pTable; + delete pIDOS; + pIDOS=NULL; + } +} diff --git a/filter/source/graphicfilter/egif/giflzwc.hxx b/filter/source/graphicfilter/egif/giflzwc.hxx new file mode 100644 index 000000000000..51d7842a59db --- /dev/null +++ b/filter/source/graphicfilter/egif/giflzwc.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: giflzwc.hxx,v $ + * $Revision: 1.3 $ + * + * 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. + * + ************************************************************************/ + +#ifndef _GIFLZWC_HXX +#define _GIFLZWC_HXX + +#ifndef _BMPACC_HXX +#include <vcl/bmpacc.hxx> +#endif + +// -------------------- +// - GIFLZWCompressor - +// -------------------- + +class GIFImageDataOutputStream; +struct GIFLZWCTreeNode; + +class GIFLZWCompressor +{ +private: + + GIFImageDataOutputStream* pIDOS; + GIFLZWCTreeNode* pTable; + GIFLZWCTreeNode* pPrefix; + USHORT nDataSize; + USHORT nClearCode; + USHORT nEOICode; + USHORT nTableSize; + USHORT nCodeSize; + +public: + + GIFLZWCompressor(); + ~GIFLZWCompressor(); + + void StartCompression( SvStream& rGIF, USHORT nPixelSize ); + void Compress( HPBYTE pSrc, ULONG nSize ); + void EndCompression(); +}; + +#endif // _GIFLZWC_HXX diff --git a/filter/source/graphicfilter/egif/makefile.mk b/filter/source/graphicfilter/egif/makefile.mk new file mode 100644 index 000000000000..78dd57867078 --- /dev/null +++ b/filter/source/graphicfilter/egif/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.14 $ +# +# 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=egif +TARGET2=egi +DEPTARGET=vegif + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +.IF "$(editdebug)"!="" || "$(EDITDEBUG)"!="" +CDEFS+= -DEDITDEBUG +.ENDIF + +SRS1NAME=$(TARGET) +SRC1FILES = dlgegif.src \ + egifstr.src +.IF "$(L10N_framework)"=="" +SLOFILES= $(SLO)$/egif.obj \ + $(SLO)$/dlgegif.obj \ + $(SLO)$/giflzwc.obj +.ENDIF + +# ========================================================================== + +RESLIB1NAME=$(TARGET2) +RESLIB1SRSFILES=$(SRS)$/$(TARGET).srs + +.IF "$(L10N_framework)"=="" +SHL1TARGET= egi$(DLLPOSTFIX) +SHL1IMPLIB= egif +SHL1STDLIBS= $(TOOLSLIB) $(VCLLIB) $(CPPULIB) $(SVTOOLLIB) $(SALLIB) + +SHL1LIBS= $(SLB)$/egif.lib + +.IF "$(GUI)" != "UNX" +.IF "$(COM)" != "GCC" +SHL1OBJS= $(SLO)$/egif.obj +.ENDIF +.ENDIF + +SHL1VERSIONMAP=exports.map +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) +.ENDIF +# ========================================================================== + +.INCLUDE : target.mk diff --git a/filter/source/graphicfilter/egif/strings.hrc b/filter/source/graphicfilter/egif/strings.hrc new file mode 100644 index 000000000000..8d1231753f49 --- /dev/null +++ b/filter/source/graphicfilter/egif/strings.hrc @@ -0,0 +1,31 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: strings.hrc,v $ + * $Revision: 1.3 $ + * + * 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. + * + ************************************************************************/ +#define KEY_INTER 256 +#define KEY_TRANS 257 |