Exemple #1
0
 internal bool _tr_tally(int dist, int lc)
 {
     this.pending[this._distanceOffset + (this.last_lit * 2)]       = (byte)(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)
     {
         this.dyn_ltree[lc * 2] = (short)(this.dyn_ltree[lc * 2] + 1);
     }
     else
     {
         this.matches++;
         dist--;
         this.dyn_ltree[((ZTree.LengthCode[lc] + InternalConstants.LITERALS) + 1) * 2] = (short)(this.dyn_ltree[((ZTree.LengthCode[lc] + InternalConstants.LITERALS) + 1) * 2] + 1);
         this.dyn_dtree[ZTree.DistanceCode(dist) * 2] = (short)(this.dyn_dtree[ZTree.DistanceCode(dist) * 2] + 1);
     }
     if (((this.last_lit & 0x1fff) == 0) && (this.compressionLevel > CompressionLevel.Level2))
     {
         int num  = this.last_lit << 3;
         int num2 = this.strstart - this.block_start;
         for (int i = 0; i < InternalConstants.D_CODES; i++)
         {
             num += (int)(this.dyn_dtree[i * 2] * (5L + ZTree.ExtraDistanceBits[i]));
         }
         num = num >> 3;
         if ((this.matches < (this.last_lit / 2)) && (num < (num2 / 2)))
         {
             return(true);
         }
     }
     return((this.last_lit == (this.lit_bufsize - 1)) || (this.last_lit == this.lit_bufsize));
 }
Exemple #2
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]      = 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);
        }
Exemple #3
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] & 255);
                    int num4 = (int)(this.pending[this._lengthOffset + num] & 255);
                    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];
        }
Exemple #4
0
        internal void send_compressed_block(short[] ltree, short[] dtree)
        {
            int num3 = 0;

            if (this.last_lit != 0)
            {
                do
                {
                    int index = this._distanceOffset + (num3 * 2);
                    int dist  = ((this.pending[index] << 8) & 0xff00) | (this.pending[index + 1] & 0xff);
                    int c     = this.pending[this._lengthOffset + num3] & 0xff;
                    num3++;
                    if (dist == 0)
                    {
                        this.send_code(c, ltree);
                    }
                    else
                    {
                        int num4 = ZTree.LengthCode[c];
                        this.send_code((num4 + InternalConstants.LITERALS) + 1, ltree);
                        int length = ZTree.ExtraLengthBits[num4];
                        if (length != 0)
                        {
                            c -= ZTree.LengthBase[num4];
                            this.send_bits(c, length);
                        }
                        dist--;
                        num4 = ZTree.DistanceCode(dist);
                        this.send_code(num4, dtree);
                        length = ZTree.ExtraDistanceBits[num4];
                        if (length != 0)
                        {
                            dist -= ZTree.DistanceBase[num4];
                            this.send_bits(dist, length);
                        }
                    }
                }while (num3 < this.last_lit);
            }
            this.send_code(END_BLOCK, ltree);
            this.last_eob_len = ltree[(END_BLOCK * 2) + 1];
        }
Exemple #5
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[] expr_6C_cp_0 = this.dyn_ltree;
         int     expr_6C_cp_1 = lc * 2;
         expr_6C_cp_0[expr_6C_cp_1] += 1;
     }
     else
     {
         this.matches++;
         dist--;
         short[] expr_A7_cp_0 = this.dyn_ltree;
         int     expr_A7_cp_1 = ((int)ZTree.LengthCode[lc] + InternalConstants.LITERALS + 1) * 2;
         expr_A7_cp_0[expr_A7_cp_1] += 1;
         short[] expr_C0_cp_0 = this.dyn_dtree;
         int     expr_C0_cp_1 = ZTree.DistanceCode(dist) * 2;
         expr_C0_cp_0[expr_C0_cp_1] += 1;
     }
     if ((this.last_lit & 8191) == 0 && this.compressionLevel > CompressionLevel.Level2)
     {
         int num  = this.last_lit << 3;
         int num2 = this.strstart - this.block_start;
         for (int i = 0; i < InternalConstants.D_CODES; i++)
         {
             num = (int)((long)num + (long)this.dyn_dtree[i * 2] * (5L + (long)ZTree.ExtraDistanceBits[i]));
         }
         num >>= 3;
         if (this.matches < this.last_lit / 2 && num < num2 / 2)
         {
             return(true);
         }
     }
     return(this.last_lit == this.lit_bufsize - 1 || this.last_lit == this.lit_bufsize);
 }
Exemple #6
0
        internal static void gen_codes(short[] tree, int max_code, short[] bl_count)
        {
            short[] array = new short[InternalConstants.MAX_BITS + 1];
            short   num   = 0;

            for (int i = 1; i <= InternalConstants.MAX_BITS; i++)
            {
                num = (array[i] = (short)(num + bl_count[i - 1] << 1));
            }
            for (int j = 0; j <= max_code; j++)
            {
                int num2 = (int)tree[j * 2 + 1];
                if (num2 != 0)
                {
                    int     arg_6F_1     = j * 2;
                    short[] expr_5C_cp_0 = array;
                    int     expr_5C_cp_1 = num2;
                    short   code;
                    expr_5C_cp_0[expr_5C_cp_1] = (code = expr_5C_cp_0[expr_5C_cp_1]) + 1;
                    tree[arg_6F_1]             = (short)ZTree.bi_reverse((int)code, num2);
                }
            }
        }