Compression Source Code
Version 1.10 12/01/02 H-25
STATIC
VOID
MakeLen (
IN INT32 Root
)
/*++
Routine Description:
Create code length array for a Huffman tree
Arguments:
Root - the root of the tree
--*/
{
INT32 i, k;
UINT32 Cum;
for (i = 0; i <= 16; i++) {
mLenCnt[i] = 0;
}
CountLen(Root);
//
// Adjust the length count array so that
// no code will be generated longer than the designated length
//
Cum = 0;
for (i = 16; i > 0; i--) {
Cum += mLenCnt[i] << (16 - i);
}
while (Cum != (1U << 16)) {
mLenCnt[16]--;
for (i = 15; i > 0; i--) {
if (mLenCnt[i] != 0) {
mLenCnt[i]--;
mLenCnt[i+1] += 2;
break;
}
}
Cum--;
}
for (i = 16; i > 0; i--) {
k = mLenCnt[i];
while (--k >= 0) {
mLen[*mSortPtr++] = (UINT8)i;
}
}
}