FireBirdLib - Topfield TMS PVR TAP Programming Library
FBLib_compression.h
Go to the documentation of this file.
1
#ifndef FBLIB_COMPRESSION_H
2
#define FBLIB_COMPRESSION_H
3
4
#include <limits.h>
5
#include "type.h"
6
#include "
libFireBird.h
"
7
8
//Uncomment or pass compiler option to get a call history on the serial console
9
//#define ARCALLTRACE
10
11
/* variables for hash */
12
typedef
struct
13
{
14
dword
pos
;
15
int
too_flag
;
/* if 1, matching candidate is too many */
16
}
HASH
;
17
18
typedef
struct
19
{
20
int
len
;
21
dword
off
;
22
}
MATCHDATA
;
23
24
25
#define LOAD_WORD(x) (((x)[0] << 8) | (x)[1])
26
#define LOAD_WORDLE(x) (((x)[1] << 8) | (x)[0])
27
#define STORE_WORD(x,y) (x)[0] = (y) >> 8;(x)[1] = (y) & 0xff
28
#define STORE_WORDLE(x,y) (x)[1] = (y) >> 8;(x)[0] = (y) & 0xff
29
30
#define LZHUFF5_METHOD_NUM 5
31
#define LZHUFF6_METHOD_NUM 6
32
#define LZHUFF7_METHOD_NUM 7
33
34
#define LZHUFF4_DICBIT 12
/* 2^12 = 4KB sliding dictionary */
35
#define LZHUFF5_DICBIT 13
/* 2^13 = 8KB sliding dictionary */
36
#define LZHUFF6_DICBIT 15
/* 2^15 = 32KB sliding dictionary */
37
#define LZHUFF7_DICBIT 16
/* 2^16 = 64KB sliding dictionary */
38
39
#define NIL 0
40
41
/* hash function: it represents 3 letters from `pos' on `text' */
42
#define INIT_HASH(pos) \
43
((( (ArData->text[(pos)] << 5) \
44
^ ArData->text[(pos) + 1] ) << 5) \
45
^ ArData->text[(pos) + 2] ) & (unsigned)(HSHSIZ - 1);
46
#define NEXT_HASH(hash,pos) \
47
(((hash) << 5) \
48
^ ArData->text[(pos) + 2] ) & (unsigned)(HSHSIZ - 1);
49
50
51
#define peekbits(n) (ArData->bitbuf >> (sizeof(ArData->bitbuf)*8 - (n)))
52
#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
53
#define MAXMATCH 256
/* formerly F (not more than UCHAR_MAX + 1) */
54
#define THRESHOLD 3
/* choose optimal value */
55
#define MAX_DICBIT LZHUFF7_DICBIT
/* lh7 use 16bits */
56
#define MAX_DICSIZ (1L << MAX_DICBIT)
57
#define USHRT_BIT 16
/* (CHAR_BIT * sizeof(ushort)) */
58
#define NP (MAX_DICBIT + 1)
59
#define NT (USHRT_BIT + 3)
60
#define NPT 0x80
/* #if NT > NP #define NPT NT #else #define NPT NP #endif */
61
#define TBIT 5
/* smallest integer such that (1 << TBIT) > * NT */
62
#define CBIT 9
/* smallest integer such that (1 << CBIT) > * NC */
63
#define HSHSIZ (((dword)1) <<15)
64
#define TXTSIZ (MAX_DICSIZ * 2L + MAXMATCH)
65
#define LIMIT 0x100
/* limit of hash chain */
66
67
typedef
struct
68
{
69
byte
*
InFile
, *OutFile;
//provided by the main program
70
dword
OrigSize
;
71
dword
CompSize
;
72
73
dword
InFileRemaining
;
//io
74
int
unpackable
;
75
word
bitbuf
;
76
byte
bitcount
, subbitbuf;
77
int
dicbit
;
78
int
pbit,
np
;
79
80
word pt_code [
NPT
];
//huf
81
word c_code [
NC
];
82
83
word c_freq [2 *
NC
- 1];
84
word p_freq [2 *
NP
- 1];
85
word t_freq [2 *
NT
- 1];
86
87
word left[2 *
NC
- 1];
88
word right[2 *
NC
- 1];
89
word
output_pos
;
90
word
output_mask
;
91
byte
*
buf
;
92
byte
c_len[
NC
];
93
byte
pt_len [
NPT
];
94
dword
bufsiz
;
95
96
HASH
*
hash
;
//maketree
97
word
depth
;
98
99
byte
*
text
;
//encode
100
dword *
prev
;
101
word
cpos
;
102
word
maxmatch
;
103
104
dword
txtsiz
;
105
dword
dicsiz
;
106
int
remainder
;
107
108
word
blocksize
;
//decode
109
word c_table[4096];
110
word pt_table[256];
111
112
dword
Magic
;
113
114
}
ARDATA
;
115
116
#endif
NPT
#define NPT
Definition:
FBLib_compression.h:60
NC
#define NC
Definition:
FBLib_compression.h:52
NT
#define NT
Definition:
FBLib_compression.h:59
NP
#define NP
Definition:
FBLib_compression.h:58
libFireBird.h
ARDATA
Definition:
FBLib_compression.h:68
ARDATA::output_pos
word output_pos
Definition:
FBLib_compression.h:89
ARDATA::bitbuf
word bitbuf
Definition:
FBLib_compression.h:75
ARDATA::hash
HASH * hash
Definition:
FBLib_compression.h:96
ARDATA::depth
word depth
Definition:
FBLib_compression.h:97
ARDATA::dicsiz
dword dicsiz
Definition:
FBLib_compression.h:105
ARDATA::bitcount
byte bitcount
Definition:
FBLib_compression.h:76
ARDATA::CompSize
dword CompSize
Definition:
FBLib_compression.h:71
ARDATA::InFileRemaining
dword InFileRemaining
Definition:
FBLib_compression.h:73
ARDATA::cpos
word cpos
Definition:
FBLib_compression.h:101
ARDATA::buf
byte * buf
Definition:
FBLib_compression.h:91
ARDATA::text
byte * text
Definition:
FBLib_compression.h:99
ARDATA::txtsiz
dword txtsiz
Definition:
FBLib_compression.h:104
ARDATA::remainder
int remainder
Definition:
FBLib_compression.h:106
ARDATA::Magic
dword Magic
Definition:
FBLib_compression.h:112
ARDATA::unpackable
int unpackable
Definition:
FBLib_compression.h:74
ARDATA::OrigSize
dword OrigSize
Definition:
FBLib_compression.h:70
ARDATA::blocksize
word blocksize
Definition:
FBLib_compression.h:108
ARDATA::output_mask
word output_mask
Definition:
FBLib_compression.h:90
ARDATA::maxmatch
word maxmatch
Definition:
FBLib_compression.h:102
ARDATA::dicbit
int dicbit
Definition:
FBLib_compression.h:77
ARDATA::prev
dword * prev
Definition:
FBLib_compression.h:100
ARDATA::InFile
byte * InFile
Definition:
FBLib_compression.h:69
ARDATA::bufsiz
dword bufsiz
Definition:
FBLib_compression.h:94
ARDATA::np
int np
Definition:
FBLib_compression.h:78
HASH
Definition:
FBLib_compression.h:13
HASH::pos
dword pos
Definition:
FBLib_compression.h:14
HASH::too_flag
int too_flag
Definition:
FBLib_compression.h:15
MATCHDATA
Definition:
FBLib_compression.h:19
MATCHDATA::len
int len
Definition:
FBLib_compression.h:20
MATCHDATA::off
dword off
Definition:
FBLib_compression.h:21
compression
FBLib_compression.h
Generated on Fri Apr 29 2022 13:34:00 for FireBirdLib - Topfield TMS PVR TAP Programming Library by
1.9.3