=========================================================================== * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */
| 688 | * in the bit length tree. |
| 689 | */ |
| 690 | local void scan_tree(deflate_state *s, ct_data *tree, int max_code) |
| 691 | { |
| 692 | int n; /* iterates over all tree elements */ |
| 693 | int prevlen = -1; /* last emitted length */ |
| 694 | int curlen; /* length of current code */ |
| 695 | int nextlen = tree[0].Len; /* length of next code */ |
| 696 | int count = 0; /* repeat count of the current code */ |
| 697 | int max_count = 7; /* max repeat count */ |
| 698 | int min_count = 4; /* min repeat count */ |
| 699 | |
| 700 | if (nextlen == 0) max_count = 138, min_count = 3; |
| 701 | tree[max_code+1].Len = (ush)0xffff; /* guard */ |
| 702 | |
| 703 | for (n = 0; n <= max_code; n++) { |
| 704 | curlen = nextlen; nextlen = tree[n+1].Len; |
| 705 | if (++count < max_count && curlen == nextlen) { |
| 706 | continue; |
| 707 | } else if (count < min_count) { |
| 708 | s->bl_tree[curlen].Freq += count; |
| 709 | } else if (curlen != 0) { |
| 710 | if (curlen != prevlen) s->bl_tree[curlen].Freq++; |
| 711 | s->bl_tree[REP_3_6].Freq++; |
| 712 | } else if (count <= 10) { |
| 713 | s->bl_tree[REPZ_3_10].Freq++; |
| 714 | } else { |
| 715 | s->bl_tree[REPZ_11_138].Freq++; |
| 716 | } |
| 717 | count = 0; prevlen = curlen; |
| 718 | if (nextlen == 0) { |
| 719 | max_count = 138, min_count = 3; |
| 720 | } else if (curlen == nextlen) { |
| 721 | max_count = 6, min_count = 3; |
| 722 | } else { |
| 723 | max_count = 7, min_count = 4; |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | /* =========================================================================== |
| 729 | * Send a literal or distance tree in compressed form, using the codes in |