Beispiel #1
0
        internal void build_tree(DeflateManager s)
        {
            short[] array     = this.dyn_tree;
            short[] treeCodes = this.staticTree.treeCodes;
            int     elems     = this.staticTree.elems;
            int     num       = -1;

            s.heap_len = 0;
            s.heap_max = ZTree.HEAP_SIZE;
            for (int i = 0; i < elems; i++)
            {
                if (array[i * 2] != 0)
                {
                    num        = (s.heap[++s.heap_len] = i);
                    s.depth[i] = 0;
                }
                else
                {
                    array[i * 2 + 1] = 0;
                }
            }
            int num2;

            while (s.heap_len < 2)
            {
                num2            = (s.heap[++s.heap_len] = ((num >= 2) ? 0 : (++num)));
                array[num2 * 2] = 1;
                s.depth[num2]   = 0;
                s.opt_len--;
                if (treeCodes != null)
                {
                    s.static_len -= (int)treeCodes[num2 * 2 + 1];
                }
            }
            this.max_code = num;
            for (int i = s.heap_len / 2; i >= 1; i--)
            {
                s.pqdownheap(array, i);
            }
            num2 = elems;
            do
            {
                int i = s.heap[1];
                s.heap[1] = s.heap[s.heap_len--];
                s.pqdownheap(array, 1);
                int num3 = s.heap[1];
                s.heap[--s.heap_max] = i;
                s.heap[--s.heap_max] = num3;
                array[num2 * 2]      = (short)(array[i * 2] + array[num3 * 2]);
                s.depth[num2]        = (sbyte)(Math.Max((byte)s.depth[i], (byte)s.depth[num3]) + 1);
                array[i * 2 + 1]     = (array[num3 * 2 + 1] = (short)num2);
                s.heap[1]            = num2++;
                s.pqdownheap(array, 1);
            }while (s.heap_len >= 2);
            s.heap[--s.heap_max] = s.heap[1];
            this.gen_bitlen(s);
            ZTree.gen_codes(array, num, s.bl_count);
        }
Beispiel #2
0
        internal void send_compressed_block(short[] ltree, short[] dtree)
        {
            int num = 0;

            if (this.last_lit != 0)
            {
                do
                {
                    int num2 = this._distanceOffset + num * 2;
                    int num3 = ((int)this.pending[num2] << 8 & 65280) | (int)(this.pending[num2 + 1] & byte.MaxValue);
                    int num4 = (int)(this.pending[this._lengthOffset + num] & byte.MaxValue);
                    num++;
                    if (num3 == 0)
                    {
                        this.send_code(num4, ltree);
                    }
                    else
                    {
                        int num5 = (int)ZTree.LengthCode[num4];
                        this.send_code(num5 + InternalConstants.LITERALS + 1, ltree);
                        int num6 = ZTree.ExtraLengthBits[num5];
                        if (num6 != 0)
                        {
                            num4 -= ZTree.LengthBase[num5];
                            this.send_bits(num4, num6);
                        }
                        num3--;
                        num5 = ZTree.DistanceCode(num3);
                        this.send_code(num5, dtree);
                        num6 = ZTree.ExtraDistanceBits[num5];
                        if (num6 != 0)
                        {
                            num3 -= ZTree.DistanceBase[num5];
                            this.send_bits(num3, num6);
                        }
                    }
                }while (num < this.last_lit);
            }
            this.send_code(DeflateManager.END_BLOCK, ltree);
            this.last_eob_len = (int)ltree[DeflateManager.END_BLOCK * 2 + 1];
        }
Beispiel #3
0
 internal bool _tr_tally(int dist, int lc)
 {
     this.pending[this._distanceOffset + this.last_lit * 2]     = (byte)((uint)dist >> 8);
     this.pending[this._distanceOffset + this.last_lit * 2 + 1] = (byte)dist;
     this.pending[this._lengthOffset + this.last_lit]           = (byte)lc;
     this.last_lit++;
     if (dist == 0)
     {
         short[] array = this.dyn_ltree;
         int     num   = lc * 2;
         array[num] += 1;
     }
     else
     {
         this.matches++;
         dist--;
         short[] array2 = this.dyn_ltree;
         int     num2   = ((int)ZTree.LengthCode[lc] + InternalConstants.LITERALS + 1) * 2;
         array2[num2] += 1;
         short[] array3 = this.dyn_dtree;
         int     num3   = ZTree.DistanceCode(dist) * 2;
         array3[num3] += 1;
     }
     if ((this.last_lit & 8191) == 0 && this.compressionLevel > CompressionLevel.Level2)
     {
         int num4 = this.last_lit << 3;
         int num5 = this.strstart - this.block_start;
         for (int i = 0; i < InternalConstants.D_CODES; i++)
         {
             num4 = (int)((long)num4 + (long)this.dyn_dtree[i * 2] * (5L + (long)ZTree.ExtraDistanceBits[i]));
         }
         num4 >>= 3;
         if (this.matches < this.last_lit / 2 && num4 < num5 / 2)
         {
             return(true);
         }
     }
     return(this.last_lit == this.lit_bufsize - 1 || this.last_lit == this.lit_bufsize);
 }