MCPcopy Create free account
hub / github.com/hoothin/UserScripts / compress_block

Function compress_block

Picviewer CE+/dist.user.js:10968–11017  ·  view source on GitHub ↗
(s, ltree, dtree)

Source from the content-addressed store, hash-verified

10966 * Send the block data compressed using the given Huffman trees
10967 */
10968function compress_block(s, ltree, dtree)
10969// deflate_state *s;
10970// const ct_data *ltree; /* literal tree */
10971// const ct_data *dtree; /* distance tree */
10972{
10973 var dist; /* distance of matched string */
10974 var lc; /* match length or unmatched char (if dist == 0) */
10975 var lx = 0; /* running index in l_buf */
10976 var code; /* the code to send */
10977 var extra; /* number of extra bits to send */
10978
10979 if (s.last_lit !== 0) {
10980 do {
10981 dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
10982 lc = s.pending_buf[s.l_buf + lx];
10983 lx++;
10984
10985 if (dist === 0) {
10986 send_code(s, lc, ltree); /* send a literal byte */
10987 //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
10988 } else {
10989 /* Here, lc is the match length - MIN_MATCH */
10990 code = _length_code[lc];
10991 send_code(s, code + LITERALS + 1, ltree); /* send the length code */
10992 extra = extra_lbits[code];
10993 if (extra !== 0) {
10994 lc -= base_length[code];
10995 send_bits(s, lc, extra); /* send the extra length bits */
10996 }
10997 dist--; /* dist is now the match distance - 1 */
10998 code = d_code(dist);
10999 //Assert (code < D_CODES, "bad d_code");
11000
11001 send_code(s, code, dtree); /* send the distance code */
11002 extra = extra_dbits[code];
11003 if (extra !== 0) {
11004 dist -= base_dist[code];
11005 send_bits(s, dist, extra); /* send the extra distance bits */
11006 }
11007 } /* literal or match pair ? */
11008
11009 /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
11010 //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
11011 // "pendingBuf overflow");
11012
11013 } while (lx < s.last_lit);
11014 }
11015
11016 send_code(s, END_BLOCK, ltree);
11017}
11018
11019
11020/* ===========================================================================

Callers 1

_tr_flush_blockFunction · 0.70

Calls 3

send_codeFunction · 0.70
send_bitsFunction · 0.70
d_codeFunction · 0.70

Tested by

no test coverage detected