Lines Matching refs:s
144 local void init_block OF((deflate_state *s));
145 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
146 local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
148 local void build_tree OF((deflate_state *s, tree_desc *desc));
149 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
150 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
151 local int build_bl_tree OF((deflate_state *s));
152 local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
154 local void compress_block OF((deflate_state *s, ct_data *ltree,
156 local int detect_data_type OF((deflate_state *s));
158 local void bi_windup OF((deflate_state *s));
159 local void bi_flush OF((deflate_state *s));
160 local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
168 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) argument
172 # define send_code(s, c, tree) \ argument
174 send_bits(s, tree[c].Code, tree[c].Len); }
181 #define put_short(s, w) { \ argument
182 put_byte(s, (uch)((w) & 0xff)); \
183 put_byte(s, (uch)((ush)(w) >> 8)); \
191 local void send_bits OF((deflate_state *s, int value, int length));
193 local void send_bits(s, value, length) in send_bits() argument
194 deflate_state *s; in send_bits()
200 s->bits_sent += (ulg)length;
206 if (s->bi_valid > (int)Buf_size - length) {
207 s->bi_buf |= (ush)value << s->bi_valid;
208 put_short(s, s->bi_buf);
209 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
210 s->bi_valid += length - Buf_size;
212 s->bi_buf |= (ush)value << s->bi_valid;
213 s->bi_valid += length;
218 #define send_bits(s, value, length) \ argument
220 if (s->bi_valid > (int)Buf_size - len) {\
222 s->bi_buf |= (ush)val << s->bi_valid;\
223 put_short(s, s->bi_buf);\
224 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
225 s->bi_valid += len - Buf_size;\
227 s->bi_buf |= (ush)(value) << s->bi_valid;\
228 s->bi_valid += len;\
386 void ZLIB_INTERNAL _tr_init(s) in _tr_init() argument
387 deflate_state *s; in _tr_init()
391 s->l_desc.dyn_tree = s->dyn_ltree;
392 s->l_desc.stat_desc = &static_l_desc;
394 s->d_desc.dyn_tree = s->dyn_dtree;
395 s->d_desc.stat_desc = &static_d_desc;
397 s->bl_desc.dyn_tree = s->bl_tree;
398 s->bl_desc.stat_desc = &static_bl_desc;
400 s->bi_buf = 0;
401 s->bi_valid = 0;
402 s->last_eob_len = 8; /* enough lookahead for inflate */
404 s->compressed_len = 0L;
405 s->bits_sent = 0L;
409 init_block(s);
415 local void init_block(s) in init_block() argument
416 deflate_state *s; in init_block()
421 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
422 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
423 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
425 s->dyn_ltree[END_BLOCK].Freq = 1;
426 s->opt_len = s->static_len = 0L;
427 s->last_lit = s->matches = 0;
438 #define pqremove(s, tree, top) \ argument
440 top = s->heap[SMALLEST]; \
441 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
442 pqdownheap(s, tree, SMALLEST); \
459 local void pqdownheap(s, tree, k) in pqdownheap() argument
460 deflate_state *s; in pqdownheap()
464 int v = s->heap[k];
466 while (j <= s->heap_len) {
468 if (j < s->heap_len &&
469 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
473 if (smaller(tree, v, s->heap[j], s->depth)) break;
476 s->heap[k] = s->heap[j]; k = j;
481 s->heap[k] = v;
494 local void gen_bitlen(s, desc) in gen_bitlen() argument
495 deflate_state *s; in gen_bitlen()
511 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
516 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
518 for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
519 n = s->heap[h];
527 s->bl_count[bits]++;
531 s->opt_len += (ulg)f * (bits + xbits);
532 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
542 while (s->bl_count[bits] == 0) bits--;
543 s->bl_count[bits]--; /* move one leaf down the tree */
544 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
545 s->bl_count[max_length]--;
558 n = s->bl_count[bits];
560 m = s->heap[--h];
564 s->opt_len += ((long)bits - (long)tree[m].Len)
623 local void build_tree(s, desc) in build_tree() argument
624 deflate_state *s; in build_tree()
638 s->heap_len = 0, s->heap_max = HEAP_SIZE;
642 s->heap[++(s->heap_len)] = max_code = n;
643 s->depth[n] = 0;
654 while (s->heap_len < 2) {
655 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
657 s->depth[node] = 0;
658 s->opt_len--; if (stree) s->static_len -= stree[node].Len;
666 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
673 pqremove(s, tree, n); /* n = node of least frequency */
674 m = s->heap[SMALLEST]; /* m = node of next least frequency */
676 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
677 s->heap[--(s->heap_max)] = m;
681 s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
682 s->depth[n] : s->depth[m]) + 1);
685 if (tree == s->bl_tree) {
691 s->heap[SMALLEST] = node++;
692 pqdownheap(s, tree, SMALLEST);
694 } while (s->heap_len >= 2);
696 s->heap[--(s->heap_max)] = s->heap[SMALLEST];
701 gen_bitlen(s, (tree_desc *)desc);
704 gen_codes ((ct_data *)tree, max_code, s->bl_count);
711 local void scan_tree (s, tree, max_code) in scan_tree() argument
712 deflate_state *s; in scan_tree()
732 s->bl_tree[curlen].Freq += count;
734 if (curlen != prevlen) s->bl_tree[curlen].Freq++;
735 s->bl_tree[REP_3_6].Freq++;
737 s->bl_tree[REPZ_3_10].Freq++;
739 s->bl_tree[REPZ_11_138].Freq++;
756 local void send_tree (s, tree, max_code) in send_tree() argument
757 deflate_state *s; in send_tree()
777 do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
781 send_code(s, curlen, s->bl_tree); count--;
784 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
787 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
790 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
807 local int build_bl_tree(s) in build_bl_tree() argument
808 deflate_state *s; in build_bl_tree()
813 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
814 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
817 build_tree(s, (tree_desc *)(&(s->bl_desc)));
827 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
830 s->opt_len += 3*(max_blindex+1) + 5+5+4;
832 s->opt_len, s->static_len));
842 local void send_all_trees(s, lcodes, dcodes, blcodes) in send_all_trees() argument
843 deflate_state *s; in send_all_trees()
852 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
853 send_bits(s, dcodes-1, 5);
854 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
857 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
859 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
861 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
862 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
864 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
865 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
871 void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) in _tr_stored_block() argument
872 deflate_state *s; in _tr_stored_block()
877 send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
879 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
880 s->compressed_len += (stored_len + 4) << 3;
882 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
896 void ZLIB_INTERNAL _tr_align(s) in _tr_align() argument
897 deflate_state *s; in _tr_align()
899 send_bits(s, STATIC_TREES<<1, 3);
900 send_code(s, END_BLOCK, static_ltree);
902 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
904 bi_flush(s);
910 if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
911 send_bits(s, STATIC_TREES<<1, 3);
912 send_code(s, END_BLOCK, static_ltree);
914 s->compressed_len += 10L;
916 bi_flush(s);
918 s->last_eob_len = 7;
925 void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) in _tr_flush_block() argument
926 deflate_state *s; in _tr_flush_block()
935 if (s->level > 0) {
938 if (s->strm->data_type == Z_UNKNOWN)
939 s->strm->data_type = detect_data_type(s);
942 build_tree(s, (tree_desc *)(&(s->l_desc)));
943 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
944 s->static_len));
946 build_tree(s, (tree_desc *)(&(s->d_desc)));
947 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
948 s->static_len));
956 max_blindex = build_bl_tree(s);
959 opt_lenb = (s->opt_len+3+7)>>3;
960 static_lenb = (s->static_len+3+7)>>3;
963 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
964 s->last_lit));
985 _tr_stored_block(s, buf, stored_len, last);
990 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
992 send_bits(s, (STATIC_TREES<<1)+last, 3);
993 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
995 s->compressed_len += 3 + s->static_len;
998 send_bits(s, (DYN_TREES<<1)+last, 3);
999 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
1001 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
1003 s->compressed_len += 3 + s->opt_len;
1006 Assert (s->compressed_len == s->bits_sent, "bad compressed size");
1010 init_block(s);
1013 bi_windup(s);
1015 s->compressed_len += 7; /* align on byte boundary */
1018 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
1019 s->compressed_len-7*last));
1026 int ZLIB_INTERNAL _tr_tally (s, dist, lc) in _tr_tally() argument
1027 deflate_state *s; in _tr_tally()
1031 s->d_buf[s->last_lit] = (ush)dist;
1032 s->l_buf[s->last_lit++] = (uch)lc;
1035 s->dyn_ltree[lc].Freq++;
1037 s->matches++;
1040 Assert((ush)dist < (ush)MAX_DIST(s) &&
1044 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
1045 s->dyn_dtree[d_code(dist)].Freq++;
1050 if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
1052 ulg out_length = (ulg)s->last_lit*8L;
1053 ulg in_length = (ulg)((long)s->strstart - s->block_start);
1056 out_length += (ulg)s->dyn_dtree[dcode].Freq *
1061 s->last_lit, in_length, out_length,
1063 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
1066 return (s->last_lit == s->lit_bufsize-1);
1076 local void compress_block(s, ltree, dtree) in compress_block() argument
1077 deflate_state *s; in compress_block()
1087 if (s->last_lit != 0) do {
1088 dist = s->d_buf[lx];
1089 lc = s->l_buf[lx++];
1091 send_code(s, lc, ltree); /* send a literal byte */
1096 send_code(s, code+LITERALS+1, ltree); /* send the length code */
1100 send_bits(s, lc, extra); /* send the extra length bits */
1106 send_code(s, code, dtree); /* send the distance code */
1110 send_bits(s, dist, extra); /* send the extra distance bits */
1115 Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
1118 } while (lx < s->last_lit);
1120 send_code(s, END_BLOCK, ltree);
1121 s->last_eob_len = ltree[END_BLOCK].Len;
1137 local int detect_data_type(s) in detect_data_type() argument
1138 deflate_state *s; in detect_data_type()
1149 if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
1153 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
1154 || s->dyn_ltree[13].Freq != 0)
1157 if (s->dyn_ltree[n].Freq != 0)
1186 local void bi_flush(s) in bi_flush() argument
1187 deflate_state *s; in bi_flush()
1189 if (s->bi_valid == 16) {
1190 put_short(s, s->bi_buf);
1191 s->bi_buf = 0;
1192 s->bi_valid = 0;
1193 } else if (s->bi_valid >= 8) {
1194 put_byte(s, (Byte)s->bi_buf);
1195 s->bi_buf >>= 8;
1196 s->bi_valid -= 8;
1203 local void bi_windup(s) in bi_windup() argument
1204 deflate_state *s; in bi_windup()
1206 if (s->bi_valid > 8) {
1207 put_short(s, s->bi_buf);
1208 } else if (s->bi_valid > 0) {
1209 put_byte(s, (Byte)s->bi_buf);
1211 s->bi_buf = 0;
1212 s->bi_valid = 0;
1214 s->bits_sent = (s->bits_sent+7) & ~7;
1222 local void copy_block(s, buf, len, header) in copy_block() argument
1223 deflate_state *s; in copy_block()
1228 bi_windup(s); /* align on byte boundary */
1229 s->last_eob_len = 8; /* enough lookahead for inflate */
1232 put_short(s, (ush)len);
1233 put_short(s, (ush)~len);
1235 s->bits_sent += 2*16;
1239 s->bits_sent += (ulg)len<<3;
1242 put_byte(s, *buf++);