예제 #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];
 }
예제 #2
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;
        }
예제 #3
0
            public void BuildCodes()
            {
                int num = this.freqs.Length;

                int[] array = new int[this.maxLength];
                int   num2  = 0;

                this.codes = new short[this.freqs.Length];
                for (int i = 0; i < this.maxLength; i++)
                {
                    array[i] = num2;
                    num2    += this.bl_counts[i] << 15 - i;
                }
                for (int j = 0; j < this.numCodes; j++)
                {
                    int num3 = (int)this.length[j];
                    if (num3 > 0)
                    {
                        this.codes[j]    = DeflaterHuffman.BitReverse(array[num3 - 1]);
                        array[num3 - 1] += 1 << 16 - num3;
                    }
                }
            }
예제 #4
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] & 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);
                }
            }
        }
예제 #5
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));
            }
        }
예제 #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];
			
			// We start at index 1, to avoid an implementation deficiency, that
			// we cannot build a repeat pattern at index 0.
			blockStart = strstart = 1;
		}
예제 #7
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];
			}