Lines Matching refs:s

143 local void init_block     OF((deflate_state *s));
144 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
145 local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
147 local void build_tree OF((deflate_state *s, tree_desc *desc));
148 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
149 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
150 local int build_bl_tree OF((deflate_state *s));
151 local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
153 local void compress_block OF((deflate_state *s, ct_data *ltree,
155 local void set_data_type OF((deflate_state *s));
157 local void bi_windup OF((deflate_state *s));
158 local void bi_flush OF((deflate_state *s));
159 local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
167 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) argument
171 # define send_code(s, c, tree) \ argument
173 send_bits(s, tree[c].Code, tree[c].Len); }
180 #define put_short(s, w) { \ argument
181 put_byte(s, (uch)((w) & 0xff)); \
182 put_byte(s, (uch)((ush)(w) >> 8)); \
190 local void send_bits OF((deflate_state *s, int value, int length));
192 local void send_bits(s, value, length) in send_bits() argument
193 deflate_state *s; in send_bits()
199 s->bits_sent += (ulg)length;
205 if (s->bi_valid > (int)Buf_size - length) {
206 s->bi_buf |= (value << s->bi_valid);
207 put_short(s, s->bi_buf);
208 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
209 s->bi_valid += length - Buf_size;
211 s->bi_buf |= value << s->bi_valid;
212 s->bi_valid += length;
217 #define send_bits(s, value, length) \ argument
219 if (s->bi_valid > (int)Buf_size - len) {\
221 s->bi_buf |= (val << s->bi_valid);\
222 put_short(s, s->bi_buf);\
223 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
224 s->bi_valid += len - Buf_size;\
226 s->bi_buf |= (value) << s->bi_valid;\
227 s->bi_valid += len;\
382 void _tr_init(s) in _tr_init() argument
383 deflate_state *s; in _tr_init()
387 s->l_desc.dyn_tree = s->dyn_ltree;
388 s->l_desc.stat_desc = &static_l_desc;
390 s->d_desc.dyn_tree = s->dyn_dtree;
391 s->d_desc.stat_desc = &static_d_desc;
393 s->bl_desc.dyn_tree = s->bl_tree;
394 s->bl_desc.stat_desc = &static_bl_desc;
396 s->bi_buf = 0;
397 s->bi_valid = 0;
398 s->last_eob_len = 8; /* enough lookahead for inflate */
400 s->compressed_len = 0L;
401 s->bits_sent = 0L;
405 init_block(s);
411 local void init_block(s) in init_block() argument
412 deflate_state *s; in init_block()
417 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
418 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
419 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
421 s->dyn_ltree[END_BLOCK].Freq = 1;
422 s->opt_len = s->static_len = 0L;
423 s->last_lit = s->matches = 0;
434 #define pqremove(s, tree, top) \ argument
436 top = s->heap[SMALLEST]; \
437 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
438 pqdownheap(s, tree, SMALLEST); \
455 local void pqdownheap(s, tree, k) in pqdownheap() argument
456 deflate_state *s; in pqdownheap()
460 int v = s->heap[k];
462 while (j <= s->heap_len) {
464 if (j < s->heap_len &&
465 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
469 if (smaller(tree, v, s->heap[j], s->depth)) break;
472 s->heap[k] = s->heap[j]; k = j;
477 s->heap[k] = v;
490 local void gen_bitlen(s, desc) in gen_bitlen() argument
491 deflate_state *s; in gen_bitlen()
507 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
512 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
514 for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
515 n = s->heap[h];
523 s->bl_count[bits]++;
527 s->opt_len += (ulg)f * (bits + xbits);
528 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
538 while (s->bl_count[bits] == 0) bits--;
539 s->bl_count[bits]--; /* move one leaf down the tree */
540 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
541 s->bl_count[max_length]--;
554 n = s->bl_count[bits];
556 m = s->heap[--h];
560 s->opt_len += ((long)bits - (long)tree[m].Len)
619 local void build_tree(s, desc) in build_tree() argument
620 deflate_state *s; in build_tree()
634 s->heap_len = 0, s->heap_max = HEAP_SIZE;
638 s->heap[++(s->heap_len)] = max_code = n;
639 s->depth[n] = 0;
650 while (s->heap_len < 2) {
651 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
653 s->depth[node] = 0;
654 s->opt_len--; if (stree) s->static_len -= stree[node].Len;
662 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
669 pqremove(s, tree, n); /* n = node of least frequency */
670 m = s->heap[SMALLEST]; /* m = node of next least frequency */
672 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
673 s->heap[--(s->heap_max)] = m;
677 s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
678 s->depth[n] : s->depth[m]) + 1);
681 if (tree == s->bl_tree) {
687 s->heap[SMALLEST] = node++;
688 pqdownheap(s, tree, SMALLEST);
690 } while (s->heap_len >= 2);
692 s->heap[--(s->heap_max)] = s->heap[SMALLEST];
697 gen_bitlen(s, (tree_desc *)desc);
700 gen_codes ((ct_data *)tree, max_code, s->bl_count);
707 local void scan_tree (s, tree, max_code) in scan_tree() argument
708 deflate_state *s; in scan_tree()
728 s->bl_tree[curlen].Freq += count;
730 if (curlen != prevlen) s->bl_tree[curlen].Freq++;
731 s->bl_tree[REP_3_6].Freq++;
733 s->bl_tree[REPZ_3_10].Freq++;
735 s->bl_tree[REPZ_11_138].Freq++;
752 local void send_tree (s, tree, max_code) in send_tree() argument
753 deflate_state *s; in send_tree()
773 do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
777 send_code(s, curlen, s->bl_tree); count--;
780 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
783 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
786 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
803 local int build_bl_tree(s) in build_bl_tree() argument
804 deflate_state *s; in build_bl_tree()
809 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
810 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
813 build_tree(s, (tree_desc *)(&(s->bl_desc)));
823 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
826 s->opt_len += 3*(max_blindex+1) + 5+5+4;
828 s->opt_len, s->static_len));
838 local void send_all_trees(s, lcodes, dcodes, blcodes) in send_all_trees() argument
839 deflate_state *s; in send_all_trees()
848 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
849 send_bits(s, dcodes-1, 5);
850 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
853 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
855 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
857 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
858 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
860 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
861 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
867 void _tr_stored_block(s, buf, stored_len, eof) in _tr_stored_block() argument
868 deflate_state *s; in _tr_stored_block()
873 send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
875 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
876 s->compressed_len += (stored_len + 4) << 3;
878 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
892 void _tr_align(s) in _tr_align() argument
893 deflate_state *s; in _tr_align()
895 send_bits(s, STATIC_TREES<<1, 3);
896 send_code(s, END_BLOCK, static_ltree);
898 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
900 bi_flush(s);
906 if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
907 send_bits(s, STATIC_TREES<<1, 3);
908 send_code(s, END_BLOCK, static_ltree);
910 s->compressed_len += 10L;
912 bi_flush(s);
914 s->last_eob_len = 7;
921 void _tr_flush_block(s, buf, stored_len, eof) in _tr_flush_block() argument
922 deflate_state *s; in _tr_flush_block()
931 if (s->level > 0) {
934 if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
935 set_data_type(s);
938 build_tree(s, (tree_desc *)(&(s->l_desc)));
939 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
940 s->static_len));
942 build_tree(s, (tree_desc *)(&(s->d_desc)));
943 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
944 s->static_len));
952 max_blindex = build_bl_tree(s);
955 opt_lenb = (s->opt_len+3+7)>>3;
956 static_lenb = (s->static_len+3+7)>>3;
959 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
960 s->last_lit));
981 _tr_stored_block(s, buf, stored_len, eof);
986 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
988 send_bits(s, (STATIC_TREES<<1)+eof, 3);
989 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
991 s->compressed_len += 3 + s->static_len;
994 send_bits(s, (DYN_TREES<<1)+eof, 3);
995 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
997 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
999 s->compressed_len += 3 + s->opt_len;
1002 Assert (s->compressed_len == s->bits_sent, "bad compressed size");
1006 init_block(s);
1009 bi_windup(s);
1011 s->compressed_len += 7; /* align on byte boundary */
1014 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
1015 s->compressed_len-7*eof));
1022 int _tr_tally (s, dist, lc) in _tr_tally() argument
1023 deflate_state *s; in _tr_tally()
1027 s->d_buf[s->last_lit] = (ush)dist;
1028 s->l_buf[s->last_lit++] = (uch)lc;
1031 s->dyn_ltree[lc].Freq++;
1033 s->matches++;
1036 Assert((ush)dist < (ush)MAX_DIST(s) &&
1040 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
1041 s->dyn_dtree[d_code(dist)].Freq++;
1046 if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
1048 ulg out_length = (ulg)s->last_lit*8L;
1049 ulg in_length = (ulg)((long)s->strstart - s->block_start);
1052 out_length += (ulg)s->dyn_dtree[dcode].Freq *
1057 s->last_lit, in_length, out_length,
1059 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
1062 return (s->last_lit == s->lit_bufsize-1);
1072 local void compress_block(s, ltree, dtree) in compress_block() argument
1073 deflate_state *s; in compress_block()
1083 if (s->last_lit != 0) do {
1084 dist = s->d_buf[lx];
1085 lc = s->l_buf[lx++];
1087 send_code(s, lc, ltree); /* send a literal byte */
1092 send_code(s, code+LITERALS+1, ltree); /* send the length code */
1096 send_bits(s, lc, extra); /* send the extra length bits */
1102 send_code(s, code, dtree); /* send the distance code */
1106 send_bits(s, dist, extra); /* send the extra distance bits */
1111 Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
1114 } while (lx < s->last_lit);
1116 send_code(s, END_BLOCK, ltree);
1117 s->last_eob_len = ltree[END_BLOCK].Len;
1126 local void set_data_type(s) in set_data_type() argument
1127 deflate_state *s; in set_data_type()
1132 if (s->dyn_ltree[n].Freq != 0)
1136 if (s->dyn_ltree[n].Freq != 0)
1138 s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
1161 local void bi_flush(s) in bi_flush() argument
1162 deflate_state *s; in bi_flush()
1164 if (s->bi_valid == 16) {
1165 put_short(s, s->bi_buf);
1166 s->bi_buf = 0;
1167 s->bi_valid = 0;
1168 } else if (s->bi_valid >= 8) {
1169 put_byte(s, (Byte)s->bi_buf);
1170 s->bi_buf >>= 8;
1171 s->bi_valid -= 8;
1178 local void bi_windup(s) in bi_windup() argument
1179 deflate_state *s; in bi_windup()
1181 if (s->bi_valid > 8) {
1182 put_short(s, s->bi_buf);
1183 } else if (s->bi_valid > 0) {
1184 put_byte(s, (Byte)s->bi_buf);
1186 s->bi_buf = 0;
1187 s->bi_valid = 0;
1189 s->bits_sent = (s->bits_sent+7) & ~7;
1197 local void copy_block(s, buf, len, header) in copy_block() argument
1198 deflate_state *s; in copy_block()
1203 bi_windup(s); /* align on byte boundary */
1204 s->last_eob_len = 8; /* enough lookahead for inflate */
1207 put_short(s, (ush)len);
1208 put_short(s, (ush)~len);
1210 s->bits_sent += 2*16;
1214 s->bits_sent += (ulg)len<<3;
1217 put_byte(s, *buf++);