102 #define MAX_BL_BITS 7
105 #define LENGTH_CODES 29
110 #define END_BLOCK 256
114 #define L_CODES (LITERALS+1+LENGTH_CODES)
123 #define STORED_BLOCK 0
124 #define STATIC_TREES 1
146 #define LIT_BUFSIZE 0x8000
147 #if LIT_BUFSIZE > INBUFSIZ
158 #define REPZ_11_138 18
166 #define HEAP_SIZE (2*L_CODES+1)
171 #define send_code(c, tree) Nlmzip_send_bits(tree[c].Code, tree[c].Len)
177 #define d_code(dist) \
180 : dist_code[256+((dist)>>7)])
183 #define URMAX(a,b) (a >= b ? a : b)
191 #define pqremove(tree, top) \
193 top = heap[SMALLEST]; \
194 heap[SMALLEST] = heap[heap_len--]; \
195 pqdownheap(tree, SMALLEST); \
202 #define smaller(tree, n, m) \
203 (tree[n].Freq < tree[m].Freq || \
204 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
227 0,0,0,0,0,0,0,0,1,1,1,1,
228 2,2,2,2,3,3,3,3,4,4,4,4,
234 0,0,0,0,1,1,2,2,3,3,4,4,
235 5,5,6,6,7,7,8,8,9,9,10,10,
241 0,0,0,0,0,0,0,0,0,0,
300 16,17,18,0,8,7,9,6,10,
301 5,11,4,12,3,13,2,14,1,15
332 #define l_buf Nlmzip_inbuf
455 for ( bits = 0; bits <=
MAX_BITS; bits++ ) {
467 if ( bits > max_length ) {
474 if (
n > max_code ) {
481 xbits = extra[
n-base];
489 if ( overflow == 0 ) {
506 }
while ( overflow > 0 );
513 for ( bits = max_length; bits != 0; bits-- ) {
517 if ( m > max_code ) {
555 for ( bits = 1; bits <=
MAX_BITS; bits++ ) {
562 for (
n = 0;
n <= max_code;
n++ ) {
593 int elems = desc->
elems;
605 for (
n = 0;
n < elems;
n++ ) {
620 int new_off =
heap[++
heap_len] = (max_code < 2 ? ++max_code : 0);
621 tree[new_off].Freq = 1;
686 int nextlen =
tree[0].Len;
691 if ( nextlen == 0 ) {
692 max_count = 138; min_count = 3;
694 tree[max_code+1].Len = (
ush)0xffff;
696 for (
n = 0;
n <= max_code;
n++ ) {
698 nextlen =
tree[
n+1].Len;
699 if ( ++
count < max_count && curlen == nextlen ) {
701 }
else if (
count < min_count ) {
703 }
else if ( curlen != 0 ) {
704 if ( curlen != prevlen ) {
708 }
else if (
count <= 10 ) {
715 if ( nextlen == 0 ) {
718 }
else if ( curlen == nextlen ) {
743 int nextlen =
tree[0].Len;
749 if ( nextlen == 0 ) {
754 for (
n = 0;
n <= max_code;
n++ ) {
756 nextlen =
tree[
n+1].Len;
757 if ( ++
count < max_count && curlen == nextlen ) {
759 }
else if (
count < min_count ) {
762 }
while ( --
count != 0 );
763 }
else if ( curlen != 0 ) {
764 if ( curlen != prevlen ) {
770 }
else if (
count <= 10 ) {
779 if ( nextlen == 0 ) {
782 }
else if ( curlen == nextlen ) {
820 for ( max_blindex =
BL_CODES-1; max_blindex >= 3; max_blindex-- ) {
827 opt_len += 3*(max_blindex+1) + (5+5+4);
852 for ( rank = 0; rank < blcodes; rank++ ) {
880 if ( (lx & 7) == 0 ) {
884 if ( (flag & 1) == 0 ) {
988 for ( bits = 0; bits <=
MAX_BITS; bits++ ) {
1000 while (
n <= 279 ) {
1008 while (
n <= 287 ) {
1038 ulg opt_lenb, static_lenb;
1069 if ( static_lenb <= opt_lenb ) {
1070 opt_lenb = static_lenb;
1077 if ( stored_len+4 <= opt_lenb &&
buf != (
char*)0 ) {
1088 }
else if ( static_lenb == opt_lenb ) {
1151 for ( dcode = 0; dcode <
D_CODES; dcode++ ) {
void Nlmzip_send_bits(int value, int length)
Uint4 Nlmzip_bi_reverse(Uint4 code, int len)
void Nlmzip_copy_block(char *buf, Uint4 len, int header)
void Nlmzip_bi_windup(void)
unsigned char Nlmzip_inbuf[0x8000]
BEGIN_CTRANSITION_SCOPE int Nlmzip_level
unsigned short Nlmzip_d_buf[0x8000]
static ct_data dyn_ltree[(2 *(256+1+29)+1)]
static unsigned char length_code[258 - 3+1]
static void scan_tree(ct_data *, int)
static ct_data static_dtree[30]
#define pqremove(tree, top)
static ct_data dyn_dtree[2 *30+1]
static void gen_codes(ct_data *, int)
void Nlmzip_ct_init(ush *attr, int *methodp)
static unsigned char dist_code[512]
static int heap[2 *(256+1+29)+1]
struct tree_desc tree_desc
static int extra_blbits[19]
static unsigned char depth[2 *(256+1+29)+1]
static int build_bl_tree(void)
static void build_tree(tree_desc *)
static ct_data bl_tree[2 *19+1]
#define smaller(tree, n, m)
static void pqdownheap(ct_data *, int)
ulg Nlmzip_flush_block(char *buf, ulg stored_len, int eof)
static ct_data static_ltree[(256+1+29)+2]
int Nlmzip_ct_tally(int dist, int lc)
#define send_code(c, tree)
static void set_file_type(void)
static ulg compressed_len
static void compress_block(ct_data *, ct_data *)
static void send_all_trees(int, int, int)
static void init_block(void)
static int extra_dbits[30]
static int extra_lbits[29]
static unsigned char flag_buf[(0x8000/8)]
static void send_tree(ct_data *, int)
static unsigned short bl_count[15+1]
static unsigned char bl_order[19]
static void gen_bitlen(tree_desc *)
BEGIN_CTRANSITION_SCOPE struct ct_data ct_data
static int base_length[29]
int32_t Int4
4-byte (32-bit) signed integer
uint32_t Uint4
4-byte (32-bit) unsigned integer