xref: /aoo4110/main/tools/inc/tools/zcodec.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _ZCODEC_HXX
25 #define _ZCODEC_HXX
26 
27 #include "tools/toolsdllapi.h"
28 #include <tools/solar.h>
29 
30 // -----------
31 // - Defines -
32 // -----------
33 
34 #define DEFAULT_IN_BUFSIZE			(0x00008000UL)
35 #define DEFAULT_OUT_BUFSIZE			(0x00008000UL)
36 
37 #define MAX_MEM_USAGE 8
38 
39 //
40 // memory requirement using compress:
41 //	[ INBUFFER ] + [ OUTBUFFER ] + 128KB + 1 << (MEM_USAGE+9)
42 //
43 // memory requirement using decompress:
44 //	[ INBUFFER ] + [ OUTBUFFER ] + 32KB
45 //
46 
47 #define ZCODEC_NO_COMPRESSION		(0x00000000UL)
48 #define ZCODEC_BEST_SPEED			(0x00000001UL)
49 #define	ZCODEC_DEFAULT_COMPRESSION	(0x00000006UL)
50 #define ZCODEC_BEST_COMPRESSION		(0x00000009UL)
51 
52 #define ZCODEC_DEFAULT_STRATEGY		(0x00000000UL)
53 #define ZCODEC_ZFILTERED			(0x00000100UL)
54 #define ZCODEC_ZHUFFMAN_ONLY		(0x00000200UL)
55 
56 #define ZCODEC_UPDATE_CRC			(0x00010000UL)
57 #define ZCODEC_GZ_LIB				(0x00020000UL)
58 
59 #define ZCODEC_PNG_DEFAULT ( ZCODEC_NO_COMPRESSION | ZCODEC_DEFAULT_STRATEGY | ZCODEC_UPDATE_CRC )
60 #define ZCODEC_DEFAULT	( ZCODEC_DEFAULT_COMPRESSION | ZCODEC_DEFAULT_STRATEGY )
61 
62 // ----------
63 // - ZCodec -
64 // ----------
65 
66 class SvStream;
67 
68 class TOOLS_DLLPUBLIC ZCodec
69 {
70 private:
71 
72 	sal_uIntPtr			mbInit;
73 	sal_Bool			mbStatus;
74 	sal_Bool			mbFinish;
75 	sal_uIntPtr			mnMemUsage;
76 	SvStream*		mpIStm;
77 	sal_uInt8*			mpInBuf;
78 	sal_uIntPtr			mnInBufSize;
79 	sal_uIntPtr			mnInToRead;
80 	SvStream*		mpOStm;
81     sal_uInt8*			mpOutBuf;
82 	sal_uIntPtr			mnOutBufSize;
83 
84 	sal_uIntPtr			mnCRC;
85 	sal_uIntPtr			mnCompressMethod;
86 	void*			mpsC_Stream;
87 
88 	void			ImplInitBuf( sal_Bool nIOFlag );
89 	void			ImplWriteBack( void );
90 
91 public:
92 					ZCodec( sal_uIntPtr nInBuf, sal_uIntPtr nOutBuf, sal_uIntPtr nMemUsage = MAX_MEM_USAGE );
93 					ZCodec( void );
94 	virtual			~ZCodec();
95 
96 	virtual void	BeginCompression( sal_uIntPtr nCompressMethod = ZCODEC_DEFAULT );
97 	virtual long	EndCompression();
IsFinished() const98 	sal_Bool            IsFinished () const { return mbFinish; }
99 
100 	long			Compress( SvStream& rIStm, SvStream& rOStm );
101 	long			Decompress( SvStream& rIStm, SvStream& rOStm );
102 
103 	long			Write( SvStream& rOStm, const sal_uInt8* pData, sal_uIntPtr nSize );
104 	long			Read( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize );
105 	long			ReadAsynchron( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize );
106 
107 	void			SetBreak( sal_uIntPtr );
108 	sal_uIntPtr			GetBreak( void );
109 	void			SetCRC( sal_uIntPtr nCurrentCRC );
110 	sal_uIntPtr			UpdateCRC( sal_uIntPtr nLatestCRC, sal_uIntPtr nSource );
111 	sal_uIntPtr			UpdateCRC( sal_uIntPtr nLatestCRC, sal_uInt8* pSource, long nDatSize );
112 	sal_uIntPtr			GetCRC();
113 };
114 
115 class GZCodec : public ZCodec
116 {
117 
118 public:
GZCodec()119 					GZCodec(){};
~GZCodec()120 					~GZCodec(){};
121 	virtual void	BeginCompression( sal_uIntPtr nCompressMethod = ZCODEC_DEFAULT );
122 };
123 
124 #endif // _ZCODEC_HXX
125