Esempio n. 1
0
        private UInt32[] CalculateHuffmanCode()
        {
            UInt32[] array  = new UInt32[17];
            Byte[]   array2 = this.codeLengthArray;
            for (Int32 i = 0; i < (Int32)array2.Length; i++)
            {
                Int32 num = (Int32)array2[i];
                array[num] += 1u;
            }
            array[0] = 0u;
            UInt32[] array3 = new UInt32[17];
            UInt32   num2   = 0u;

            for (Int32 j = 1; j <= 16; j++)
            {
                num2      = num2 + array[j - 1] << 1;
                array3[j] = num2;
            }
            UInt32[] array4 = new UInt32[288];
            for (Int32 k = 0; k < (Int32)this.codeLengthArray.Length; k++)
            {
                Int32 num3 = (Int32)this.codeLengthArray[k];
                if (num3 > 0)
                {
                    array4[k]     = FastEncoderStatics.BitReverse(array3[num3], num3);
                    array3[num3] += 1u;
                }
            }
            return(array4);
        }
Esempio n. 2
0
        // Calculate the huffman code for each character based on the code length for each character.
        // This algorithm is described in standard RFC 1951
        private uint[] CalculateHuffmanCode()
        {
            var bitLengthCount = new uint[17];

            foreach (int codeLength in codeLengthArray)
            {
                bitLengthCount[codeLength]++;
            }
            bitLengthCount[0] = 0;             // clear count for length 0

            var  nextCode = new uint[17];
            uint tempCode = 0;

            for (var bits = 1; bits <= 16; bits++)
            {
                tempCode       = (tempCode + bitLengthCount[bits - 1]) << 1;
                nextCode[bits] = tempCode;
            }

            var code = new uint[MaxLiteralTreeElements];

            for (var i = 0; i < codeLengthArray.Length; i++)
            {
                int len = codeLengthArray[i];

                if (len > 0)
                {
                    code[i] = FastEncoderStatics.BitReverse(nextCode[len], len);
                    nextCode[len]++;
                }
            }
            return(code);
        }
Esempio n. 3
0
        private uint[] CalculateHuffmanCode()
        {
            uint[] array  = new uint[17];
            byte[] array2 = this.codeLengthArray;
            for (int i = 0; i < array2.Length; i++)
            {
                int num = (int)array2[i];
                array[num] += 1u;
            }
            array[0] = 0u;
            uint[] array3 = new uint[17];
            uint   num2   = 0u;

            for (int j = 1; j <= 16; j++)
            {
                num2      = num2 + array[j - 1] << 1;
                array3[j] = num2;
            }
            uint[] array4 = new uint[288];
            for (int k = 0; k < this.codeLengthArray.Length; k++)
            {
                int num3 = (int)this.codeLengthArray[k];
                if (num3 > 0)
                {
                    array4[k]     = FastEncoderStatics.BitReverse(array3[num3], num3);
                    array3[num3] += 1u;
                }
            }
            return(array4);
        }