=========================================================================== * Send the block data compressed using the given Huffman trees */
(s, ltree, dtree)
| 1062 | * Send the block data compressed using the given Huffman trees |
| 1063 | */ |
| 1064 | local void compress_block(s, ltree, dtree) |
| 1065 | deflate_state *s; |
| 1066 | const ct_data *ltree; /* literal tree */ |
| 1067 | const ct_data *dtree; /* distance tree */ |
| 1068 | { |
| 1069 | unsigned dist; /* distance of matched string */ |
| 1070 | int lc; /* match length or unmatched char (if dist == 0) */ |
| 1071 | unsigned lx = 0; /* running index in l_buf */ |
| 1072 | unsigned code; /* the code to send */ |
| 1073 | int extra; /* number of extra bits to send */ |
| 1074 | |
| 1075 | if (s->last_lit != 0) do { |
| 1076 | dist = s->d_buf[lx]; |
| 1077 | lc = s->l_buf[lx++]; |
| 1078 | if (dist == 0) { |
| 1079 | send_code(s, lc, ltree); /* send a literal byte */ |
| 1080 | Tracecv(isgraph(lc), (stderr," '%c' ", lc)); |
| 1081 | } else { |
| 1082 | /* Here, lc is the match length - MIN_MATCH */ |
| 1083 | code = _length_code[lc]; |
| 1084 | send_code(s, code+LITERALS+1, ltree); /* send the length code */ |
| 1085 | extra = extra_lbits[code]; |
| 1086 | if (extra != 0) { |
| 1087 | lc -= base_length[code]; |
| 1088 | send_bits(s, lc, extra); /* send the extra length bits */ |
| 1089 | } |
| 1090 | dist--; /* dist is now the match distance - 1 */ |
| 1091 | code = d_code(dist); |
| 1092 | Assert (code < D_CODES, "bad d_code"); |
| 1093 | |
| 1094 | send_code(s, code, dtree); /* send the distance code */ |
| 1095 | extra = extra_dbits[code]; |
| 1096 | if (extra != 0) { |
| 1097 | dist -= (unsigned)base_dist[code]; |
| 1098 | send_bits(s, dist, extra); /* send the extra distance bits */ |
| 1099 | } |
| 1100 | } /* literal or match pair ? */ |
| 1101 | |
| 1102 | /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ |
| 1103 | Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, |
| 1104 | "pendingBuf overflow"); |
| 1105 | |
| 1106 | } while (lx < s->last_lit); |
| 1107 | |
| 1108 | send_code(s, END_BLOCK, ltree); |
| 1109 | } |
| 1110 | |
| 1111 | /* =========================================================================== |
| 1112 | * Check if the data type is TEXT or BINARY, using the following algorithm: |