Lines Matching refs:s

132 static void init_block     (deflate_state *s);
133 static void pqdownheap (deflate_state *s, ct_data *tree, int k);
134 static void gen_bitlen (deflate_state *s, tree_desc *desc);
136 static void build_tree (deflate_state *s, tree_desc *desc);
137 static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
138 static void send_tree (deflate_state *s, ct_data *tree, int max_code);
139 static int build_bl_tree (deflate_state *s);
140 static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
142 static void compress_block (deflate_state *s, ct_data *ltree,
144 static void set_data_type (deflate_state *s);
145 static void bi_flush (deflate_state *s);
146 static void copy_block (deflate_state *s, char *buf, unsigned len,
150 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) argument
154 # define send_code(s, c, tree) \ argument
156 send_bits(s, tree[c].Code, tree[c].Len); }
242 deflate_state *s in zlib_tr_init() argument
247 s->compressed_len = 0L; in zlib_tr_init()
249 s->l_desc.dyn_tree = s->dyn_ltree; in zlib_tr_init()
250 s->l_desc.stat_desc = &static_l_desc; in zlib_tr_init()
252 s->d_desc.dyn_tree = s->dyn_dtree; in zlib_tr_init()
253 s->d_desc.stat_desc = &static_d_desc; in zlib_tr_init()
255 s->bl_desc.dyn_tree = s->bl_tree; in zlib_tr_init()
256 s->bl_desc.stat_desc = &static_bl_desc; in zlib_tr_init()
258 s->bi_buf = 0; in zlib_tr_init()
259 s->bi_valid = 0; in zlib_tr_init()
260 s->last_eob_len = 8; /* enough lookahead for inflate */ in zlib_tr_init()
262 s->bits_sent = 0L; in zlib_tr_init()
266 init_block(s); in zlib_tr_init()
273 deflate_state *s in init_block() argument
279 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; in init_block()
280 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; in init_block()
281 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; in init_block()
283 s->dyn_ltree[END_BLOCK].Freq = 1; in init_block()
284 s->opt_len = s->static_len = 0L; in init_block()
285 s->last_lit = s->matches = 0; in init_block()
296 #define pqremove(s, tree, top) \ argument
298 top = s->heap[SMALLEST]; \
299 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
300 pqdownheap(s, tree, SMALLEST); \
318 deflate_state *s, in pqdownheap() argument
323 int v = s->heap[k]; in pqdownheap()
325 while (j <= s->heap_len) { in pqdownheap()
327 if (j < s->heap_len && in pqdownheap()
328 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { in pqdownheap()
332 if (smaller(tree, v, s->heap[j], s->depth)) break; in pqdownheap()
335 s->heap[k] = s->heap[j]; k = j; in pqdownheap()
340 s->heap[k] = v; in pqdownheap()
354 deflate_state *s, in gen_bitlen() argument
371 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; in gen_bitlen()
376 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ in gen_bitlen()
378 for (h = s->heap_max+1; h < HEAP_SIZE; h++) { in gen_bitlen()
379 n = s->heap[h]; in gen_bitlen()
387 s->bl_count[bits]++; in gen_bitlen()
391 s->opt_len += (ulg)f * (bits + xbits); in gen_bitlen()
392 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); in gen_bitlen()
402 while (s->bl_count[bits] == 0) bits--; in gen_bitlen()
403 s->bl_count[bits]--; /* move one leaf down the tree */ in gen_bitlen()
404 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ in gen_bitlen()
405 s->bl_count[max_length]--; in gen_bitlen()
418 n = s->bl_count[bits]; in gen_bitlen()
420 m = s->heap[--h]; in gen_bitlen()
424 s->opt_len += ((long)bits - (long)tree[m].Len) in gen_bitlen()
485 deflate_state *s, in build_tree() argument
500 s->heap_len = 0, s->heap_max = HEAP_SIZE; in build_tree()
504 s->heap[++(s->heap_len)] = max_code = n; in build_tree()
505 s->depth[n] = 0; in build_tree()
516 while (s->heap_len < 2) { in build_tree()
517 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); in build_tree()
519 s->depth[node] = 0; in build_tree()
520 s->opt_len--; if (stree) s->static_len -= stree[node].Len; in build_tree()
528 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); in build_tree()
535 pqremove(s, tree, n); /* n = node of least frequency */ in build_tree()
536 m = s->heap[SMALLEST]; /* m = node of next least frequency */ in build_tree()
538 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ in build_tree()
539 s->heap[--(s->heap_max)] = m; in build_tree()
543 s->depth[node] = (uch) (max(s->depth[n], s->depth[m]) + 1); in build_tree()
546 if (tree == s->bl_tree) { in build_tree()
552 s->heap[SMALLEST] = node++; in build_tree()
553 pqdownheap(s, tree, SMALLEST); in build_tree()
555 } while (s->heap_len >= 2); in build_tree()
557 s->heap[--(s->heap_max)] = s->heap[SMALLEST]; in build_tree()
562 gen_bitlen(s, (tree_desc *)desc); in build_tree()
565 gen_codes ((ct_data *)tree, max_code, s->bl_count); in build_tree()
573 deflate_state *s, in scan_tree() argument
594 s->bl_tree[curlen].Freq += count; in scan_tree()
596 if (curlen != prevlen) s->bl_tree[curlen].Freq++; in scan_tree()
597 s->bl_tree[REP_3_6].Freq++; in scan_tree()
599 s->bl_tree[REPZ_3_10].Freq++; in scan_tree()
601 s->bl_tree[REPZ_11_138].Freq++; in scan_tree()
619 deflate_state *s, in send_tree() argument
640 do { send_code(s, curlen, s->bl_tree); } while (--count != 0); in send_tree()
644 send_code(s, curlen, s->bl_tree); count--; in send_tree()
647 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); in send_tree()
650 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); in send_tree()
653 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); in send_tree()
671 deflate_state *s in build_bl_tree() argument
677 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); in build_bl_tree()
678 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); in build_bl_tree()
681 build_tree(s, (tree_desc *)(&(s->bl_desc))); in build_bl_tree()
691 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; in build_bl_tree()
694 s->opt_len += 3*(max_blindex+1) + 5+5+4; in build_bl_tree()
696 s->opt_len, s->static_len)); in build_bl_tree()
707 deflate_state *s, in send_all_trees() argument
719 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ in send_all_trees()
720 send_bits(s, dcodes-1, 5); in send_all_trees()
721 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ in send_all_trees()
724 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); in send_all_trees()
726 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); in send_all_trees()
728 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ in send_all_trees()
729 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); in send_all_trees()
731 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ in send_all_trees()
732 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); in send_all_trees()
739 deflate_state *s, in zlib_tr_stored_block() argument
745 send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ in zlib_tr_stored_block()
746 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; in zlib_tr_stored_block()
747 s->compressed_len += (stored_len + 4) << 3; in zlib_tr_stored_block()
749 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ in zlib_tr_stored_block()
755 deflate_state *s in zlib_tr_stored_type_only() argument
758 send_bits(s, (STORED_BLOCK << 1), 3); in zlib_tr_stored_type_only()
759 bi_windup(s); in zlib_tr_stored_type_only()
760 s->compressed_len = (s->compressed_len + 3) & ~7L; in zlib_tr_stored_type_only()
776 deflate_state *s in zlib_tr_align() argument
779 send_bits(s, STATIC_TREES<<1, 3); in zlib_tr_align()
780 send_code(s, END_BLOCK, static_ltree); in zlib_tr_align()
781 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ in zlib_tr_align()
782 bi_flush(s); in zlib_tr_align()
788 if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { in zlib_tr_align()
789 send_bits(s, STATIC_TREES<<1, 3); in zlib_tr_align()
790 send_code(s, END_BLOCK, static_ltree); in zlib_tr_align()
791 s->compressed_len += 10L; in zlib_tr_align()
792 bi_flush(s); in zlib_tr_align()
794 s->last_eob_len = 7; in zlib_tr_align()
803 deflate_state *s, argument
813 if (s->level > 0) {
816 if (s->data_type == Z_UNKNOWN) set_data_type(s);
819 build_tree(s, (tree_desc *)(&(s->l_desc)));
820 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
821 s->static_len));
823 build_tree(s, (tree_desc *)(&(s->d_desc)));
824 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
825 s->static_len));
833 max_blindex = build_bl_tree(s);
836 opt_lenb = (s->opt_len+3+7)>>3;
837 static_lenb = (s->static_len+3+7)>>3;
840 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
841 s->last_lit));
856 if (eof && s->compressed_len == 0L) { /* force stored file */
858 if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
863 copy_block(s, buf, (unsigned)stored_len, 0); /* without header */
864 s->compressed_len = stored_len << 3;
865 s->method = STORED;
881 zlib_tr_stored_block(s, buf, stored_len, eof);
888 send_bits(s, (STATIC_TREES<<1)+eof, 3);
889 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
890 s->compressed_len += 3 + s->static_len;
892 send_bits(s, (DYN_TREES<<1)+eof, 3);
893 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
895 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
896 s->compressed_len += 3 + s->opt_len;
898 Assert (s->compressed_len == s->bits_sent, "bad compressed size");
899 init_block(s);
902 bi_windup(s);
903 s->compressed_len += 7; /* align on byte boundary */
905 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
906 s->compressed_len-7*eof));
908 return s->compressed_len >> 3;
916 deflate_state *s, argument
921 s->d_buf[s->last_lit] = (ush)dist;
922 s->l_buf[s->last_lit++] = (uch)lc;
925 s->dyn_ltree[lc].Freq++;
927 s->matches++;
930 Assert((ush)dist < (ush)MAX_DIST(s) &&
934 s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++;
935 s->dyn_dtree[d_code(dist)].Freq++;
939 if ((s->last_lit & 0xfff) == 0 && s->level > 2) {
941 ulg out_length = (ulg)s->last_lit*8L;
942 ulg in_length = (ulg)((long)s->strstart - s->block_start);
945 out_length += (ulg)s->dyn_dtree[dcode].Freq *
950 s->last_lit, in_length, out_length,
952 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
954 return (s->last_lit == s->lit_bufsize-1);
965 deflate_state *s, argument
976 if (s->last_lit != 0) do {
977 dist = s->d_buf[lx];
978 lc = s->l_buf[lx++];
980 send_code(s, lc, ltree); /* send a literal byte */
985 send_code(s, code+LITERALS+1, ltree); /* send the length code */
989 send_bits(s, lc, extra); /* send the extra length bits */
995 send_code(s, code, dtree); /* send the distance code */
999 send_bits(s, dist, extra); /* send the extra distance bits */
1004 Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
1006 } while (lx < s->last_lit);
1008 send_code(s, END_BLOCK, ltree);
1009 s->last_eob_len = ltree[END_BLOCK].Len;
1019 deflate_state *s argument
1025 while (n < 7) bin_freq += s->dyn_ltree[n++].Freq;
1026 while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq;
1027 while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
1028 s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
1036 deflate_state *s, argument
1042 bi_windup(s); /* align on byte boundary */
1043 s->last_eob_len = 8; /* enough lookahead for inflate */
1046 put_short(s, (ush)len);
1047 put_short(s, (ush)~len);
1049 s->bits_sent += 2*16;
1053 s->bits_sent += (ulg)len<<3;
1056 memcpy(&s->pending_buf[s->pending], buf, len);
1057 s->pending += len;