userlibandfileserver/fileserver/sfile/sf_deflate.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32\sfile\sf_deflate.h
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __SF_DEFLATE_H__
       
    19 #define __SF_DEFLATE_H__
       
    20 #include "e32huffman.h"
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 typedef TUint8* (*TMemoryMoveFunction)(TAny* aTrg,const TAny* aSrc,TInt aLength);
       
    24 
       
    25 #define __CONFIGURABLE_F32_LOADER_INFLATE_WINDOW_SIZE__ 0x8000
       
    26 
       
    27 // deflation constants
       
    28 const TInt KDeflateLengthMag=8;
       
    29 const TInt KDeflateDistanceMag=12;
       
    30 //
       
    31 const TInt KDeflateMinLength=3;
       
    32 const TInt KDeflateMaxLength=KDeflateMinLength-1 + (1<<KDeflateLengthMag);
       
    33 const TInt KDeflateMaxDistance=(1<<KDeflateDistanceMag);
       
    34 const TInt KDeflateDistCodeBase=0x200;
       
    35 // hashing
       
    36 const TUint KDeflateHashMultiplier=0xAC4B9B19u;
       
    37 const TInt KDeflateHashShift=24;
       
    38 // inflate
       
    39 const TInt KInflateWindowSize=__CONFIGURABLE_F32_LOADER_INFLATE_WINDOW_SIZE__ ;
       
    40 
       
    41 class TEncoding
       
    42 	{
       
    43 public:
       
    44 	enum {ELiterals=256,ELengths=(KDeflateLengthMag-1)*4,ESpecials=1,EDistances=(KDeflateDistanceMag-1)*4};
       
    45 	enum {ELitLens=ELiterals+ELengths+ESpecials};
       
    46 	enum {EEos=ELiterals+ELengths};
       
    47 public:
       
    48 	TUint32 iLitLen[ELitLens];
       
    49 	TUint32 iDistance[EDistances];
       
    50 	};
       
    51 
       
    52 const TInt KDeflationCodes=TEncoding::ELitLens+TEncoding::EDistances;
       
    53 
       
    54 NONSHARABLE_CLASS(CInflater) : public CBase
       
    55 	{
       
    56 public:
       
    57 	enum {EBufSize = 0x800, ESafetyZone=8};
       
    58 public:
       
    59 	static CInflater* NewLC(TBitInput& aInput);
       
    60 	~CInflater();
       
    61 //
       
    62 	TInt ReadL(TUint8* aBuffer,TInt aLength, TMemoryMoveFunction aMemMovefn);
       
    63 	TInt SkipL(TInt aLength);
       
    64 private:
       
    65 	CInflater(TBitInput& aInput);
       
    66 	void ConstructL();
       
    67 	void InitL();
       
    68 	TInt InflateL();
       
    69 private:
       
    70 	TBitInput* iBits;
       
    71 	const TUint8* iRptr;			// partial segment
       
    72 	TInt iLen;
       
    73 	const TUint8* iAvail;			// available data
       
    74 	const TUint8* iLimit;
       
    75 	TEncoding* iEncoding;
       
    76 	TUint8* iOut;					// circular buffer for distance matches
       
    77 	};
       
    78 
       
    79 void DeflateL(const TUint8* aBuf, TInt aLength, TBitOutput& aOutput);
       
    80 
       
    81 NONSHARABLE_CLASS(TFileInput) : public TBitInput
       
    82 	{
       
    83  	enum {KBufSize=KInflateWindowSize};
       
    84 public:
       
    85 	TFileInput(RFile& aFile);
       
    86 	void Cancel();
       
    87 private:
       
    88 	void UnderflowL();
       
    89 private:
       
    90 	RFile& iFile;
       
    91 	TRequestStatus iStat;
       
    92 	TUint8* iReadBuf;
       
    93 	TPtr8 iPtr;
       
    94 	TUint8 iBuf1[KBufSize];
       
    95 	TUint8 iBuf2[KBufSize];
       
    96 	};
       
    97 
       
    98 #endif