59 #define REPZ_11_138 18
63 = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
66 = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
69 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
72 = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
81 #define DIST_CODE_LEN 512
83 #if defined(GEN_TREES_H) || !defined(STDC)
159 local void gen_trees_header
OF((
void));
163 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
167 # define send_code(s, c, tree) \
168 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
169 send_bits(s, tree[c].Code, tree[c].Len); }
176 #define put_short(s, w) { \
177 put_byte(s, (uch)((w) & 0xff)); \
178 put_byte(s, (uch)((ush)(w) >> 8)); \
190 Tracevv((stderr,
" l %2d v %4x ", length, value));
191 Assert(length > 0 && length <= 15,
"invalid length");
192 s->bits_sent += (
ulg)length;
210 #define send_bits(s, value, length) \
212 if (s->bi_valid > (int)Buf_size - len) {\
214 s->bi_buf |= (ush)val << s->bi_valid;\
215 put_short(s, s->bi_buf);\
216 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
217 s->bi_valid += len - Buf_size;\
219 s->bi_buf |= (ush)(value) << s->bi_valid;\
233 #if defined(GEN_TREES_H) || !defined(STDC)
234 static int static_init_done = 0;
243 if (static_init_done)
return;
246 #ifdef NO_INIT_GLOBAL_POINTERS
262 Assert (length == 256,
"tr_static_init: length != 256");
271 for (code = 0 ; code < 16; code++) {
277 Assert (dist == 256,
"tr_static_init: dist != 256");
279 for ( ; code <
D_CODES; code++) {
285 Assert (dist == 256,
"tr_static_init: 256+dist != 512");
288 for (bits = 0; bits <=
MAX_BITS; bits++) bl_count[bits] = 0;
290 while (n <= 143)
static_ltree[n++].Len = 8, bl_count[8]++;
291 while (n <= 255)
static_ltree[n++].Len = 9, bl_count[9]++;
292 while (n <= 279)
static_ltree[n++].Len = 7, bl_count[7]++;
293 while (n <= 287)
static_ltree[n++].Len = 8, bl_count[8]++;
301 for (n = 0; n <
D_CODES; n++) {
305 static_init_done = 1;
321 # define SEPARATOR(i, last, width) \
322 ((i) == (last)? "\n};\n\n" : \
323 ((i) % (width) == (width)-1 ? ",\n" : ", "))
325 void gen_trees_header()
327 FILE *header = fopen(
"trees.h",
"w");
330 Assert (header != NULL,
"Can't open trees.h");
332 "/* header created automatically with -DGEN_TREES_H */\n\n");
334 fprintf(header,
"local const ct_data static_ltree[L_CODES+2] = {\n");
335 for (i = 0; i <
L_CODES+2; i++) {
340 fprintf(header,
"local const ct_data static_dtree[D_CODES] = {\n");
341 for (i = 0; i <
D_CODES; i++) {
346 fprintf(header,
"const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
349 SEPARATOR(i, DIST_CODE_LEN-1, 20));
353 "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
359 fprintf(header,
"local const int base_length[LENGTH_CODES] = {\n");
362 SEPARATOR(i, LENGTH_CODES-1, 20));
365 fprintf(header,
"local const int base_dist[D_CODES] = {\n");
366 for (i = 0; i <
D_CODES; i++) {
368 SEPARATOR(i, D_CODES-1, 10));
394 s->compressed_len = 0
L;
427 #define pqremove(s, tree, top) \
429 top = s->heap[SMALLEST]; \
430 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
431 pqdownheap(s, tree, SMALLEST); \
438 #define smaller(tree, n, m, depth) \
439 (tree[n].Freq < tree[m].Freq || \
440 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
452 while (j <= s->heap_len) {
454 if (j < s->heap_len &&
504 bits = tree[tree[
n].Dad].Len + 1;
505 if (bits > max_length) bits = max_length, overflow++;
506 tree[
n].Len = (
ush)bits;
509 if (n > max_code)
continue;
513 if (n >= base) xbits = extra[n-
base];
518 if (overflow == 0)
return;
520 Trace((stderr,
"\nbit length overflow\n"));
526 while (s->
bl_count[bits] == 0) bits--;
534 }
while (overflow > 0);
541 for (bits = max_length; bits != 0; bits--) {
545 if (m > max_code)
continue;
546 if ((
unsigned) tree[m].
Len != (
unsigned) bits) {
547 Trace((stderr,
"code %d bits %d->%d\n", m, tree[m].
Len, bits));
548 s->
opt_len += ((long)bits - (
long)tree[
m].Len)
550 tree[
m].Len = (
ush)bits;
575 for (bits = 1; bits <=
MAX_BITS; bits++) {
576 next_code[bits] = code = (code + bl_count[bits-1]) << 1;
582 "inconsistent bit counts");
583 Tracev((stderr,
"\ngen_codes: max_code %d ", max_code));
585 for (n = 0; n <= max_code; n++) {
586 int len = tree[
n].Len;
587 if (len == 0)
continue;
592 n, (isgraph(n) ? n :
' '), len, tree[n].
Code, next_code[len]-1));
619 for (n = 0; n < elems; n++) {
620 if (tree[n].
Freq != 0) {
634 node = s->
heap[++(s->
heap_len)] = (max_code < 2 ? ++max_code : 0);
659 tree[node].Freq = tree[
n].Freq + tree[
m].Freq;
662 tree[
n].Dad = tree[
m].Dad = (
ush)node;
665 fprintf(stderr,
"\nnode %d(%d), sons %d(%d) %d(%d)",
666 node, tree[node].
Freq, n, tree[n].Freq, m, tree[m].Freq);
695 int nextlen = tree[0].Len;
700 if (nextlen == 0) max_count = 138, min_count = 3;
701 tree[max_code+1].Len = (
ush)0xffff;
703 for (n = 0; n <= max_code; n++) {
704 curlen = nextlen; nextlen = tree[n+1].Len;
705 if (++count < max_count && curlen == nextlen) {
707 }
else if (count < min_count) {
708 s->
bl_tree[curlen].Freq += count;
709 }
else if (curlen != 0) {
710 if (curlen != prevlen) s->
bl_tree[curlen].Freq++;
712 }
else if (count <= 10) {
717 count = 0; prevlen = curlen;
719 max_count = 138, min_count = 3;
720 }
else if (curlen == nextlen) {
721 max_count = 6, min_count = 3;
723 max_count = 7, min_count = 4;
737 int nextlen = tree[0].Len;
743 if (nextlen == 0) max_count = 138, min_count = 3;
745 for (n = 0; n <= max_code; n++) {
746 curlen = nextlen; nextlen = tree[n+1].Len;
747 if (++count < max_count && curlen == nextlen) {
749 }
else if (count < min_count) {
752 }
else if (curlen != 0) {
753 if (curlen != prevlen) {
756 Assert(count >= 3 && count <= 6,
" 3_6?");
759 }
else if (count <= 10) {
765 count = 0; prevlen = curlen;
767 max_count = 138, min_count = 3;
768 }
else if (curlen == nextlen) {
769 max_count = 6, min_count = 3;
771 max_count = 7, min_count = 4;
798 for (max_blindex =
BL_CODES-1; max_blindex >= 3; max_blindex--) {
802 s->
opt_len += 3*(max_blindex+1) + 5+5+4;
803 Tracev((stderr,
"\ndyn trees: dyn %ld, stat %ld",
818 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4,
"not enough codes");
819 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <=
BL_CODES,
821 Tracev((stderr,
"\nbl counts: "));
825 for (rank = 0; rank < blcodes; rank++) {
829 Tracev((stderr,
"\nbl tree: sent %ld", s->bits_sent));
832 Tracev((stderr,
"\nlit tree: sent %ld", s->bits_sent));
835 Tracev((stderr,
"\ndist tree: sent %ld", s->bits_sent));
845 s->compressed_len = (s->compressed_len + 3 + 7) & (
ulg)~7
L;
846 s->compressed_len += (stored_len + 4) << 3;
868 s->compressed_len += 10
L;
879 ulg opt_lenb, static_lenb;
895 Tracev((stderr,
"\ndist data: dyn %ld, stat %ld", s->
opt_len,
907 opt_lenb = (s->
opt_len+3+7)>>3;
910 Tracev((stderr,
"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
914 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
917 Assert(buf != (
char*)0,
"lost buf");
918 opt_lenb = static_lenb = stored_len + 5;
922 if (buf != (
char*)0) {
924 if (stored_len+4 <= opt_lenb && buf != (
char*)0) {
936 }
else if (static_lenb >= 0) {
953 s->compressed_len += 3 + s->
opt_len;
956 Assert (s->compressed_len == s->bits_sent,
"bad compressed size");
965 s->compressed_len += 7;
968 Tracev((stderr,
"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
969 s->compressed_len-7*last));
989 (
ush)
d_code(dist) < (
ush)D_CODES,
"_tr_tally: bad match");
995 #ifdef TRUNCATE_BLOCK
1002 for (dcode = 0; dcode <
D_CODES; dcode++) {
1007 Tracev((stderr,
"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1008 s->
last_lit, in_length, out_length,
1009 100
L - out_length*100
L/in_length));
1032 dist = s->
d_buf[lx];
1033 lc = s->
l_buf[lx++];
1036 Tracecv(isgraph(lc), (stderr,
" '%c' ", lc));
1048 Assert (code < D_CODES,
"bad d_code");
1060 "pendingBuf overflow");
1062 }
while (lx < s->last_lit);
1086 unsigned long black_mask = 0xf3ffc07fUL;
1090 for (n = 0; n <= 31; n++, black_mask >>= 1)
1091 if ((black_mask & 1) && (s->
dyn_ltree[n].Freq != 0))
1118 code >>= 1, res <<= 1;
1119 }
while (--len > 0);
1152 s->bits_sent = (s->bits_sent+7) & ~7;
1168 s->bits_sent += 2*16;
1172 s->bits_sent += (
ulg)len<<3;
int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc)
local const uch bl_order[BL_CODES]
local static_tree_desc static_l_desc
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
local void bi_windup(deflate_state *s)
local static_tree_desc static_bl_desc
local static_tree_desc static_d_desc
void ZLIB_INTERNAL _tr_init(deflate_state *s)
local const int extra_blbits[BL_CODES]
#define smaller(tree, n, m, depth)
local ct_data static_dtree[D_CODES]
#define Assert(cond, msg)
struct ct_data_s dyn_ltree[HEAP_SIZE]
void ZLIB_INTERNAL _tr_align(deflate_state *s)
local void pqdownheap(deflate_state *s, ct_data *tree, int k)
static_tree_desc * stat_desc
local void send_tree(deflate_state *s, ct_data *tree, int max_code)
local void scan_tree(deflate_state *s, ct_data *tree, int max_code)
local void bi_flush(deflate_state *s)
uch ZLIB_INTERNAL _dist_code[]
const XML_Char int const XML_Char int const XML_Char * base
local void build_tree(deflate_state *s, tree_desc *desc)
local int base_length[LENGTH_CODES]
local ct_data static_ltree[L_CODES+2]
local int build_bl_tree(deflate_state *s)
local const int extra_dbits[D_CODES]
static constexpr double m
const XML_Char int const XML_Char * value
struct tree_desc_s bl_desc
struct tree_desc_s d_desc
local void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
local unsigned bi_reverse(unsigned code, int len)
#define pqremove(s, tree, top)
local const int extra_lbits[LENGTH_CODES]
local int base_dist[D_CODES]
local void copy_block(deflate_state *s, charf *buf, unsigned len, int header)
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len, int last)
local void tr_static_init()
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
struct ct_data_s dyn_dtree[2 *D_CODES+1]
struct tree_desc_s l_desc
local void gen_bitlen(deflate_state *s, tree_desc *desc)
uch ZLIB_INTERNAL _length_code[]
const ct_data * static_tree
local void init_block(deflate_state *s)
static constexpr double L
local void compress_block(deflate_state *s, const ct_data *ltree, const ct_data *dtree)
#define send_code(s, c, tree)
struct ct_data_s bl_tree[2 *BL_CODES+1]
for(G4int i1=0;i1< theStableOnes.GetNumberOfIsotopes(static_cast< G4int >(anE->GetZ()));i1++)
#define send_bits(s, value, length)
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))
local void gen_codes(ct_data *tree, int max_code, ushf *bl_count)
local int detect_data_type(deflate_state *s)