Ejemplo n.º 1
0
 public Tree(DeflaterHuffman dh, int elems, int minCodes, int maxLength)
 {
     this.dh          = dh;
     this.minNumCodes = minCodes;
     this.maxLength   = maxLength;
     freqs            = new short[elems];
     bl_counts        = new int[maxLength];
 }
Ejemplo n.º 2
0
			public Tree(DeflaterHuffman dh, int elems, int minCodes, int maxLength) 
			{
				this.dh =  dh;
				this.minNumCodes = minCodes;
				this.maxLength  = maxLength;
				freqs  = new short[elems];
				bl_counts = new int[maxLength];
			}
Ejemplo n.º 3
0
 public DeflaterEngine(DeflaterPending pending)
 {
     this.pending = pending;
     huffman      = new DeflaterHuffman(pending);
     adler        = new Adler32();
     window       = new byte[65536];
     head         = new short[32768];
     prev         = new short[32768];
     blockStart   = (strstart = 1);
 }
Ejemplo n.º 4
0
 public DeflaterEngine(DeflaterPending pending)
 {
     this.pending    = pending;
     this.huffman    = new DeflaterHuffman(pending);
     this.adler      = new Adler32();
     this.window     = new byte[0x10000];
     this.head       = new short[0x8000];
     this.prev       = new short[0x8000];
     this.blockStart = this.strstart = 1;
 }
Ejemplo n.º 5
0
 public DeflaterEngine(DeflaterPending pending)
 {
     this.pending = pending;
     this.huffman = new DeflaterHuffman(pending);
     this.adler = new Adler32();
     this.window = new byte[65536];
     this.head = new short[32768];
     this.prev = new short[32768];
     this.blockStart = (this.strstart = 1);
 }
Ejemplo n.º 6
0
		/// <summary>
		/// Construct instance with pending buffer
		/// </summary>
		/// <param name="pending">
		/// Pending buffer to use
		/// </param>>
		public DeflaterEngine(DeflaterPending pending) 
		{
			this.pending = pending;
			huffman = new DeflaterHuffman(pending);
			adler = new Adler32();
			
			window = new byte[2 * WSIZE];
			head   = new short[HASH_SIZE];
			prev   = new short[WSIZE];
			blockStart = strstart = 1;
		}
Ejemplo n.º 7
0
        public DeflaterEngine(DeflaterPending pending)
        {
            this.pending = pending;
            huffman      = new DeflaterHuffman(pending);
            adler        = new Adler32();

            window = new byte[2 * WSIZE];
            head   = new short[HASH_SIZE];
            prev   = new short[WSIZE];

            blockStart = strstart = 1;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Construct instance with pending buffer
        /// </summary>
        /// <param name="pending">
        /// Pending buffer to use
        /// </param>>
        public DeflaterEngine(DeflaterPending pending) {
            this.pending=pending;
            huffman=new DeflaterHuffman(pending);
            adler=new Adler32();

            window=new byte[2*WSIZE];
            head=new short[HASH_SIZE];
            prev=new short[WSIZE];

            // We start at index 1, to avoid an implementation deficiency, that
            // we cannot build a repeat pattern at index 0.
            blockStart=strstart=1;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Construct instance with pending buffer
        /// </summary>
        /// <param name="pending">
        /// Pending buffer to use
        /// </param>
        /// <param name="noAdlerCalculation">
        /// If no adler calculation should be performed
        /// </param>
        public DeflaterEngine(DeflaterPending pending, bool noAdlerCalculation)
        {
            this.pending = pending;
            huffman      = new DeflaterHuffman(pending);
            if (!noAdlerCalculation)
            {
                adler = new Adler32();
            }

            window = new byte[2 * DeflaterConstants.WSIZE];
            head   = new short[DeflaterConstants.HASH_SIZE];
            prev   = new short[DeflaterConstants.WSIZE];

            // We start at index 1, to avoid an implementation deficiency, that
            // we cannot build a repeat pattern at index 0.
            blockStart = strstart = 1;
        }
Ejemplo n.º 10
0
            public Tree(DeflaterHuffman dh, int elems, int minCodes, int maxLength)
            {
                this.dh          = dh;
                this.minNumCodes = minCodes;
                this.maxLength   = maxLength;
                freqs            = new short[elems];
                lengthbuff       = new byte[freqs.Length];

                heap       = new int[elems];
                childsbuff = new int[elems * 4];
                childslen  = 0;

                valuesbuff = new int[elems * 2];
                valueslen  = 0;

                bl_counts = new int[maxLength];
            }
Ejemplo n.º 11
0
            public void BuildCodes()
            {
                int[] array = new int[this.maxLength];
                int   num   = 0;

                this.codes = new short[this.freqs.Length];
                for (int i = 0; i < this.maxLength; i++)
                {
                    array[i] = num;
                    num     += this.bl_counts[i] << 15 - i;
                }
                for (int j = 0; j < this.numCodes; j++)
                {
                    int num2 = (int)this.length[j];
                    if (num2 > 0)
                    {
                        this.codes[j]    = DeflaterHuffman.BitReverse(array[num2 - 1]);
                        array[num2 - 1] += 1 << 16 - num2;
                    }
                }
            }
Ejemplo n.º 12
0
            public void BuildCodes()
            {
                int length = this.freqs.Length;

                int[] numArray = new int[this.maxLength];
                int   num      = 0;

                this.codes = new short[this.freqs.Length];
                for (int i = 0; i < this.maxLength; i++)
                {
                    numArray[i] = num;
                    num        += this.bl_counts[i] << (15 - i);
                }
                for (int j = 0; j < this.numCodes; j++)
                {
                    int num4 = this.length[j];
                    if (num4 > 0)
                    {
                        this.codes[j]       = DeflaterHuffman.BitReverse(numArray[num4 - 1]);
                        numArray[num4 - 1] += ((int)1) << (0x10 - num4);
                    }
                }
            }
Ejemplo n.º 13
0
        void BuildTree(byte[] codeLengths)
        {
            int[] blCount  = new int[MAX_BITLEN + 1];
            int[] nextCode = new int[MAX_BITLEN + 1];

            for (int i = 0; i < codeLengths.Length; i++)
            {
                int bits = codeLengths[i];
                if (bits > 0)
                {
                    blCount[bits]++;
                }
            }

            int code     = 0;
            int treeSize = 512;

            for (int bits = 1; bits <= MAX_BITLEN; bits++)
            {
                nextCode[bits] = code;
                code          += blCount[bits] << (16 - bits);
                if (bits >= 10)
                {
                    /* We need an extra table for bit lengths >= 10. */
                    int start = nextCode[bits] & 0x1ff80;
                    int end   = code & 0x1ff80;
                    treeSize += (end - start) >> (16 - bits);
                }
            }

/* -jr comment this out! doesnt work for dynamic trees and pkzip 2.04g
 *                      if (code != 65536)
 *                      {
 *                              throw new SharpZipBaseException("Code lengths don't add up properly.");
 *                      }
 */
            /* Now create and fill the extra tables from longest to shortest
             * bit len.  This way the sub trees will be aligned.
             */
            tree = new short[treeSize];
            int treePtr = 512;

            for (int bits = MAX_BITLEN; bits >= 10; bits--)
            {
                int end = code & 0x1ff80;
                code -= blCount[bits] << (16 - bits);
                int start = code & 0x1ff80;
                for (int i = start; i < end; i += 1 << 7)
                {
                    tree[DeflaterHuffman.BitReverse(i)] = (short)((-treePtr << 4) | bits);
                    treePtr += 1 << (bits - 9);
                }
            }

            for (int i = 0; i < codeLengths.Length; i++)
            {
                int bits = codeLengths[i];
                if (bits == 0)
                {
                    continue;
                }
                code = nextCode[bits];
                int revcode = DeflaterHuffman.BitReverse(code);
                if (bits <= 9)
                {
                    do
                    {
                        tree[revcode] = (short)((i << 4) | bits);
                        revcode      += 1 << bits;
                    } while (revcode < 512);
                }
                else
                {
                    int subTree = tree[revcode & 511];
                    int treeLen = 1 << (subTree & 15);
                    subTree = -(subTree >> 4);
                    do
                    {
                        tree[subTree | (revcode >> 9)] = (short)((i << 4) | bits);
                        revcode += 1 << bits;
                    } while (revcode < treeLen);
                }
                nextCode[bits] = code + (1 << (16 - bits));
            }
        }
Ejemplo n.º 14
0
        private unsafe void BuildTree(byte[] codeLengths)
        {
            int[] numArray  = new int[0x10];
            int[] numArray2 = new int[0x10];
            for (int i = 0; i < codeLengths.Length; i++)
            {
                int num5 = codeLengths[i];
                if (num5 > 0)
                {
                    int *numPtr1 = &(numArray[num5]);
                    numPtr1[0]++;
                }
            }
            int toReverse = 0;
            int num2      = 0x200;

            for (int j = 1; j <= 15; j++)
            {
                numArray2[j] = toReverse;
                toReverse   += numArray[j] << ((0x10 - j) & 0x1f);
                if (j >= 10)
                {
                    num2 += ((toReverse & 0x1ff80) - (numArray2[j] & 0x1ff80)) >> ((0x10 - j) & 0x1f);
                }
            }
            this.tree = new short[num2];
            int num3  = 0x200;
            int index = 15;

            while (index >= 10)
            {
                int num10 = toReverse & 0x1ff80;
                toReverse -= numArray[index] << ((0x10 - index) & 0x1f);
                int num11 = toReverse & 0x1ff80;
                while (true)
                {
                    if (num11 >= num10)
                    {
                        index--;
                        break;
                    }
                    this.tree[DeflaterHuffman.BitReverse(num11)] = (short)((-num3 << 4) | index);
                    num3  += 1 << ((index - 9) & 0x1f);
                    num11 += 0x80;
                }
            }
            for (int k = 0; k < codeLengths.Length; k++)
            {
                int num13 = codeLengths[k];
                if (num13 != 0)
                {
                    toReverse = numArray2[num13];
                    int num14 = DeflaterHuffman.BitReverse(toReverse);
                    if (num13 <= 9)
                    {
                        do
                        {
                            this.tree[num14] = (short)((k << 4) | num13);
                            num14           += 1 << (num13 & 0x1f);
                        }while (num14 < 0x200);
                    }
                    else
                    {
                        int num15 = this.tree[num14 & 0x1ff];
                        int num16 = 1 << ((num15 & 15) & 0x1f);
                        num15 = -(num15 >> 4);
                        do
                        {
                            this.tree[num15 | (num14 >> 9)] = (short)((k << 4) | num13);
                            num14 += 1 << (num13 & 0x1f);
                        }while (num14 < num16);
                    }
                    numArray2[num13] = toReverse + (1 << ((0x10 - num13) & 0x1f));
                }
            }
        }
Ejemplo n.º 15
0
        private void BuildTree(byte[] codeLengths)
        {
            int[] array  = new int[16];
            int[] array2 = new int[16];
            foreach (int num in codeLengths)
            {
                if (num > 0)
                {
                    array[num]++;
                }
            }
            int num2 = 0;
            int num3 = 512;

            for (int j = 1; j <= 15; j++)
            {
                array2[j] = num2;
                num2     += array[j] << 16 - j;
                if (j >= 10)
                {
                    int num4 = array2[j] & 0x1FF80;
                    int num5 = num2 & 0x1FF80;
                    num3 += num5 - num4 >> 16 - j;
                }
            }
            tree = new short[num3];
            int num6 = 512;

            for (int num7 = 15; num7 >= 10; num7--)
            {
                int num8 = num2 & 0x1FF80;
                num2 -= array[num7] << 16 - num7;
                for (int k = num2 & 0x1FF80; k < num8; k += 128)
                {
                    tree[DeflaterHuffman.BitReverse(k)] = (short)((-num6 << 4) | num7);
                    num6 += 1 << num7 - 9;
                }
            }
            for (int l = 0; l < codeLengths.Length; l++)
            {
                int num9 = codeLengths[l];
                if (num9 != 0)
                {
                    num2 = array2[num9];
                    int num10 = DeflaterHuffman.BitReverse(num2);
                    if (num9 <= 9)
                    {
                        do
                        {
                            tree[num10] = (short)((l << 4) | num9);
                            num10      += 1 << num9;
                        }while (num10 < 512);
                    }
                    else
                    {
                        int num11 = tree[num10 & 0x1FF];
                        int num12 = 1 << (num11 & 0xF);
                        num11 = -(num11 >> 4);
                        do
                        {
                            tree[num11 | (num10 >> 9)] = (short)((l << 4) | num9);
                            num10 += 1 << num9;
                        }while (num10 < num12);
                    }
                    array2[num9] = num2 + (1 << 16 - num9);
                }
            }
        }
		/// <summary>
		/// Construct instance with pending buffer
		/// </summary>
		/// <param name="pending">
		/// Pending buffer to use
		/// </param>>
		public DeflaterEngine(DeflaterPending pending) 
		{
			this.pending = pending;
			huffman = new DeflaterHuffman(pending);
			adler = new Adler32();
			
			window = new byte[2 * WSIZE];
			head   = new short[HASH_SIZE];
			prev   = new short[WSIZE];
			
			// We start at index 1, to avoid an implementation deficiency, that
			// we cannot build a repeat pattern at index 0.
			blockStart = strstart = 1;
		}
Ejemplo n.º 17
0
        static DeflaterHuffman()
        {
            DeflaterHuffman.BL_ORDER = new int[]
            {
                16,
                17,
                18,
                0,
                8,
                7,
                9,
                6,
                10,
                5,
                11,
                4,
                12,
                3,
                13,
                2,
                14,
                1,
                15
            };
            DeflaterHuffman.bit4Reverse = new byte[]
            {
                0,
                8,
                4,
                12,
                2,
                10,
                6,
                14,
                1,
                9,
                5,
                13,
                3,
                11,
                7,
                15
            };
            DeflaterHuffman.staticLCodes  = new short[286];
            DeflaterHuffman.staticLLength = new byte[286];
            int i = 0;

            while (i < 144)
            {
                DeflaterHuffman.staticLCodes[i]    = DeflaterHuffman.BitReverse(48 + i << 8);
                DeflaterHuffman.staticLLength[i++] = 8;
            }
            while (i < 256)
            {
                DeflaterHuffman.staticLCodes[i]    = DeflaterHuffman.BitReverse(256 + i << 7);
                DeflaterHuffman.staticLLength[i++] = 9;
            }
            while (i < 280)
            {
                DeflaterHuffman.staticLCodes[i]    = DeflaterHuffman.BitReverse(-256 + i << 9);
                DeflaterHuffman.staticLLength[i++] = 7;
            }
            while (i < 286)
            {
                DeflaterHuffman.staticLCodes[i]    = DeflaterHuffman.BitReverse(-88 + i << 8);
                DeflaterHuffman.staticLLength[i++] = 8;
            }
            DeflaterHuffman.staticDCodes  = new short[30];
            DeflaterHuffman.staticDLength = new byte[30];
            for (i = 0; i < 30; i++)
            {
                DeflaterHuffman.staticDCodes[i]  = DeflaterHuffman.BitReverse(i << 11);
                DeflaterHuffman.staticDLength[i] = 5;
            }
        }
Ejemplo n.º 18
0
        private void BuildTree(byte[] codeLengths)
        {
            int num2;
            int num5;
            int num6;

            int[] numArray  = new int[0x10];
            int[] numArray2 = new int[0x10];
            int   index     = 0;

            while (index < codeLengths.Length)
            {
                num2 = codeLengths[index];
                if (num2 > 0)
                {
                    numArray[num2]++;
                }
                index++;
            }
            int toReverse = 0;
            int num4      = 0x200;

            for (num2 = 1; num2 <= 15; num2++)
            {
                numArray2[num2] = toReverse;
                toReverse      += numArray[num2] << (0x10 - num2);
                if (num2 >= 10)
                {
                    num5  = numArray2[num2] & 0x1ff80;
                    num6  = toReverse & 0x1ff80;
                    num4 += (num6 - num5) >> (0x10 - num2);
                }
            }
            this.tree = new short[num4];
            int num7 = 0x200;

            num2 = 15;
            while (num2 >= 10)
            {
                num6       = toReverse & 0x1ff80;
                toReverse -= numArray[num2] << (0x10 - num2);
                num5       = toReverse & 0x1ff80;
                index      = num5;
                while (index < num6)
                {
                    this.tree[DeflaterHuffman.BitReverse(index)] = (short)((-num7 << 4) | num2);
                    num7  += ((int)1) << (num2 - 9);
                    index += 0x80;
                }
                num2--;
            }
            for (index = 0; index < codeLengths.Length; index++)
            {
                num2 = codeLengths[index];
                if (num2 != 0)
                {
                    toReverse = numArray2[num2];
                    int num8 = DeflaterHuffman.BitReverse(toReverse);
                    if (num2 <= 9)
                    {
                        do
                        {
                            this.tree[num8] = (short)((index << 4) | num2);
                            num8           += ((int)1) << num2;
                        }while (num8 < 0x200);
                    }
                    else
                    {
                        int num9  = this.tree[num8 & 0x1ff];
                        int num10 = ((int)1) << (num9 & 15);
                        num9 = -(num9 >> 4);
                        do
                        {
                            this.tree[num9 | (num8 >> 9)] = (short)((index << 4) | num2);
                            num8 += ((int)1) << num2;
                        }while (num8 < num10);
                    }
                    numArray2[num2] = toReverse + (((int)1) << (0x10 - num2));
                }
            }
        }
Ejemplo n.º 19
0
 public void CalcBLFreq(DeflaterHuffman.Tree blTree)
 {
     int index = -1;
     int num5 = 0;
     while (num5 < this.numCodes)
     {
         int num;
         int num2;
         int num3 = 1;
         int num6 = this.length[num5];
         if (num6 == 0)
         {
             num = 0x8a;
             num2 = 3;
         }
         else
         {
             num = 6;
             num2 = 3;
             if (index != num6)
             {
                 blTree.freqs[num6] = (short) (blTree.freqs[num6] + 1);
                 num3 = 0;
             }
         }
         index = num6;
         num5++;
         while ((num5 < this.numCodes) && (index == this.length[num5]))
         {
             num5++;
             if (++num3 >= num)
             {
                 break;
             }
         }
         if (num3 < num2)
         {
             blTree.freqs[index] = (short) (blTree.freqs[index] + ((short) num3));
         }
         else
         {
             if (index != 0)
             {
                 blTree.freqs[0x10] = (short) (blTree.freqs[0x10] + 1);
                 continue;
             }
             if (num3 <= 10)
             {
                 blTree.freqs[0x11] = (short) (blTree.freqs[0x11] + 1);
                 continue;
             }
             blTree.freqs[0x12] = (short) (blTree.freqs[0x12] + 1);
         }
     }
 }
Ejemplo n.º 20
0
 public void WriteTree(DeflaterHuffman.Tree blTree)
 {
     int code = -1;
     int index = 0;
     while (index < this.numCodes)
     {
         int num;
         int num2;
         int num3 = 1;
         int num6 = this.length[index];
         if (num6 == 0)
         {
             num = 0x8a;
             num2 = 3;
         }
         else
         {
             num = 6;
             num2 = 3;
             if (code != num6)
             {
                 blTree.WriteSymbol(num6);
                 num3 = 0;
             }
         }
         code = num6;
         index++;
         while ((index < this.numCodes) && (code == this.length[index]))
         {
             index++;
             if (++num3 >= num)
             {
                 break;
             }
         }
         if (num3 < num2)
         {
             while (num3-- > 0)
             {
                 blTree.WriteSymbol(code);
             }
         }
         else if (code != 0)
         {
             blTree.WriteSymbol(0x10);
             this.dh.pending.WriteBits(num3 - 3, 2);
         }
         else
         {
             if (num3 <= 10)
             {
                 blTree.WriteSymbol(0x11);
                 this.dh.pending.WriteBits(num3 - 3, 3);
                 continue;
             }
             blTree.WriteSymbol(0x12);
             this.dh.pending.WriteBits(num3 - 11, 7);
         }
     }
 }
Ejemplo n.º 21
0
        private void BuildTree(byte[] codeLengths)
        {
            int[] array  = new int[16];
            int[] array2 = new int[16];
            for (int i = 0; i < codeLengths.Length; i++)
            {
                int num = (int)codeLengths[i];
                if (num > 0)
                {
                    array[num]++;
                }
            }
            int num2 = 0;
            int num3 = 512;

            for (int j = 1; j <= 15; j++)
            {
                array2[j] = num2;
                num2     += array[j] << 16 - j;
                if (j >= 10)
                {
                    int num4 = array2[j] & 130944;
                    int num5 = num2 & 130944;
                    num3 += num5 - num4 >> 16 - j;
                }
            }
            this.tree = new short[num3];
            int num6 = 512;

            for (int k = 15; k >= 10; k--)
            {
                int num7 = num2 & 130944;
                num2 -= array[k] << 16 - k;
                int num8 = num2 & 130944;
                for (int l = num8; l < num7; l += 128)
                {
                    this.tree[(int)DeflaterHuffman.BitReverse(l)] = (short)(-num6 << 4 | k);
                    num6 += 1 << k - 9;
                }
            }
            for (int m = 0; m < codeLengths.Length; m++)
            {
                int num9 = (int)codeLengths[m];
                if (num9 != 0)
                {
                    num2 = array2[num9];
                    int num10 = (int)DeflaterHuffman.BitReverse(num2);
                    if (num9 <= 9)
                    {
                        do
                        {
                            this.tree[num10] = (short)(m << 4 | num9);
                            num10           += 1 << num9;
                        }while (num10 < 512);
                    }
                    else
                    {
                        int num11 = (int)this.tree[num10 & 511];
                        int num12 = 1 << (num11 & 15);
                        num11 = -(num11 >> 4);
                        do
                        {
                            this.tree[num11 | num10 >> 9] = (short)(m << 4 | num9);
                            num10 += 1 << num9;
                        }while (num10 < num12);
                    }
                    array2[num9] = num2 + (1 << 16 - num9);
                }
            }
        }
Ejemplo n.º 22
0
        private void BuildTree(byte[] codeLengths)
        {
            int[] numArray  = new int[0x10];
            int[] numArray2 = new int[0x10];
            for (int i = 0; i < codeLengths.Length; i++)
            {
                int index = codeLengths[i];
                if (index > 0)
                {
                    numArray[index]++;
                }
            }
            int toReverse = 0;
            int num4      = 0x200;

            for (int j = 1; j <= 15; j++)
            {
                numArray2[j] = toReverse;
                toReverse   += numArray[j] << (0x10 - j);
                if (j >= 10)
                {
                    int num6 = numArray2[j] & 0x1ff80;
                    int num7 = toReverse & 0x1ff80;
                    num4 += (num7 - num6) >> (0x10 - j);
                }
            }
            this.tree = new short[num4];
            int num8 = 0x200;

            for (int k = 15; k >= 10; k--)
            {
                int num10 = toReverse & 0x1ff80;
                toReverse -= numArray[k] << (0x10 - k);
                int num11 = toReverse & 0x1ff80;
                for (int n = num11; n < num10; n += 0x80)
                {
                    this.tree[DeflaterHuffman.BitReverse(n)] = (short)((-num8 << 4) | k);
                    num8 += ((int)1) << (k - 9);
                }
            }
            for (int m = 0; m < codeLengths.Length; m++)
            {
                int num14 = codeLengths[m];
                if (num14 != 0)
                {
                    toReverse = numArray2[num14];
                    int num15 = DeflaterHuffman.BitReverse(toReverse);
                    if (num14 <= 9)
                    {
                        do
                        {
                            this.tree[num15] = (short)((m << 4) | num14);
                            num15           += ((int)1) << num14;
                        }while (num15 < 0x200);
                    }
                    else
                    {
                        int num16 = this.tree[num15 & 0x1ff];
                        int num17 = ((int)1) << (num16 & 15);
                        num16 = -(num16 >> 4);
                        do
                        {
                            this.tree[num16 | (num15 >> 9)] = (short)((m << 4) | num14);
                            num15 += ((int)1) << num14;
                        }while (num15 < num17);
                    }
                    numArray2[num14] = toReverse + (((int)1) << (0x10 - num14));
                }
            }
        }
        void BuildTree(byte[] codeLengths)
        {
            int[] blCount  = new int[MAX_BITLEN + 1];
            int[] nextCode = new int[MAX_BITLEN + 1];

            for (int i = 0; i < codeLengths.Length; i++)
            {
                int bits = codeLengths[i];
                if (bits > 0)
                {
                    blCount[bits]++;
                }
            }

            int code     = 0;
            int treeSize = 512;

            for (int bits = 1; bits <= MAX_BITLEN; bits++)
            {
                nextCode[bits] = code;
                code          += blCount[bits] << (16 - bits);
                if (bits >= 10)
                {
                    int start = nextCode[bits] & 0x1ff80;
                    int end   = code & 0x1ff80;
                    treeSize += (end - start) >> (16 - bits);
                }
            }


            tree = new short[treeSize];
            int treePtr = 512;

            for (int bits = MAX_BITLEN; bits >= 10; bits--)
            {
                int end = code & 0x1ff80;
                code -= blCount[bits] << (16 - bits);
                int start = code & 0x1ff80;
                for (int i = start; i < end; i += 1 << 7)
                {
                    tree[DeflaterHuffman.BitReverse(i)] = (short)((-treePtr << 4) | bits);
                    treePtr += 1 << (bits - 9);
                }
            }

            for (int i = 0; i < codeLengths.Length; i++)
            {
                int bits = codeLengths[i];
                if (bits == 0)
                {
                    continue;
                }
                code = nextCode[bits];
                int revcode = DeflaterHuffman.BitReverse(code);
                if (bits <= 9)
                {
                    do
                    {
                        tree[revcode] = (short)((i << 4) | bits);
                        revcode      += 1 << bits;
                    } while (revcode < 512);
                }
                else
                {
                    int subTree = tree[revcode & 511];
                    int treeLen = 1 << (subTree & 15);
                    subTree = -(subTree >> 4);
                    do
                    {
                        tree[subTree | (revcode >> 9)] = (short)((i << 4) | bits);
                        revcode += 1 << bits;
                    } while (revcode < treeLen);
                }
                nextCode[bits] = code + (1 << (16 - bits));
            }
        }