toolsandutils/e32tools/compress/byte_pair.h
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 2005-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 "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 //
       
    15 
       
    16 #ifndef BYTE_PAIR_H
       
    17 #define BYTE_PAIR_H
       
    18 
       
    19 #ifdef __VC32__
       
    20 #ifdef __MSVCDOTNET__
       
    21 #include <strstream>
       
    22 #include <iomanip>
       
    23 #else //!__MSVCDOTNET__
       
    24 #include <strstrea.h>
       
    25 #include <iomanip.h>
       
    26 #endif //__MSVCDOTNET__
       
    27 #else // !__VC32__
       
    28 #ifdef __TOOLS2__ 
       
    29 #include <sstream>
       
    30 #include <iomanip>
       
    31 using namespace std;
       
    32 #else
       
    33 #include <strstream.h>
       
    34 #include <iomanip.h>
       
    35 #endif
       
    36 #endif // __VC32__
       
    37 
       
    38 
       
    39 
       
    40 #include <e32cmn.h>
       
    41 const TInt MaxBlockSize = 0x1000;
       
    42 class CBytePair {
       
    43     private:
       
    44         TBool iFastCompress;
       
    45         TUint16 PairCount[0x10000];
       
    46         TUint16 PairBuffer[MaxBlockSize*2];
       
    47         TInt PairsFound;
       
    48 
       
    49         TUint16 GlobalPairs[0x10000];
       
    50         TUint16 GlobalTokenCounts[0x100];
       
    51 
       
    52         TUint16 ByteCount[0x100+4];
       
    53 
       
    54         void CountBytes(TUint8* data, TInt size) {
       
    55             memset(ByteCount,0,sizeof(ByteCount));
       
    56             TUint8* dataEnd = data+size;
       
    57             while(data<dataEnd)
       
    58                 ++ByteCount[*data++];
       
    59         }
       
    60         inline void ByteUsed(TInt b) {
       
    61             ByteCount[b] = 0xffff;
       
    62         }
       
    63         int TieBreak(int b1,int b2) {
       
    64             return -ByteCount[b1]-ByteCount[b2];
       
    65         }
       
    66 
       
    67         void InitPairCount(TUint8* data, TInt size, TInt minFrequency, TInt marker);
       
    68         TInt MostCommonPair(TInt& pair);
       
    69         TInt LeastCommonByte(TInt& byte);
       
    70     public:
       
    71         CBytePair(TBool fastCompress) {
       
    72             iFastCompress = fastCompress;
       
    73             memset(GlobalPairs,0,sizeof(GlobalPairs));
       
    74             memset(GlobalTokenCounts,0,sizeof(GlobalTokenCounts));
       
    75         }
       
    76         TInt Compress(TUint8* dst, TUint8* src, TInt size);
       
    77         TInt Decompress(TUint8* dst, TInt dstSize, TUint8* src, TInt srcSize, TUint8*& srcNext);
       
    78 };
       
    79 TInt BytePairCompress(TUint8* dst, TUint8* src, TInt size, CBytePair *aBPE);
       
    80 
       
    81 #endif
       
    82