=========================================================================== * Send the block data compressed using the given Huffman trees */
| 896 | * Send the block data compressed using the given Huffman trees |
| 897 | */ |
| 898 | local void compress_block(deflate_state *s, const ct_data *ltree, |
| 899 | const ct_data *dtree) { |
| 900 | unsigned dist; /* distance of matched string */ |
| 901 | int lc; /* match length or unmatched char (if dist == 0) */ |
| 902 | unsigned sx = 0; /* running index in symbol buffers */ |
| 903 | unsigned code; /* the code to send */ |
| 904 | int extra; /* number of extra bits to send */ |
| 905 | |
| 906 | if (s->sym_next != 0) do { |
| 907 | #ifdef LIT_MEM |
| 908 | dist = s->d_buf[sx]; |
| 909 | lc = s->l_buf[sx++]; |
| 910 | #else |
| 911 | dist = s->sym_buf[sx++] & 0xff; |
| 912 | dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; |
| 913 | lc = s->sym_buf[sx++]; |
| 914 | #endif |
| 915 | if (dist == 0) { |
| 916 | send_code(s, lc, ltree); /* send a literal byte */ |
| 917 | Tracecv(isgraph(lc), (stderr," '%c' ", lc)); |
| 918 | } else { |
| 919 | /* Here, lc is the match length - MIN_MATCH */ |
| 920 | code = _length_code[lc]; |
| 921 | send_code(s, code + LITERALS + 1, ltree); /* send length code */ |
| 922 | extra = extra_lbits[code]; |
| 923 | if (extra != 0) { |
| 924 | lc -= base_length[code]; |
| 925 | send_bits(s, lc, extra); /* send the extra length bits */ |
| 926 | } |
| 927 | dist--; /* dist is now the match distance - 1 */ |
| 928 | code = d_code(dist); |
| 929 | Assert (code < D_CODES, "bad d_code"); |
| 930 | |
| 931 | send_code(s, code, dtree); /* send the distance code */ |
| 932 | extra = extra_dbits[code]; |
| 933 | if (extra != 0) { |
| 934 | dist -= (unsigned)base_dist[code]; |
| 935 | send_bits(s, dist, extra); /* send the extra distance bits */ |
| 936 | } |
| 937 | } /* literal or match pair ? */ |
| 938 | |
| 939 | /* Check for no overlay of pending_buf on needed symbols */ |
| 940 | #ifdef LIT_MEM |
| 941 | Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); |
| 942 | #else |
| 943 | Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); |
| 944 | #endif |
| 945 | |
| 946 | } while (sx < s->sym_next); |
| 947 | |
| 948 | send_code(s, END_BLOCK, ltree); |
| 949 | } |
| 950 | |
| 951 | /* =========================================================================== |
| 952 | * Check if the data type is TEXT or BINARY, using the following algorithm: |