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

Function scan_tree

extern/zlib/src/trees.c:710–745  ·  view source on GitHub ↗

=========================================================================== * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */

Source from the content-addressed store, hash-verified

708 * in the bit length tree.
709 */
710local void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
711 int n; /* iterates over all tree elements */
712 int prevlen = -1; /* last emitted length */
713 int curlen; /* length of current code */
714 int nextlen = tree[0].Len; /* length of next code */
715 int count = 0; /* repeat count of the current code */
716 int max_count = 7; /* max repeat count */
717 int min_count = 4; /* min repeat count */
718
719 if (nextlen == 0) max_count = 138, min_count = 3;
720 tree[max_code + 1].Len = (ush)0xffff; /* guard */
721
722 for (n = 0; n <= max_code; n++) {
723 curlen = nextlen; nextlen = tree[n + 1].Len;
724 if (++count < max_count && curlen == nextlen) {
725 continue;
726 } else if (count < min_count) {
727 s->bl_tree[curlen].Freq += count;
728 } else if (curlen != 0) {
729 if (curlen != prevlen) s->bl_tree[curlen].Freq++;
730 s->bl_tree[REP_3_6].Freq++;
731 } else if (count <= 10) {
732 s->bl_tree[REPZ_3_10].Freq++;
733 } else {
734 s->bl_tree[REPZ_11_138].Freq++;
735 }
736 count = 0; prevlen = curlen;
737 if (nextlen == 0) {
738 max_count = 138, min_count = 3;
739 } else if (curlen == nextlen) {
740 max_count = 6, min_count = 3;
741 } else {
742 max_count = 7, min_count = 4;
743 }
744 }
745}
746
747/* ===========================================================================
748 * Send a literal or distance tree in compressed form, using the codes in

Callers 1

build_bl_treeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected