MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / tr_static_init

Function tr_static_init

extern/zlib/src/trees.c:294–373  ·  view source on GitHub ↗

=========================================================================== * Initialize the various 'constant' tables. */

Source from the content-addressed store, hash-verified

292 * Initialize the various 'constant' tables.
293 */
294local void tr_static_init(void) {
295#if defined(GEN_TREES_H) || !defined(STDC)
296 static int static_init_done = 0;
297 int n; /* iterates over tree elements */
298 int bits; /* bit counter */
299 int length; /* length value */
300 int code; /* code value */
301 int dist; /* distance index */
302 ush bl_count[MAX_BITS+1];
303 /* number of codes at each bit length for an optimal tree */
304
305 if (static_init_done) return;
306
307 /* For some embedded targets, global variables are not initialized: */
308#ifdef NO_INIT_GLOBAL_POINTERS
309 static_l_desc.static_tree = static_ltree;
310 static_l_desc.extra_bits = extra_lbits;
311 static_d_desc.static_tree = static_dtree;
312 static_d_desc.extra_bits = extra_dbits;
313 static_bl_desc.extra_bits = extra_blbits;
314#endif
315
316 /* Initialize the mapping length (0..255) -> length code (0..28) */
317 length = 0;
318 for (code = 0; code < LENGTH_CODES-1; code++) {
319 base_length[code] = length;
320 for (n = 0; n < (1 << extra_lbits[code]); n++) {
321 _length_code[length++] = (uch)code;
322 }
323 }
324 Assert (length == 256, "tr_static_init: length != 256");
325 /* Note that the length 255 (match length 258) can be represented
326 * in two different ways: code 284 + 5 bits or code 285, so we
327 * overwrite length_code[255] to use the best encoding:
328 */
329 _length_code[length - 1] = (uch)code;
330
331 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
332 dist = 0;
333 for (code = 0 ; code < 16; code++) {
334 base_dist[code] = dist;
335 for (n = 0; n < (1 << extra_dbits[code]); n++) {
336 _dist_code[dist++] = (uch)code;
337 }
338 }
339 Assert (dist == 256, "tr_static_init: dist != 256");
340 dist >>= 7; /* from now on, all distances are divided by 128 */
341 for ( ; code < D_CODES; code++) {
342 base_dist[code] = dist << 7;
343 for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
344 _dist_code[256 + dist++] = (uch)code;
345 }
346 }
347 Assert (dist == 256, "tr_static_init: 256 + dist != 512");
348
349 /* Construct the codes of the static literal tree */
350 for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
351 n = 0;

Callers 1

_tr_initFunction · 0.85

Calls 3

gen_codesFunction · 0.85
bi_reverseFunction · 0.85
gen_trees_headerFunction · 0.85

Tested by

no test coverage detected