diff options
Diffstat (limited to 'filter/source/graphicfilter/egif')
-rw-r--r-- | filter/source/graphicfilter/egif/egif.cxx | 573 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/exports.map | 7 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/giflzwc.cxx | 256 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/giflzwc.hxx | 65 | ||||
-rw-r--r-- | filter/source/graphicfilter/egif/makefile.mk | 71 |
5 files changed, 972 insertions, 0 deletions
diff --git a/filter/source/graphicfilter/egif/egif.cxx b/filter/source/graphicfilter/egif/egif.cxx new file mode 100644 index 000000000000..877ab0df7763 --- /dev/null +++ b/filter/source/graphicfilter/egif/egif.cxx @@ -0,0 +1,573 @@ +/************************************************************************* + * + * 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/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" + +// ------------- +// - GIFWriter - +// ------------- + +class GIFWriter +{ + Bitmap aAccBmp; + BitmapReadAccess* pAcc; + SvStream* pGIF; + sal_uLong nMinPercent; + sal_uLong nMaxPercent; + sal_uLong nLastPercent; + long nActX; + long nActY; + sal_Int32 nInterlaced; + sal_Bool bStatus; + sal_Bool bTransparent; + + void MayCallback( sal_uLong nPercent ); + void WriteSignature( sal_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(); + + sal_Bool CreateAccess( const BitmapEx& rBmpEx ); + void DestroyAccess(); + + void WriteAnimation( const Animation& rAnimation ); + void WriteBitmapEx( const BitmapEx& rBmpEx, const Point& rPoint, sal_Bool bExtended, + long nTimer = 0, Disposal eDisposal = DISPOSE_NOT ); + + com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator; + +public: + + GIFWriter() {} + ~GIFWriter() {} + + sal_Bool WriteGIF( const Graphic& rGraphic, SvStream& rGIF, + FilterConfigItem* pConfigItem ); +}; + +// ------------------------------------------------------------------------ + +sal_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() ); + sal_Bool bLogSize = ( aMap.GetMapUnit() != MAP_PIXEL ); + + if( bLogSize ) + aSize100 = Application::GetDefaultDevice()->LogicToLogic( rGraphic.GetPrefSize(), aMap, MAP_100TH_MM ); + + pGIF = &rGIF; + bStatus = sal_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( sal_True ); + + if ( bStatus ) + { + WriteGlobalHeader( rAnimation.GetDisplaySizePixel() ); + + if( bStatus ) + { + WriteLoopExtension( rAnimation ); + + if( bStatus ) + WriteAnimation( rAnimation ); + } + } + } + else + { + const sal_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, + sal_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 sal_uInt16 nCount = rAnimation.Count(); + + if( nCount ) + { + const double fStep = 100. / nCount; + + nMinPercent = 0L; + nMaxPercent = (sal_uLong) fStep; + + for( sal_uInt16 i = 0; i < nCount; i++ ) + { + const AnimationBitmap& rAnimBmp = rAnimation.Get( i ); + + WriteBitmapEx( rAnimBmp.aBmpEx, rAnimBmp.aPosPix, sal_True, + rAnimBmp.nWait, rAnimBmp.eDisposal ); + nMinPercent = nMaxPercent; + nMaxPercent = (sal_uLong) ( nMaxPercent + fStep ); + } + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::MayCallback( sal_uLong nPercent ) +{ + if ( xStatusIndicator.is() ) + { + if( nPercent >= nLastPercent + 3 ) + { + nLastPercent = nPercent; + if ( nPercent <= 100 ) + xStatusIndicator->setValue( nPercent ); + } + } +} + +// ------------------------------------------------------------------------ + +sal_Bool GIFWriter::CreateAccess( const BitmapEx& rBmpEx ) +{ + if( bStatus ) + { + Bitmap aMask( rBmpEx.GetMask() ); + + aAccBmp = rBmpEx.GetBitmap(); + bTransparent = sal_False; + + if( !!aMask ) + { + if( aAccBmp.Convert( BMP_CONVERSION_8BIT_TRANS ) ) + { + aMask.Convert( BMP_CONVERSION_1BIT_THRESHOLD ); + aAccBmp.Replace( aMask, BMP_COL_TRANS ); + bTransparent = sal_True; + } + else + aAccBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); + } + else + aAccBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); + + pAcc = aAccBmp.AcquireReadAccess(); + + if( !pAcc ) + bStatus = sal_False; + } + + return bStatus; +} + +// ------------------------------------------------------------------------ + +void GIFWriter::DestroyAccess() +{ + aAccBmp.ReleaseAccess( pAcc ); + pAcc = NULL; +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteSignature( sal_Bool bGIF89a ) +{ + if( bStatus ) + { + pGIF->Write( bGIF89a ? "GIF89a" : "GIF87a" , 6 ); + + if( pGIF->GetError() ) + bStatus = sal_False; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteGlobalHeader( const Size& rSize ) +{ + if( bStatus ) + { + // 256 Farben + const sal_uInt16 nWidth = (sal_uInt16) rSize.Width(); + const sal_uInt16 nHeight = (sal_uInt16) rSize.Height(); + const sal_uInt8 cFlags = 128 | ( 7 << 4 ); + + // Werte rausschreiben + *pGIF << nWidth; + *pGIF << nHeight; + *pGIF << cFlags; + *pGIF << (sal_uInt8) 0x00; + *pGIF << (sal_uInt8) 0x00; + + // Dummy-Palette mit zwei Eintraegen (Schwarz/Weiss) schreiben; + // dieses nur wegen Photoshop-Bug, da die keine Bilder ohne + // globale Farbpalette lesen koennen + *pGIF << (sal_uInt16) 0; + *pGIF << (sal_uInt16) 255; + *pGIF << (sal_uInt16) 65535; + + if( pGIF->GetError() ) + bStatus = sal_False; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteLoopExtension( const Animation& rAnimation ) +{ + DBG_ASSERT( rAnimation.Count() > 0, "Animation has no bitmaps!" ); + + sal_uInt16 nLoopCount = (sal_uInt16) 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 sal_uInt8 cLoByte = (const sal_uInt8) nLoopCount; + const sal_uInt8 cHiByte = (const sal_uInt8) ( nLoopCount >> 8 ); + + *pGIF << (sal_uInt8) 0x21; + *pGIF << (sal_uInt8) 0xff; + *pGIF << (sal_uInt8) 0x0b; + pGIF->Write( "NETSCAPE2.0", 11 ); + *pGIF << (sal_uInt8) 0x03; + *pGIF << (sal_uInt8) 0x01; + *pGIF << cLoByte; + *pGIF << cHiByte; + *pGIF << (sal_uInt8) 0x00; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteLogSizeExtension( const Size& rSize100 ) +{ + // PrefSize in 100th-mm als ApplicationExtension schreiben + if( rSize100.Width() && rSize100.Height() ) + { + *pGIF << (sal_uInt8) 0x21; + *pGIF << (sal_uInt8) 0xff; + *pGIF << (sal_uInt8) 0x0b; + pGIF->Write( "STARDIV 5.0", 11 ); + *pGIF << (sal_uInt8) 0x09; + *pGIF << (sal_uInt8) 0x01; + *pGIF << (sal_uInt32) rSize100.Width(); + *pGIF << (sal_uInt32) rSize100.Height(); + *pGIF << (sal_uInt8) 0x00; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteImageExtension( long nTimer, Disposal eDisposal ) +{ + if( bStatus ) + { + const sal_uInt16 nDelay = (sal_uInt16) nTimer; + sal_uInt8 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 << (sal_uInt8) 0x21; + *pGIF << (sal_uInt8) 0xf9; + *pGIF << (sal_uInt8) 0x04; + *pGIF << cFlags; + *pGIF << nDelay; + *pGIF << (sal_uInt8) pAcc->GetBestPaletteIndex( BMP_COL_TRANS ); + *pGIF << (sal_uInt8) 0x00; + + if( pGIF->GetError() ) + bStatus = sal_False; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteLocalHeader() +{ + if( bStatus ) + { + const sal_uInt16 nPosX = (sal_uInt16) nActX; + const sal_uInt16 nPosY = (sal_uInt16) nActY; + const sal_uInt16 nWidth = (sal_uInt16) pAcc->Width(); + const sal_uInt16 nHeight = (sal_uInt16) pAcc->Height(); + sal_uInt8 cFlags = (sal_uInt8) ( pAcc->GetBitCount() - 1 ); + + // Interlaced-Flag setzen + if( nInterlaced ) + cFlags |= 0x40; + + // Flag fuer lokale Farbpalette setzen + cFlags |= 0x80; + + // alles rausschreiben + *pGIF << (sal_uInt8) 0x2c; + *pGIF << nPosX; + *pGIF << nPosY; + *pGIF << nWidth; + *pGIF << nHeight; + *pGIF << cFlags; + + if( pGIF->GetError() ) + bStatus = sal_False; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WritePalette() +{ + if( bStatus && pAcc->HasPalette() ) + { + const sal_uInt16 nCount = pAcc->GetPaletteEntryCount(); + const sal_uInt16 nMaxCount = ( 1 << pAcc->GetBitCount() ); + + for ( sal_uInt16 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 = sal_False; + } +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteAccess() +{ + GIFLZWCompressor aCompressor; + const long nWidth = pAcc->Width(); + const long nHeight = pAcc->Height(); + sal_uInt8* pBuffer = NULL; + const sal_uLong nFormat = pAcc->GetScanlineFormat(); + long nY; + long nT; + long i; + sal_Bool bNative = ( BMP_FORMAT_8BIT_PAL == nFormat ); + + if( !bNative ) + pBuffer = new sal_uInt8[ 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 ] = (sal_uInt8) pAcc->GetPixel( nY, nX ); + + aCompressor.Compress( pBuffer, nWidth ); + } + + if ( pGIF->GetError() ) + bStatus = sal_False; + + MayCallback( nMinPercent + ( nMaxPercent - nMinPercent ) * i / nHeight ); + + if( !bStatus ) + break; + } + + aCompressor.EndCompression(); + + if ( pGIF->GetError() ) + bStatus = sal_False; + } + + delete[] pBuffer; +} + +// ------------------------------------------------------------------------ + +void GIFWriter::WriteTerminator() +{ + if( bStatus ) + { + *pGIF << (sal_uInt8) 0x3b; + + if( pGIF->GetError() ) + bStatus = sal_False; + } +} + +// ------------------------------------------------------------------------ + +extern "C" sal_Bool __LOADONCALLAPI GraphicExport( SvStream& rStream, Graphic& rGraphic, + FilterConfigItem* pConfigItem, sal_Bool ) +{ + return GIFWriter().WriteGIF( rGraphic, rStream, pConfigItem ); +} + +// ------------------------------------------------------------------------ diff --git a/filter/source/graphicfilter/egif/exports.map b/filter/source/graphicfilter/egif/exports.map new file mode 100644 index 000000000000..d4e28c44700c --- /dev/null +++ b/filter/source/graphicfilter/egif/exports.map @@ -0,0 +1,7 @@ +UDK_3_0_0 { + global: + GraphicExport; + + local: + *; +}; diff --git a/filter/source/graphicfilter/egif/giflzwc.cxx b/filter/source/graphicfilter/egif/giflzwc.cxx new file mode 100644 index 000000000000..e57f81ebf073 --- /dev/null +++ b/filter/source/graphicfilter/egif/giflzwc.cxx @@ -0,0 +1,256 @@ +/************************************************************************* + * + * 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 <tools/stream.hxx> +#include "giflzwc.hxx" + +// ---------------------------- +// - GIFImageDataOutputStream - +// ---------------------------- + +class GIFImageDataOutputStream +{ +private: + + void FlushBlockBuf(); + inline void FlushBitsBufsFullBytes(); + + SvStream& rStream; + sal_uInt8* pBlockBuf; + sal_uInt8 nBlockBufSize; + sal_uLong nBitsBuf; + sal_uInt16 nBitsBufSize; + +public: + + GIFImageDataOutputStream( SvStream & rGIF, sal_uInt8 nLZWDataSize ); + ~GIFImageDataOutputStream(); + + inline void WriteBits( sal_uInt16 nCode, sal_uInt16 nCodeLen ); +}; + +// ------------------------------------------------------------------------ + +inline void GIFImageDataOutputStream::FlushBitsBufsFullBytes() +{ + while (nBitsBufSize>=8) + { + if( nBlockBufSize==255 ) + FlushBlockBuf(); + + pBlockBuf[nBlockBufSize++] = (sal_uInt8) nBitsBuf; + nBitsBuf >>= 8; + nBitsBufSize -= 8; + } +} + +// ------------------------------------------------------------------------ + +inline void GIFImageDataOutputStream::WriteBits( sal_uInt16 nCode, sal_uInt16 nCodeLen ) +{ + if( nBitsBufSize+nCodeLen>32 ) + FlushBitsBufsFullBytes(); + + nBitsBuf |= (sal_uLong) nCode << nBitsBufSize; + nBitsBufSize = nBitsBufSize + nCodeLen; +} + +// ------------------------------------------------------------------------ + +GIFImageDataOutputStream::GIFImageDataOutputStream( SvStream & rGIF, sal_uInt8 nLZWDataSize ) : + rStream(rGIF) +{ + pBlockBuf = new sal_uInt8[ 255 ]; + nBlockBufSize = 0; + nBitsBufSize = 0; + nBitsBuf = 0; + rStream << nLZWDataSize; +} + +// ------------------------------------------------------------------------ + + +GIFImageDataOutputStream::~GIFImageDataOutputStream() +{ + WriteBits(0,7); + FlushBitsBufsFullBytes(); + FlushBlockBuf(); + rStream << (sal_uInt8)0; + delete[] pBlockBuf; +} + +// ------------------------------------------------------------------------ + +void GIFImageDataOutputStream::FlushBlockBuf() +{ + if( nBlockBufSize ) + { + rStream << (sal_uInt8) nBlockBufSize; + rStream.Write( pBlockBuf,nBlockBufSize ); + nBlockBufSize = 0; + } +} + +// ------------------- +// - GIFLZWCTreeNode - +// ------------------- + +struct GIFLZWCTreeNode +{ + + GIFLZWCTreeNode* pBrother; // naechster Knoten, der den selben Vater hat + GIFLZWCTreeNode* pFirstChild; // erster Sohn + sal_uInt16 nCode; // Der Code fuer den String von Pixelwerten, der sich ergibt, wenn + sal_uInt16 nValue; // Der Pixelwert +}; + +// -------------------- +// - GIFLZWCompressor - +// -------------------- + +GIFLZWCompressor::GIFLZWCompressor() +{ + pIDOS=NULL; +} + +// ------------------------------------------------------------------------ + +GIFLZWCompressor::~GIFLZWCompressor() +{ + if (pIDOS!=NULL) EndCompression(); +} + +// ------------------------------------------------------------------------ + +void GIFLZWCompressor::StartCompression( SvStream& rGIF, sal_uInt16 nPixelSize ) +{ + if( !pIDOS ) + { + sal_uInt16 i; + + nDataSize = nPixelSize; + + if( nDataSize < 2 ) + nDataSize=2; + + nClearCode=1<<nDataSize; + nEOICode=nClearCode+1; + nTableSize=nEOICode+1; + nCodeSize=nDataSize+1; + + pIDOS=new GIFImageDataOutputStream(rGIF,(sal_uInt8)nDataSize); + pTable=new GIFLZWCTreeNode[4096]; + + for (i=0; i<4096; i++) + { + pTable[i].pBrother = pTable[i].pFirstChild = NULL; + pTable[i].nValue = (sal_uInt8) ( pTable[i].nCode = i ); + } + + pPrefix = NULL; + pIDOS->WriteBits( nClearCode,nCodeSize ); + } +} + +// ------------------------------------------------------------------------ + +void GIFLZWCompressor::Compress( HPBYTE pSrc, sal_uLong nSize ) +{ + if( pIDOS ) + { + GIFLZWCTreeNode* p; + sal_uInt16 i; + sal_uInt8 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==(sal_uInt16)(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..1520603cfe69 --- /dev/null +++ b/filter/source/graphicfilter/egif/giflzwc.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#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; + sal_uInt16 nDataSize; + sal_uInt16 nClearCode; + sal_uInt16 nEOICode; + sal_uInt16 nTableSize; + sal_uInt16 nCodeSize; + +public: + + GIFLZWCompressor(); + ~GIFLZWCompressor(); + + void StartCompression( SvStream& rGIF, sal_uInt16 nPixelSize ); + void Compress( HPBYTE pSrc, sal_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..5579a301e020 --- /dev/null +++ b/filter/source/graphicfilter/egif/makefile.mk @@ -0,0 +1,71 @@ +#************************************************************************* +# +# 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=egif +TARGET2=egi +DEPTARGET=vegif + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +.IF "$(editdebug)"!="" || "$(EDITDEBUG)"!="" +CDEFS+= -DEDITDEBUG +.ENDIF + +.IF "$(L10N_framework)"=="" +SLOFILES= $(SLO)$/egif.obj \ + $(SLO)$/giflzwc.obj +.ENDIF + +# ========================================================================== + +.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 |