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

Function build_bl_tree

Picviewer CE+/dist.user.js:11261–11289  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

11259 * bl_order of the last bit length code to send.
11260 */
11261function build_bl_tree(s) {
11262 var max_blindex; /* index of last bit length code of non zero freq */
11263
11264 /* Determine the bit length frequencies for literal and distance trees */
11265 scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
11266 scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
11267
11268 /* Build the bit length tree: */
11269 build_tree(s, s.bl_desc);
11270 /* opt_len now includes the length of the tree representations, except
11271 * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
11272 */
11273
11274 /* Determine the number of bit length codes to send. The pkzip format
11275 * requires that at least 4 bit length codes be sent. (appnote.txt says
11276 * 3 but the actual value used is 4.)
11277 */
11278 for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
11279 if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) {
11280 break;
11281 }
11282 }
11283 /* Update opt_len to include the bit length tree and counts */
11284 s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
11285 //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
11286 // s->opt_len, s->static_len));
11287
11288 return max_blindex;
11289}
11290
11291
11292/* ===========================================================================

Callers 1

_tr_flush_blockFunction · 0.70

Calls 2

scan_treeFunction · 0.70
build_treeFunction · 0.70

Tested by

no test coverage detected