1 /******************************************************************************
2 *
3 * Copyright (C) 2009, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * Author: Alexey Krivonogov ( gentee )
11 *
12 ******************************************************************************/
13
14 #include "lzge.h"
15
16 dword rngbits[]={ 0, 0, 0, 1, 1, 2, 2, 2, 3,3,4,4,5,5,6,6,7,
17 7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,
18 17,17,17,17,17,17,17,17,17,17,17,17,17,17, 0xFF };
19 dword rngmax[ 51 ];
20 dword rngmin[ 51 ];
21
22 dword lenmax[ 20 ];
23 dword lenmin[ 20 ];
24 dword lenbits[]={ 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 21, 0xFF };
25
26 //--------------------------------------------------------------------------
27
28 dword STACKAPI lzge_bits( dword val )
29 {
30 dword i;
31
32 for ( i = 1; i < 32; i++ )
33 {
34 if ( (dword)val < (dword)( 1 << i )) return i;
35 }
36 return 32;
37 }
38
39 //--------------------------------------------------------------------------
40
41 void STDCALL lzge_ranges( pslzge lzge, dword maxoff )
42 {
43 dword i = 3, j = MIN_OFFSET;
44
45 rngmax[0] = 0;
46 rngmax[1] = 0;
47 rngmax[2] = 0;
48 // rngmax[3] = 0;
49 while ( rngbits[i] != 0xFF )
50 {
51 rngmin[i] = j;
52 j += 1 << rngbits[i];
53 rngmax[i] = j - 1;
54 // printf("%i = %i - %i %x\n", i, rngmin[i], rngmax[i], rngmax[i] );
55 i++;
56 if ( rngmax[i - 1] >= maxoff ) break;
57 }
58 lzge->numoff = i;
59 lzge->maxbit = lzge_bits( maxoff );
60 lenbits[ ALL_LEN - 1 ] = lzge->maxbit;
61 // printf("Maxoff=%i\n", maxoff );
62 i = 0;
63 j = MATCH_LEN;
64 while ( lenbits[i] != 0xFF )
65 {
66 lenmin[i] = j;
67 j += 1 << lenbits[i];
68 lenmax[i] = j - 1;
69 // printf("%i b=%i %i - %i %x\n", i, lenbits[i], lenmin[i], lenmax[i], lenmax[i] );
70 i++;
71 }
72 }
73
74 //--------------------------------------------------------------------------
75
76