=========================================================================== * Send the block data compressed using the given Huffman trees */
| 999 | * Send the block data compressed using the given Huffman trees |
| 1000 | */ |
| 1001 | local void compress_block(deflate_state *s, const ct_data *ltree, const ct_data *dtree) |
| 1002 | { |
| 1003 | unsigned dist; /* distance of matched string */ |
| 1004 | int lc; /* match length or unmatched char (if dist == 0) */ |
| 1005 | unsigned sx = 0; /* running index in sym_buf */ |
| 1006 | unsigned code; /* the code to send */ |
| 1007 | int extra; /* number of extra bits to send */ |
| 1008 | |
| 1009 | if (s->sym_next != 0) do { |
| 1010 | dist = s->sym_buf[sx++] & 0xff; |
| 1011 | dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; |
| 1012 | lc = s->sym_buf[sx++]; |
| 1013 | if (dist == 0) { |
| 1014 | send_code(s, lc, ltree); /* send a literal byte */ |
| 1015 | Tracecv(isgraph(lc), (stderr," '%c' ", lc)); |
| 1016 | } else { |
| 1017 | /* Here, lc is the match length - MIN_MATCH */ |
| 1018 | code = _length_code[lc]; |
| 1019 | send_code(s, code+LITERALS+1, ltree); /* send the length code */ |
| 1020 | extra = extra_lbits[code]; |
| 1021 | if (extra != 0) { |
| 1022 | lc -= base_length[code]; |
| 1023 | send_bits(s, lc, extra); /* send the extra length bits */ |
| 1024 | } |
| 1025 | dist--; /* dist is now the match distance - 1 */ |
| 1026 | code = d_code(dist); |
| 1027 | Assert (code < D_CODES, "bad d_code"); |
| 1028 | |
| 1029 | send_code(s, code, dtree); /* send the distance code */ |
| 1030 | extra = extra_dbits[code]; |
| 1031 | if (extra != 0) { |
| 1032 | dist -= base_dist[code]; |
| 1033 | send_bits(s, dist, extra); /* send the extra distance bits */ |
| 1034 | } |
| 1035 | } /* literal or match pair ? */ |
| 1036 | |
| 1037 | /* Check that the overlay between pending_buf and sym_buf is ok: */ |
| 1038 | Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); |
| 1039 | |
| 1040 | } while (sx < s->sym_next); |
| 1041 | |
| 1042 | send_code(s, END_BLOCK, ltree); |
| 1043 | } |
| 1044 | |
| 1045 | /* =========================================================================== |
| 1046 | * Check if the data type is TEXT or BINARY, using the following algorithm: |