williamr@2
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@4
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@4
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
// Declaration for Compression class
|
williamr@2
|
15 |
//
|
williamr@2
|
16 |
//
|
williamr@2
|
17 |
|
williamr@2
|
18 |
#ifndef __EZCOMPRESSOR_H__
|
williamr@2
|
19 |
#define __EZCOMPRESSOR_H__
|
williamr@2
|
20 |
|
williamr@2
|
21 |
#include <e32base.h>
|
williamr@2
|
22 |
#include <ezstream.h>
|
williamr@2
|
23 |
#include <ezbufman.h>
|
williamr@2
|
24 |
|
williamr@2
|
25 |
/**
|
williamr@2
|
26 |
The CEZCompressor class provides in-memory compression functions, including integrity checks of the uncompressed data.
|
williamr@2
|
27 |
This version of the library supports only one compression method (deflation). Compression can be done in a single step
|
williamr@2
|
28 |
(using CompressL()) if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls
|
williamr@2
|
29 |
of the DeflateL() function. The source data is compressed to the target buffer (both source and target contained within
|
williamr@2
|
30 |
the buffer manager argument), and various other arguments distinguish the different compression settings.
|
williamr@2
|
31 |
|
williamr@4
|
32 |
Note: In this version of the library a windowBits value of 8 is unsupported due to a problem with the window size being
|
williamr@4
|
33 |
set to 256 bytes. Although a value of 8 will be accepted by the CEZCompressor constructors, as it is being changed
|
williamr@4
|
34 |
internally by Zlib from 8 to 9, it will not be possible to use the same value for decompression. This is because the
|
williamr@4
|
35 |
Zlib functions called by the CEZDecompressor constructors do not make the same change internally and as a result a
|
williamr@4
|
36 |
KEZlibErrData is returned when calling InflateL(). It is therefore advised that for this version of the library
|
williamr@4
|
37 |
windowBits of 9 is used in place of 8.
|
williamr@4
|
38 |
|
williamr@2
|
39 |
@publishedAll
|
williamr@2
|
40 |
@released
|
williamr@2
|
41 |
*/
|
williamr@2
|
42 |
class CEZCompressor : public CEZZStream
|
williamr@2
|
43 |
{
|
williamr@2
|
44 |
public:
|
williamr@2
|
45 |
/** Compression strategy - used to tune the compression algorithm */
|
williamr@2
|
46 |
enum TStrategy
|
williamr@2
|
47 |
{
|
williamr@2
|
48 |
/** Use for normal data */
|
williamr@2
|
49 |
EDefaultStrategy = Z_DEFAULT_STRATEGY,
|
williamr@2
|
50 |
|
williamr@4
|
51 |
/** Use for data produced by a filter (or predictor) */
|
williamr@2
|
52 |
EFiltered = Z_FILTERED,
|
williamr@2
|
53 |
|
williamr@4
|
54 |
/** Force Huffman encoding only (no string match) */
|
williamr@2
|
55 |
EHuffmanOnly = Z_HUFFMAN_ONLY
|
williamr@2
|
56 |
};
|
williamr@2
|
57 |
|
williamr@2
|
58 |
/** Compression levels */
|
williamr@2
|
59 |
enum
|
williamr@2
|
60 |
{
|
williamr@2
|
61 |
EDefaultCompression = Z_DEFAULT_COMPRESSION,
|
williamr@2
|
62 |
ENoCompression = Z_NO_COMPRESSION,
|
williamr@2
|
63 |
EBestSpeed = Z_BEST_SPEED,
|
williamr@2
|
64 |
EBestCompression = Z_BEST_COMPRESSION
|
williamr@2
|
65 |
};
|
williamr@2
|
66 |
|
williamr@2
|
67 |
/** Window Bits - the base two logarithm of the window size (the size of the history buffer) */
|
williamr@2
|
68 |
enum
|
williamr@2
|
69 |
{
|
williamr@2
|
70 |
EMaxWBits = MAX_WBITS
|
williamr@2
|
71 |
};
|
williamr@2
|
72 |
|
williamr@2
|
73 |
/** Memory level - specifies how much memory should be allocated for the internal compression state */
|
williamr@2
|
74 |
enum
|
williamr@2
|
75 |
{
|
williamr@2
|
76 |
EDefMemLevel = MAX_MEM_LEVEL
|
williamr@2
|
77 |
};
|
williamr@2
|
78 |
|
williamr@2
|
79 |
/** Compression panic values */
|
williamr@2
|
80 |
enum
|
williamr@2
|
81 |
{
|
williamr@2
|
82 |
EDeflateInitlialiserError = EUnexpected + 1,
|
williamr@2
|
83 |
EDeflateTerminated
|
williamr@2
|
84 |
};
|
williamr@2
|
85 |
|
williamr@2
|
86 |
public:
|
williamr@2
|
87 |
~CEZCompressor();
|
williamr@2
|
88 |
|
williamr@2
|
89 |
IMPORT_C static CEZCompressor* NewLC(MEZBufferManager& aInit, TInt aLevel = EDefaultCompression,
|
williamr@2
|
90 |
TInt aWindowBits = EMaxWBits, TInt aMemLevel = EDefMemLevel, TStrategy aStrategy = EDefaultStrategy);
|
williamr@2
|
91 |
IMPORT_C static CEZCompressor* NewL(MEZBufferManager& aInit, TInt aLevel = EDefaultCompression,
|
williamr@2
|
92 |
TInt aWindowBits = EMaxWBits, TInt aMemLevel = EDefMemLevel, TStrategy aStrategy = EDefaultStrategy);
|
williamr@2
|
93 |
IMPORT_C static CEZCompressor* NewLC(MEZBufferManager& aInit, const TDesC8 &aDictionary,
|
williamr@2
|
94 |
TInt aLevel = EDefaultCompression, TInt aWindowBits = EMaxWBits, TInt aMemLevel = EDefMemLevel,
|
williamr@2
|
95 |
TStrategy aStrategy = EDefaultStrategy);
|
williamr@2
|
96 |
IMPORT_C static CEZCompressor* NewL(MEZBufferManager& aInit, const TDesC8 &aDictionary,
|
williamr@2
|
97 |
TInt aLevel = EDefaultCompression, TInt aWindowBits = EMaxWBits, TInt aMemLevel = EDefMemLevel,
|
williamr@2
|
98 |
TStrategy aStrategy = EDefaultStrategy);
|
williamr@2
|
99 |
|
williamr@2
|
100 |
IMPORT_C void ResetL(MEZBufferManager& aInit);
|
williamr@2
|
101 |
|
williamr@2
|
102 |
IMPORT_C TBool DeflateL();
|
williamr@2
|
103 |
|
williamr@2
|
104 |
IMPORT_C static void CompressL(TDes8 &aDestination, const TDesC8 &aSource, TInt aLevel = EDefaultCompression);
|
williamr@2
|
105 |
|
williamr@2
|
106 |
private:
|
williamr@2
|
107 |
enum TDeflationState
|
williamr@2
|
108 |
{
|
williamr@2
|
109 |
ENoFlush,
|
williamr@2
|
110 |
EFinish,
|
williamr@2
|
111 |
EFinalize,
|
williamr@2
|
112 |
ETerminated
|
williamr@2
|
113 |
};
|
williamr@2
|
114 |
|
williamr@2
|
115 |
private:
|
williamr@2
|
116 |
CEZCompressor(MEZBufferManager* aInit);
|
williamr@2
|
117 |
void ConstructL(TInt aLevel, const TUint8* aDictionary, TInt aLength, TInt aWindowBits, TInt aMemLevel, TStrategy aStrategy);
|
williamr@2
|
118 |
void ConstructL(TInt aLevel, TInt aWindowBits, TInt aMemLevel, TStrategy aStrategy);
|
williamr@2
|
119 |
|
williamr@2
|
120 |
private:
|
williamr@2
|
121 |
MEZBufferManager* iBufferInit;
|
williamr@2
|
122 |
TDeflationState iDeflationState;
|
williamr@2
|
123 |
};
|
williamr@2
|
124 |
|
williamr@2
|
125 |
#endif
|
williamr@4
|
126 |
|
williamr@4
|
127 |
|