1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _ZCODEC_HXX 29 #define _ZCODEC_HXX 30 31 #include "tools/toolsdllapi.h" 32 #include <tools/solar.h> 33 34 // ----------- 35 // - Defines - 36 // ----------- 37 38 #define DEFAULT_IN_BUFSIZE (0x00008000UL) 39 #define DEFAULT_OUT_BUFSIZE (0x00008000UL) 40 41 #define MAX_MEM_USAGE 8 42 43 // 44 // memory requirement using compress: 45 // [ INBUFFER ] + [ OUTBUFFER ] + 128KB + 1 << (MEM_USAGE+9) 46 // 47 // memory requirement using decompress: 48 // [ INBUFFER ] + [ OUTBUFFER ] + 32KB 49 // 50 51 #define ZCODEC_NO_COMPRESSION (0x00000000UL) 52 #define ZCODEC_BEST_SPEED (0x00000001UL) 53 #define ZCODEC_DEFAULT_COMPRESSION (0x00000006UL) 54 #define ZCODEC_BEST_COMPRESSION (0x00000009UL) 55 56 #define ZCODEC_DEFAULT_STRATEGY (0x00000000UL) 57 #define ZCODEC_ZFILTERED (0x00000100UL) 58 #define ZCODEC_ZHUFFMAN_ONLY (0x00000200UL) 59 60 #define ZCODEC_UPDATE_CRC (0x00010000UL) 61 #define ZCODEC_GZ_LIB (0x00020000UL) 62 63 #define ZCODEC_PNG_DEFAULT ( ZCODEC_NO_COMPRESSION | ZCODEC_DEFAULT_STRATEGY | ZCODEC_UPDATE_CRC ) 64 #define ZCODEC_DEFAULT ( ZCODEC_DEFAULT_COMPRESSION | ZCODEC_DEFAULT_STRATEGY ) 65 66 // ---------- 67 // - ZCodec - 68 // ---------- 69 70 class SvStream; 71 72 class TOOLS_DLLPUBLIC ZCodec 73 { 74 private: 75 76 sal_uIntPtr mbInit; 77 sal_Bool mbStatus; 78 sal_Bool mbFinish; 79 sal_uIntPtr mnMemUsage; 80 SvStream* mpIStm; 81 sal_uInt8* mpInBuf; 82 sal_uIntPtr mnInBufSize; 83 sal_uIntPtr mnInToRead; 84 SvStream* mpOStm; 85 sal_uInt8* mpOutBuf; 86 sal_uIntPtr mnOutBufSize; 87 88 sal_uIntPtr mnCRC; 89 sal_uIntPtr mnCompressMethod; 90 void* mpsC_Stream; 91 92 void ImplInitBuf( sal_Bool nIOFlag ); 93 void ImplWriteBack( void ); 94 95 public: 96 ZCodec( sal_uIntPtr nInBuf, sal_uIntPtr nOutBuf, sal_uIntPtr nMemUsage = MAX_MEM_USAGE ); 97 ZCodec( void ); 98 virtual ~ZCodec(); 99 100 virtual void BeginCompression( sal_uIntPtr nCompressMethod = ZCODEC_DEFAULT ); 101 virtual long EndCompression(); 102 sal_Bool IsFinished () const { return mbFinish; } 103 104 long Compress( SvStream& rIStm, SvStream& rOStm ); 105 long Decompress( SvStream& rIStm, SvStream& rOStm ); 106 107 long Write( SvStream& rOStm, const sal_uInt8* pData, sal_uIntPtr nSize ); 108 long Read( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize ); 109 long ReadAsynchron( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize ); 110 111 void SetBreak( sal_uIntPtr ); 112 sal_uIntPtr GetBreak( void ); 113 void SetCRC( sal_uIntPtr nCurrentCRC ); 114 sal_uIntPtr UpdateCRC( sal_uIntPtr nLatestCRC, sal_uIntPtr nSource ); 115 sal_uIntPtr UpdateCRC( sal_uIntPtr nLatestCRC, sal_uInt8* pSource, long nDatSize ); 116 sal_uIntPtr GetCRC(); 117 }; 118 119 class GZCodec : public ZCodec 120 { 121 122 public: 123 GZCodec(){}; 124 ~GZCodec(){}; 125 virtual void BeginCompression( sal_uIntPtr nCompressMethod = ZCODEC_DEFAULT ); 126 }; 127 128 #endif // _ZCODEC_HXX 129