Lines Matching refs:s
137 static void init_block (deflate_state *s);
138 static void pqdownheap (deflate_state *s, ct_data *tree, int k);
139 static void gen_bitlen (deflate_state *s, tree_desc *desc);
141 static void build_tree (deflate_state *s, tree_desc *desc);
142 static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
143 static void send_tree (deflate_state *s, ct_data *tree, int max_code);
144 static int build_bl_tree (deflate_state *s);
145 static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
147 static void compress_block (deflate_state *s, ct_data *ltree,
149 static void set_data_type (deflate_state *s);
150 static void bi_windup (deflate_state *s);
151 static void bi_flush (deflate_state *s);
152 static void copy_block (deflate_state *s, char *buf, unsigned len,
156 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) argument
160 # define send_code(s, c, tree) \ argument
162 send_bits(s, tree[c].Code, tree[c].Len); }
177 static void send_bits (deflate_state *s, int value, int length);
180 deflate_state *s, in send_bits() argument
187 s->bits_sent += (ulg)length; in send_bits()
193 if (s->bi_valid > (int)Buf_size - length) { in send_bits()
194 s->bi_buf |= (value << s->bi_valid); in send_bits()
195 put_short(s, s->bi_buf); in send_bits()
196 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); in send_bits()
197 s->bi_valid += length - Buf_size; in send_bits()
199 s->bi_buf |= value << s->bi_valid; in send_bits()
200 s->bi_valid += length; in send_bits()
205 #define send_bits(s, value, length) \ argument
207 if (s->bi_valid > (int)Buf_size - len) {\
209 s->bi_buf |= (val << s->bi_valid);\
210 put_short(s, s->bi_buf);\
211 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
212 s->bi_valid += len - Buf_size;\
214 s->bi_buf |= (value) << s->bi_valid;\
215 s->bi_valid += len;\
296 deflate_state *s in zlib_tr_init() argument
301 s->compressed_len = 0L; in zlib_tr_init()
303 s->l_desc.dyn_tree = s->dyn_ltree; in zlib_tr_init()
304 s->l_desc.stat_desc = &static_l_desc; in zlib_tr_init()
306 s->d_desc.dyn_tree = s->dyn_dtree; in zlib_tr_init()
307 s->d_desc.stat_desc = &static_d_desc; in zlib_tr_init()
309 s->bl_desc.dyn_tree = s->bl_tree; in zlib_tr_init()
310 s->bl_desc.stat_desc = &static_bl_desc; in zlib_tr_init()
312 s->bi_buf = 0; in zlib_tr_init()
313 s->bi_valid = 0; in zlib_tr_init()
314 s->last_eob_len = 8; /* enough lookahead for inflate */ in zlib_tr_init()
316 s->bits_sent = 0L; in zlib_tr_init()
320 init_block(s); in zlib_tr_init()
327 deflate_state *s in init_block() argument
333 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; in init_block()
334 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; in init_block()
335 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; in init_block()
337 s->dyn_ltree[END_BLOCK].Freq = 1; in init_block()
338 s->opt_len = s->static_len = 0L; in init_block()
339 s->last_lit = s->matches = 0; in init_block()
350 #define pqremove(s, tree, top) \ argument
352 top = s->heap[SMALLEST]; \
353 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
354 pqdownheap(s, tree, SMALLEST); \
372 deflate_state *s, in pqdownheap() argument
377 int v = s->heap[k]; in pqdownheap()
379 while (j <= s->heap_len) { in pqdownheap()
381 if (j < s->heap_len && in pqdownheap()
382 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { in pqdownheap()
386 if (smaller(tree, v, s->heap[j], s->depth)) break; in pqdownheap()
389 s->heap[k] = s->heap[j]; k = j; in pqdownheap()
394 s->heap[k] = v; in pqdownheap()
408 deflate_state *s, in gen_bitlen() argument
425 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; in gen_bitlen()
430 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ in gen_bitlen()
432 for (h = s->heap_max+1; h < HEAP_SIZE; h++) { in gen_bitlen()
433 n = s->heap[h]; in gen_bitlen()
441 s->bl_count[bits]++; in gen_bitlen()
445 s->opt_len += (ulg)f * (bits + xbits); in gen_bitlen()
446 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); in gen_bitlen()
456 while (s->bl_count[bits] == 0) bits--; in gen_bitlen()
457 s->bl_count[bits]--; /* move one leaf down the tree */ in gen_bitlen()
458 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ in gen_bitlen()
459 s->bl_count[max_length]--; in gen_bitlen()
472 n = s->bl_count[bits]; in gen_bitlen()
474 m = s->heap[--h]; in gen_bitlen()
478 s->opt_len += ((long)bits - (long)tree[m].Len) in gen_bitlen()
539 deflate_state *s, in build_tree() argument
554 s->heap_len = 0, s->heap_max = HEAP_SIZE; in build_tree()
558 s->heap[++(s->heap_len)] = max_code = n; in build_tree()
559 s->depth[n] = 0; in build_tree()
570 while (s->heap_len < 2) { in build_tree()
571 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); in build_tree()
573 s->depth[node] = 0; in build_tree()
574 s->opt_len--; if (stree) s->static_len -= stree[node].Len; in build_tree()
582 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); in build_tree()
589 pqremove(s, tree, n); /* n = node of least frequency */ in build_tree()
590 m = s->heap[SMALLEST]; /* m = node of next least frequency */ in build_tree()
592 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ in build_tree()
593 s->heap[--(s->heap_max)] = m; in build_tree()
597 s->depth[node] = (uch) (max(s->depth[n], s->depth[m]) + 1); in build_tree()
600 if (tree == s->bl_tree) { in build_tree()
606 s->heap[SMALLEST] = node++; in build_tree()
607 pqdownheap(s, tree, SMALLEST); in build_tree()
609 } while (s->heap_len >= 2); in build_tree()
611 s->heap[--(s->heap_max)] = s->heap[SMALLEST]; in build_tree()
616 gen_bitlen(s, (tree_desc *)desc); in build_tree()
619 gen_codes ((ct_data *)tree, max_code, s->bl_count); in build_tree()
627 deflate_state *s, in scan_tree() argument
648 s->bl_tree[curlen].Freq += count; in scan_tree()
650 if (curlen != prevlen) s->bl_tree[curlen].Freq++; in scan_tree()
651 s->bl_tree[REP_3_6].Freq++; in scan_tree()
653 s->bl_tree[REPZ_3_10].Freq++; in scan_tree()
655 s->bl_tree[REPZ_11_138].Freq++; in scan_tree()
673 deflate_state *s, in send_tree() argument
694 do { send_code(s, curlen, s->bl_tree); } while (--count != 0); in send_tree()
698 send_code(s, curlen, s->bl_tree); count--; in send_tree()
701 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); in send_tree()
704 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); in send_tree()
707 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); in send_tree()
725 deflate_state *s in build_bl_tree() argument
731 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); in build_bl_tree()
732 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); in build_bl_tree()
735 build_tree(s, (tree_desc *)(&(s->bl_desc))); in build_bl_tree()
745 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; in build_bl_tree()
748 s->opt_len += 3*(max_blindex+1) + 5+5+4; in build_bl_tree()
750 s->opt_len, s->static_len)); in build_bl_tree()
761 deflate_state *s, in send_all_trees() argument
773 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ in send_all_trees()
774 send_bits(s, dcodes-1, 5); in send_all_trees()
775 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ in send_all_trees()
778 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); in send_all_trees()
780 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); in send_all_trees()
782 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ in send_all_trees()
783 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); in send_all_trees()
785 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ in send_all_trees()
786 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); in send_all_trees()
793 deflate_state *s, in zlib_tr_stored_block() argument
799 send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ in zlib_tr_stored_block()
800 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; in zlib_tr_stored_block()
801 s->compressed_len += (stored_len + 4) << 3; in zlib_tr_stored_block()
803 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ in zlib_tr_stored_block()
809 deflate_state *s in zlib_tr_stored_type_only() argument
812 send_bits(s, (STORED_BLOCK << 1), 3); in zlib_tr_stored_type_only()
813 bi_windup(s); in zlib_tr_stored_type_only()
814 s->compressed_len = (s->compressed_len + 3) & ~7L; in zlib_tr_stored_type_only()
830 deflate_state *s in zlib_tr_align() argument
833 send_bits(s, STATIC_TREES<<1, 3); in zlib_tr_align()
834 send_code(s, END_BLOCK, static_ltree); in zlib_tr_align()
835 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ in zlib_tr_align()
836 bi_flush(s); in zlib_tr_align()
842 if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { in zlib_tr_align()
843 send_bits(s, STATIC_TREES<<1, 3); in zlib_tr_align()
844 send_code(s, END_BLOCK, static_ltree); in zlib_tr_align()
845 s->compressed_len += 10L; in zlib_tr_align()
846 bi_flush(s); in zlib_tr_align()
848 s->last_eob_len = 7; in zlib_tr_align()
857 deflate_state *s, argument
867 if (s->level > 0) {
870 if (s->data_type == Z_UNKNOWN) set_data_type(s);
873 build_tree(s, (tree_desc *)(&(s->l_desc)));
874 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
875 s->static_len));
877 build_tree(s, (tree_desc *)(&(s->d_desc)));
878 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
879 s->static_len));
887 max_blindex = build_bl_tree(s);
890 opt_lenb = (s->opt_len+3+7)>>3;
891 static_lenb = (s->static_len+3+7)>>3;
894 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
895 s->last_lit));
910 if (eof && s->compressed_len == 0L) { /* force stored file */
912 if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
917 copy_block(s, buf, (unsigned)stored_len, 0); /* without header */
918 s->compressed_len = stored_len << 3;
919 s->method = STORED;
935 zlib_tr_stored_block(s, buf, stored_len, eof);
942 send_bits(s, (STATIC_TREES<<1)+eof, 3);
943 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
944 s->compressed_len += 3 + s->static_len;
946 send_bits(s, (DYN_TREES<<1)+eof, 3);
947 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
949 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
950 s->compressed_len += 3 + s->opt_len;
952 Assert (s->compressed_len == s->bits_sent, "bad compressed size");
953 init_block(s);
956 bi_windup(s);
957 s->compressed_len += 7; /* align on byte boundary */
959 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
960 s->compressed_len-7*eof));
962 return s->compressed_len >> 3;
970 deflate_state *s, argument
975 s->d_buf[s->last_lit] = (ush)dist;
976 s->l_buf[s->last_lit++] = (uch)lc;
979 s->dyn_ltree[lc].Freq++;
981 s->matches++;
984 Assert((ush)dist < (ush)MAX_DIST(s) &&
988 s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++;
989 s->dyn_dtree[d_code(dist)].Freq++;
993 if ((s->last_lit & 0xfff) == 0 && s->level > 2) {
995 ulg out_length = (ulg)s->last_lit*8L;
996 ulg in_length = (ulg)((long)s->strstart - s->block_start);
999 out_length += (ulg)s->dyn_dtree[dcode].Freq *
1004 s->last_lit, in_length, out_length,
1006 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
1008 return (s->last_lit == s->lit_bufsize-1);
1019 deflate_state *s, argument
1030 if (s->last_lit != 0) do {
1031 dist = s->d_buf[lx];
1032 lc = s->l_buf[lx++];
1034 send_code(s, lc, ltree); /* send a literal byte */
1039 send_code(s, code+LITERALS+1, ltree); /* send the length code */
1043 send_bits(s, lc, extra); /* send the extra length bits */
1049 send_code(s, code, dtree); /* send the distance code */
1053 send_bits(s, dist, extra); /* send the extra distance bits */
1058 Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
1060 } while (lx < s->last_lit);
1062 send_code(s, END_BLOCK, ltree);
1063 s->last_eob_len = ltree[END_BLOCK].Len;
1073 deflate_state *s argument
1079 while (n < 7) bin_freq += s->dyn_ltree[n++].Freq;
1080 while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq;
1081 while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
1082 s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
1090 deflate_state *s, argument
1096 bi_windup(s); /* align on byte boundary */
1097 s->last_eob_len = 8; /* enough lookahead for inflate */
1100 put_short(s, (ush)len);
1101 put_short(s, (ush)~len);
1103 s->bits_sent += 2*16;
1107 s->bits_sent += (ulg)len<<3;
1110 memcpy(&s->pending_buf[s->pending], buf, len);
1111 s->pending += len;