=========================================================================== * Send a literal or distance tree in compressed form, using the codes in * bl_tree. */
(s, tree, max_code)
| 746 | * bl_tree. |
| 747 | */ |
| 748 | local void send_tree (s, tree, max_code) |
| 749 | deflate_state *s; |
| 750 | ct_data *tree; /* the tree to be scanned */ |
| 751 | int max_code; /* and its largest code of non zero frequency */ |
| 752 | { |
| 753 | int n; /* iterates over all tree elements */ |
| 754 | int prevlen = -1; /* last emitted length */ |
| 755 | int curlen; /* length of current code */ |
| 756 | int nextlen = tree[0].Len; /* length of next code */ |
| 757 | int count = 0; /* repeat count of the current code */ |
| 758 | int max_count = 7; /* max repeat count */ |
| 759 | int min_count = 4; /* min repeat count */ |
| 760 | |
| 761 | /* tree[max_code+1].Len = -1; */ /* guard already set */ |
| 762 | if (nextlen == 0) max_count = 138, min_count = 3; |
| 763 | |
| 764 | for (n = 0; n <= max_code; n++) { |
| 765 | curlen = nextlen; nextlen = tree[n+1].Len; |
| 766 | if (++count < max_count && curlen == nextlen) { |
| 767 | continue; |
| 768 | } else if (count < min_count) { |
| 769 | do { send_code(s, curlen, s->bl_tree); } while (--count != 0); |
| 770 | |
| 771 | } else if (curlen != 0) { |
| 772 | if (curlen != prevlen) { |
| 773 | send_code(s, curlen, s->bl_tree); count--; |
| 774 | } |
| 775 | Assert(count >= 3 && count <= 6, " 3_6?"); |
| 776 | send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); |
| 777 | |
| 778 | } else if (count <= 10) { |
| 779 | send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); |
| 780 | |
| 781 | } else { |
| 782 | send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); |
| 783 | } |
| 784 | count = 0; prevlen = curlen; |
| 785 | if (nextlen == 0) { |
| 786 | max_count = 138, min_count = 3; |
| 787 | } else if (curlen == nextlen) { |
| 788 | max_count = 6, min_count = 3; |
| 789 | } else { |
| 790 | max_count = 7, min_count = 4; |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | /* =========================================================================== |
| 796 | * Construct the Huffman tree for the bit lengths and return the index in |
no test coverage detected