Kaydet (Commit) 200d530f authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Split ZCodec::BeginCompression param into its 3 independent components

Change-Id: I275abafe81c8bb617c70646244b14f6cecc33854
üst 5e82dc51
...@@ -22,15 +22,10 @@ ...@@ -22,15 +22,10 @@
#include <tools/toolsdllapi.h> #include <tools/toolsdllapi.h>
#define ZCODEC_NO_COMPRESSION (0x00000000UL) #define ZCODEC_NO_COMPRESSION 0
#define ZCODEC_BEST_SPEED (0x00000001UL) #define ZCODEC_BEST_SPEED 1
#define ZCODEC_DEFAULT_COMPRESSION (0x00000006UL) #define ZCODEC_DEFAULT_COMPRESSION 6
#define ZCODEC_BEST_COMPRESSION (0x00000009UL) #define ZCODEC_BEST_COMPRESSION 9
#define ZCODEC_UPDATE_CRC (0x00010000UL)
#define ZCODEC_GZ_LIB (0x00020000UL)
#define ZCODEC_PNG_DEFAULT ( ZCODEC_NO_COMPRESSION | ZCODEC_UPDATE_CRC )
class SvStream; class SvStream;
...@@ -49,7 +44,9 @@ private: ...@@ -49,7 +44,9 @@ private:
sal_uIntPtr mnOutBufSize; sal_uIntPtr mnOutBufSize;
sal_uIntPtr mnCRC; sal_uIntPtr mnCRC;
sal_uIntPtr mnCompressMethod; int mnCompressLevel;
bool mbUpdateCrc;
bool mbGzLib;
void* mpsC_Stream; void* mpsC_Stream;
void ImplInitBuf( bool nIOFlag ); void ImplInitBuf( bool nIOFlag );
...@@ -59,7 +56,7 @@ public: ...@@ -59,7 +56,7 @@ public:
ZCodec( sal_uIntPtr nInBuf = 0x8000UL, sal_uIntPtr nOutBuf = 0x8000UL ); ZCodec( sal_uIntPtr nInBuf = 0x8000UL, sal_uIntPtr nOutBuf = 0x8000UL );
virtual ~ZCodec(); virtual ~ZCodec();
virtual void BeginCompression( sal_uIntPtr nCompressMethod = ZCODEC_DEFAULT_COMPRESSION ); virtual void BeginCompression( int nCompressLevel = ZCODEC_DEFAULT_COMPRESSION, bool updateCrc = false, bool gzLib = false );
virtual long EndCompression(); virtual long EndCompression();
bool IsFinished () const { return mbFinish; } bool IsFinished () const { return mbFinish; }
...@@ -82,9 +79,9 @@ class GZCodec : public ZCodec ...@@ -82,9 +79,9 @@ class GZCodec : public ZCodec
public: public:
GZCodec(){}; GZCodec(){};
virtual ~GZCodec(){}; virtual ~GZCodec(){};
virtual void BeginCompression( sal_uIntPtr nCompressMethod = ZCODEC_DEFAULT_COMPRESSION ) SAL_OVERRIDE virtual void BeginCompression( int nCompressLevel = ZCODEC_DEFAULT_COMPRESSION, bool updateCrc = false, bool gzLib = true ) SAL_OVERRIDE
{ {
ZCodec::BeginCompression( nCompressMethod | ZCODEC_GZ_LIB ); ZCodec::BeginCompression( nCompressLevel, updateCrc, gzLib );
}; };
}; };
......
...@@ -314,7 +314,7 @@ const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject() ...@@ -314,7 +314,7 @@ const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject()
{ {
SvMemoryStream* pDest = new SvMemoryStream; SvMemoryStream* pDest = new SvMemoryStream;
ZCodec aZCodec( 0x8000, 0x8000 ); ZCodec aZCodec( 0x8000, 0x8000 );
aZCodec.BeginCompression(ZCODEC_GZ_LIB); aZCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true);
mpOStm->Seek( 0 ); mpOStm->Seek( 0 );
aZCodec.Decompress( *mpOStm, *pDest ); aZCodec.Decompress( *mpOStm, *pDest );
......
...@@ -49,7 +49,9 @@ ZCodec::ZCodec( sal_uIntPtr nInBufSize, sal_uIntPtr nOutBufSize ) ...@@ -49,7 +49,9 @@ ZCodec::ZCodec( sal_uIntPtr nInBufSize, sal_uIntPtr nOutBufSize )
, mpOutBuf(NULL) , mpOutBuf(NULL)
, mnOutBufSize(nOutBufSize) , mnOutBufSize(nOutBufSize)
, mnCRC(0) , mnCRC(0)
, mnCompressMethod(0) , mnCompressLevel(0)
, mbUpdateCrc(false)
, mbGzLib(false)
{ {
mpsC_Stream = new z_stream; mpsC_Stream = new z_stream;
} }
...@@ -59,7 +61,7 @@ ZCodec::~ZCodec() ...@@ -59,7 +61,7 @@ ZCodec::~ZCodec()
delete (z_stream*) mpsC_Stream; delete (z_stream*) mpsC_Stream;
} }
void ZCodec::BeginCompression( sal_uIntPtr nCompressMethod ) void ZCodec::BeginCompression( int nCompressLevel, bool updateCrc, bool gzLib )
{ {
mbInit = 0; mbInit = 0;
mbStatus = true; mbStatus = true;
...@@ -68,7 +70,9 @@ void ZCodec::BeginCompression( sal_uIntPtr nCompressMethod ) ...@@ -68,7 +70,9 @@ void ZCodec::BeginCompression( sal_uIntPtr nCompressMethod )
mnInToRead = 0xffffffff; mnInToRead = 0xffffffff;
mpInBuf = mpOutBuf = NULL; mpInBuf = mpOutBuf = NULL;
PZSTREAM->total_out = PZSTREAM->total_in = 0; PZSTREAM->total_out = PZSTREAM->total_in = 0;
mnCompressMethod = nCompressMethod; mnCompressLevel = nCompressLevel;
mbUpdateCrc = updateCrc;
mbGzLib = gzLib;
PZSTREAM->zalloc = ( alloc_func )0; PZSTREAM->zalloc = ( alloc_func )0;
PZSTREAM->zfree = ( free_func )0; PZSTREAM->zfree = ( free_func )0;
PZSTREAM->opaque = ( voidpf )0; PZSTREAM->opaque = ( voidpf )0;
...@@ -154,7 +158,7 @@ long ZCodec::Decompress( SvStream& rIStm, SvStream& rOStm ) ...@@ -154,7 +158,7 @@ long ZCodec::Decompress( SvStream& rIStm, SvStream& rOStm )
PZSTREAM->avail_in = mpIStm->Read( PZSTREAM->next_in = mpInBuf, nInToRead ); PZSTREAM->avail_in = mpIStm->Read( PZSTREAM->next_in = mpInBuf, nInToRead );
mnInToRead -= nInToRead; mnInToRead -= nInToRead;
if ( mnCompressMethod & ZCODEC_UPDATE_CRC ) if ( mbUpdateCrc )
mnCRC = UpdateCRC( mnCRC, mpInBuf, nInToRead ); mnCRC = UpdateCRC( mnCRC, mpInBuf, nInToRead );
} }
...@@ -223,7 +227,7 @@ long ZCodec::Read( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize ) ...@@ -223,7 +227,7 @@ long ZCodec::Read( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize )
PZSTREAM->next_in = mpInBuf, nInToRead); PZSTREAM->next_in = mpInBuf, nInToRead);
mnInToRead -= nInToRead; mnInToRead -= nInToRead;
if ( mnCompressMethod & ZCODEC_UPDATE_CRC ) if ( mbUpdateCrc )
mnCRC = UpdateCRC( mnCRC, mpInBuf, nInToRead ); mnCRC = UpdateCRC( mnCRC, mpInBuf, nInToRead );
} }
...@@ -277,7 +281,7 @@ long ZCodec::ReadAsynchron( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize ...@@ -277,7 +281,7 @@ long ZCodec::ReadAsynchron( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize
PZSTREAM->next_in = mpInBuf, nInToRead); PZSTREAM->next_in = mpInBuf, nInToRead);
mnInToRead -= nInToRead; mnInToRead -= nInToRead;
if ( mnCompressMethod & ZCODEC_UPDATE_CRC ) if ( mbUpdateCrc )
mnCRC = UpdateCRC( mnCRC, mpInBuf, nInToRead ); mnCRC = UpdateCRC( mnCRC, mpInBuf, nInToRead );
} }
...@@ -304,7 +308,7 @@ void ZCodec::ImplWriteBack() ...@@ -304,7 +308,7 @@ void ZCodec::ImplWriteBack()
if ( nAvail ) if ( nAvail )
{ {
if ( mbInit & 2 && ( mnCompressMethod & ZCODEC_UPDATE_CRC ) ) if ( mbInit & 2 && mbUpdateCrc )
mnCRC = UpdateCRC( mnCRC, mpOutBuf, nAvail ); mnCRC = UpdateCRC( mnCRC, mpOutBuf, nAvail );
mpOStm->Write( PZSTREAM->next_out = mpOutBuf, nAvail ); mpOStm->Write( PZSTREAM->next_out = mpOutBuf, nAvail );
PZSTREAM->avail_out = mnOutBufSize; PZSTREAM->avail_out = mnOutBufSize;
...@@ -338,7 +342,7 @@ void ZCodec::ImplInitBuf ( bool nIOFlag ) ...@@ -338,7 +342,7 @@ void ZCodec::ImplInitBuf ( bool nIOFlag )
if ( nIOFlag ) if ( nIOFlag )
{ {
mbInit = 1; mbInit = 1;
if ( mbStatus && ( mnCompressMethod & ZCODEC_GZ_LIB ) ) if ( mbStatus && mbGzLib )
{ {
sal_uInt8 n1, n2, j, nMethod, nFlags; sal_uInt8 n1, n2, j, nMethod, nFlags;
for ( int i = 0; i < 2; i++ ) // gz - magic number for ( int i = 0; i < 2; i++ ) // gz - magic number
...@@ -395,7 +399,7 @@ void ZCodec::ImplInitBuf ( bool nIOFlag ) ...@@ -395,7 +399,7 @@ void ZCodec::ImplInitBuf ( bool nIOFlag )
{ {
mbInit = 3; mbInit = 3;
mbStatus = ( deflateInit2_( PZSTREAM, mnCompressMethod & 0xff, Z_DEFLATED, mbStatus = ( deflateInit2_( PZSTREAM, mnCompressLevel, Z_DEFLATED,
MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY, MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY,
ZLIB_VERSION, sizeof( z_stream ) ) >= 0 ); ZLIB_VERSION, sizeof( z_stream ) ) >= 0 );
......
...@@ -900,7 +900,7 @@ void PNGReaderImpl::ImplReadIDAT() ...@@ -900,7 +900,7 @@ void PNGReaderImpl::ImplReadIDAT()
if ( !mbzCodecInUse ) if ( !mbzCodecInUse )
{ {
mbzCodecInUse = true; mbzCodecInUse = true;
mpZCodec->BeginCompression( ZCODEC_PNG_DEFAULT ); mpZCodec->BeginCompression( ZCODEC_NO_COMPRESSION, true );
} }
mpZCodec->SetBreak( mnChunkLen ); mpZCodec->SetBreak( mnChunkLen );
SvMemoryStream aIStrm( &(*maDataIter), mnChunkLen, STREAM_READ ); SvMemoryStream aIStrm( &(*maDataIter), mnChunkLen, STREAM_READ );
......
...@@ -386,7 +386,7 @@ void PNGWriterImpl::ImplWriteIDAT () ...@@ -386,7 +386,7 @@ void PNGWriterImpl::ImplWriteIDAT ()
mpCurrentScan = new sal_uInt8[ mnDeflateInSize ]; mpCurrentScan = new sal_uInt8[ mnDeflateInSize ];
ImplClearFirstScanline(); ImplClearFirstScanline();
} }
mpZCodec->BeginCompression( ZCODEC_PNG_DEFAULT + mnCompLevel ); mpZCodec->BeginCompression( mnCompLevel, true );
mpZCodec->SetCRC( mnCRC ); mpZCodec->SetCRC( mnCRC );
SvMemoryStream aOStm; SvMemoryStream aOStm;
if ( mnInterlaced == 0 ) if ( mnInterlaced == 0 )
......
...@@ -322,7 +322,7 @@ void PPDDecompressStream::Open( const OUString& i_rFile ) ...@@ -322,7 +322,7 @@ void PPDDecompressStream::Open( const OUString& i_rFile )
// so let's try to decompress the stream // so let's try to decompress the stream
mpMemStream = new SvMemoryStream( 4096, 4096 ); mpMemStream = new SvMemoryStream( 4096, 4096 );
ZCodec aCodec; ZCodec aCodec;
aCodec.BeginCompression( ZCODEC_DEFAULT_COMPRESSION | ZCODEC_GZ_LIB ); aCodec.BeginCompression( ZCODEC_DEFAULT_COMPRESSION, false, true );
long nComp = aCodec.Decompress( *mpFileStream, *mpMemStream ); long nComp = aCodec.Decompress( *mpFileStream, *mpMemStream );
aCodec.EndCompression(); aCodec.EndCompression();
if( nComp < 0 ) if( nComp < 0 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment