URShift() public static method

Performs an unsigned bitwise right shift with the specified number
public static URShift ( int number, int bits ) : int
number int Number to operate on
bits int Ammount of bits to shift
return int
Beispiel #1
0
 internal bool _tr_tally(int dist, int lc)
 {
     this.pending[this.d_buf + (this.last_lit * 2)]       = (byte)SharedUtils.URShift(dist, 8);
     this.pending[(this.d_buf + (this.last_lit * 2)) + 1] = (byte)dist;
     this.pending[this.l_buf + 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[((Tree._length_code[lc] + 0x100) + 1) * 2] = (short)(this.dyn_ltree[((Tree._length_code[lc] + 0x100) + 1) * 2] + 1);
         this.dyn_dtree[Tree.d_code(dist) * 2] = (short)(this.dyn_dtree[Tree.d_code(dist) * 2] + 1);
     }
     if (((this.last_lit & 0x1fff) == 0) && (this.compressionLevel > CompressionLevel.Level2))
     {
         int number = this.last_lit * 8;
         int num2   = this.strstart - this.block_start;
         for (int i = 0; i < 30; i++)
         {
             number += (int)(this.dyn_dtree[i * 2] * (5L + Tree.extra_dbits[i]));
         }
         number = SharedUtils.URShift(number, 3);
         if ((this.matches < (this.last_lit / 2)) && (number < (num2 / 2)))
         {
             return(true);
         }
     }
     return((this.last_lit == (this.lit_bufsize - 1)) || (this.last_lit == this.lit_bufsize));
 }
Beispiel #2
0
 internal static int DistanceCode(int dist)
 {
     if (dist >= 256)
     {
         return(_dist_code[256 + SharedUtils.URShift(dist, 7)]);
     }
     return(_dist_code[dist]);
 }
Beispiel #3
0
        // Reverse the first len bits of a code, using straightforward code (a faster
        // method would use a table)
        // IN assertion: 1 <= len <= 15
        internal static int bi_reverse(int code, int len)
        {
            int res = 0;

            do
            {
                res  |= code & 1;
                code  = SharedUtils.URShift(code, 1);
                res <<= 1;
            }while (--len > 0);
            return(SharedUtils.URShift(res, 1));
        }
Beispiel #4
0
        internal static int bi_reverse(int code, int len)
        {
            int number = 0;

            do
            {
                number |= code & 1;
                code    = SharedUtils.URShift(code, 1);
                number  = number << 1;
            }while (--len > 0);
            return(SharedUtils.URShift(number, 1));
        }
Beispiel #5
0
 internal void bi_flush()
 {
     if (this.bi_valid == 0x10)
     {
         this.put_short(this.bi_buf);
         this.bi_buf   = 0;
         this.bi_valid = 0;
     }
     else if (this.bi_valid >= 8)
     {
         this.put_byte((byte)this.bi_buf);
         this.bi_buf    = (short)SharedUtils.URShift((int)this.bi_buf, 8);
         this.bi_valid -= 8;
     }
 }
Beispiel #6
0
        internal void _tr_flush_block(int buf, int stored_len, bool eof)
        {
            int num;
            int num2;
            int num3 = 0;

            if (this.compressionLevel > CompressionLevel.None)
            {
                if (this.data_type == 2)
                {
                    this.set_data_type();
                }
                this.l_desc.build_tree(this);
                this.d_desc.build_tree(this);
                num3 = this.build_bl_tree();
                num  = SharedUtils.URShift((int)((this.opt_len + 3) + 7), 3);
                num2 = SharedUtils.URShift((int)((this.static_len + 3) + 7), 3);
                if (num2 <= num)
                {
                    num = num2;
                }
            }
            else
            {
                num = num2 = stored_len + 5;
            }
            if (((stored_len + 4) <= num) && (buf != -1))
            {
                this._tr_stored_block(buf, stored_len, eof);
            }
            else if (num2 == num)
            {
                this.send_bits(2 + (eof ? 1 : 0), 3);
                this.send_compressed_block(StaticTree.static_ltree, StaticTree.static_dtree);
            }
            else
            {
                this.send_bits(4 + (eof ? 1 : 0), 3);
                this.send_all_trees(this.l_desc.max_code + 1, this.d_desc.max_code + 1, num3 + 1);
                this.send_compressed_block(this.dyn_ltree, this.dyn_dtree);
            }
            this._InitializeBlocks();
            if (eof)
            {
                this.bi_windup();
            }
        }
Beispiel #7
0
        internal void send_bits(int value_Renamed, int length)
        {
            int num = length;

            if (this.bi_valid > (0x10 - num))
            {
                int number = value_Renamed;
                this.bi_buf = (short)(this.bi_buf | ((short)((number << this.bi_valid) & 0xffff)));
                this.put_short(this.bi_buf);
                this.bi_buf    = (short)SharedUtils.URShift(number, 0x10 - this.bi_valid);
                this.bi_valid += num - 0x10;
            }
            else
            {
                this.bi_buf    = (short)(this.bi_buf | ((short)((value_Renamed << this.bi_valid) & 0xffff)));
                this.bi_valid += num;
            }
        }
Beispiel #8
0
        internal void set_data_type()
        {
            int num    = 0;
            int number = 0;
            int num3   = 0;

            while (num < 7)
            {
                num3 += this.dyn_ltree[num * 2];
                num++;
            }
            while (num < 0x80)
            {
                number += this.dyn_ltree[num * 2];
                num++;
            }
            while (num < 0x100)
            {
                num3 += this.dyn_ltree[num * 2];
                num++;
            }
            this.data_type = (num3 > SharedUtils.URShift(number, 2)) ? ((sbyte)0) : ((sbyte)1);
        }
Beispiel #9
0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int num  = 0;
            int num2 = n;

            do
            {
                this.c[b[bindex + num]]++;
                num++;
                num2--;
            }while (num2 != 0);
            if (this.c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num3 = m[0];
            int i;

            for (i = 1; i <= 15; i++)
            {
                if (this.c[i] != 0)
                {
                    break;
                }
            }
            int j = i;

            if (num3 < i)
            {
                num3 = i;
            }
            for (num2 = 15; num2 != 0; num2--)
            {
                if (this.c[num2] != 0)
                {
                    break;
                }
            }
            int num4 = num2;

            if (num3 > num2)
            {
                num3 = num2;
            }
            m[0] = num3;
            int num5 = 1 << i;

            while (i < num2)
            {
                if ((num5 -= this.c[i]) < 0)
                {
                    return(-3);
                }
                i++;
                num5 <<= 1;
            }
            if ((num5 -= this.c[num2]) < 0)
            {
                return(-3);
            }
            this.c[num2] += num5;
            i             = (this.x[1] = 0);
            num           = 1;
            int num6 = 2;

            while (--num2 != 0)
            {
                i = (this.x[num6] = i + this.c[num]);
                num6++;
                num++;
            }
            num2 = 0;
            num  = 0;
            do
            {
                if ((i = b[bindex + num]) != 0)
                {
                    v[this.x[i]++] = num2;
                }
                num++;
            }while (++num2 < n);
            n    = this.x[num4];
            num2 = (this.x[0] = 0);
            num  = 0;
            int num7 = -1;
            int num8 = -num3;

            this.u[0] = 0;
            int num9  = 0;
            int num10 = 0;

            while (j <= num4)
            {
                int num11 = this.c[j];
                while (num11-- != 0)
                {
                    int num12;
                    while (j > num8 + num3)
                    {
                        num7++;
                        num8 += num3;
                        num10 = num4 - num8;
                        num10 = ((num10 <= num3) ? num10 : num3);
                        if ((num12 = 1 << ((i = j - num8) & 31)) > num11 + 1)
                        {
                            num12 -= num11 + 1;
                            num6   = j;
                            if (i < num10)
                            {
                                while (++i < num10)
                                {
                                    if ((num12 <<= 1) <= this.c[++num6])
                                    {
                                        break;
                                    }
                                    num12 -= this.c[num6];
                                }
                            }
                        }
                        num10 = 1 << i;
                        if (hn[0] + num10 > 1440)
                        {
                            return(-3);
                        }
                        num9   = (this.u[num7] = hn[0]);
                        hn[0] += num10;
                        if (num7 != 0)
                        {
                            this.x[num7] = num2;
                            this.r[0]    = (int)((sbyte)i);
                            this.r[1]    = (int)((sbyte)num3);
                            i            = SharedUtils.URShift(num2, num8 - num3);
                            this.r[2]    = num9 - this.u[num7 - 1] - i;
                            Array.Copy(this.r, 0, hp, (this.u[num7 - 1] + i) * 3, 3);
                        }
                        else
                        {
                            t[0] = num9;
                        }
                    }
                    this.r[1] = (int)((sbyte)(j - num8));
                    if (num >= n)
                    {
                        this.r[0] = 192;
                    }
                    else if (v[num] < s)
                    {
                        this.r[0] = (int)((v[num] >= 256) ? 96 : 0);
                        this.r[2] = v[num++];
                    }
                    else
                    {
                        this.r[0] = (int)((sbyte)(e[v[num] - s] + 16 + 64));
                        this.r[2] = d[v[num++] - s];
                    }
                    num12 = 1 << j - num8;
                    for (i = SharedUtils.URShift(num2, num8); i < num10; i += num12)
                    {
                        Array.Copy(this.r, 0, hp, (num9 + i) * 3, 3);
                    }
                    i = 1 << j - 1;
                    while ((num2 & i) != 0)
                    {
                        num2 ^= i;
                        i     = SharedUtils.URShift(i, 1);
                    }
                    num2 ^= i;
                    int num13 = (1 << num8) - 1;
                    while ((num2 & num13) != this.x[num7])
                    {
                        num7--;
                        num8 -= num3;
                        num13 = (1 << num8) - 1;
                    }
                }
                j++;
            }
            return((num5 == 0 || num4 == 1) ? 0 : -5);
        }
Beispiel #10
0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int p = 0;
            int i = n;

            do
            {
                c[b[bindex + p]]++;
                p++;
                i--;
            }while (i != 0);
            if (c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int l = m[0];
            int j;

            for (j = 1; j <= 15 && c[j] == 0; j++)
            {
            }
            int k = j;

            if (l < j)
            {
                l = j;
            }
            i = 15;
            while (i != 0 && c[i] == 0)
            {
                i--;
            }
            int g = i;

            if (l > i)
            {
                l = i;
            }
            m[0] = l;
            int y = 1 << j;

            while (j < i)
            {
                if ((y -= c[j]) < 0)
                {
                    return(-3);
                }
                j++;
                y <<= 1;
            }
            if ((y -= c[i]) < 0)
            {
                return(-3);
            }
            c[i] += y;
            j     = (x[1] = 0);
            p     = 1;
            int xp = 2;

            while (--i != 0)
            {
                j = (x[xp] = j + c[p]);
                xp++;
                p++;
            }
            i = 0;
            p = 0;
            do
            {
                if ((j = b[bindex + p]) != 0)
                {
                    v[x[j]++] = i;
                }
                p++;
            }while (++i < n);
            n = x[g];
            i = (x[0] = 0);
            p = 0;
            int h = -1;
            int w = -l;

            u[0] = 0;
            int q = 0;
            int z = 0;

            for (; k <= g; k++)
            {
                int a = c[k];
                while (a-- != 0)
                {
                    int f;
                    while (k > w + l)
                    {
                        h++;
                        w += l;
                        z  = g - w;
                        z  = ((z > l) ? l : z);
                        if ((f = 1 << (j = k - w)) > a + 1)
                        {
                            f -= a + 1;
                            xp = k;
                            if (j < z)
                            {
                                while (++j < z && (f <<= 1) > c[++xp])
                                {
                                    f -= c[xp];
                                }
                            }
                        }
                        z = 1 << j;
                        if (hn[0] + z > 1440)
                        {
                            return(-3);
                        }
                        q      = (u[h] = hn[0]);
                        hn[0] += z;
                        if (h != 0)
                        {
                            x[h] = i;
                            r[0] = (sbyte)j;
                            r[1] = (sbyte)l;
                            j    = SharedUtils.URShift(i, w - l);
                            r[2] = q - u[h - 1] - j;
                            Array.Copy(r, 0, hp, (u[h - 1] + j) * 3, 3);
                        }
                        else
                        {
                            t[0] = q;
                        }
                    }
                    r[1] = (sbyte)(k - w);
                    if (p >= n)
                    {
                        r[0] = 192;
                    }
                    else if (v[p] < s)
                    {
                        r[0] = (sbyte)((v[p] >= 256) ? 96 : 0);
                        r[2] = v[p++];
                    }
                    else
                    {
                        r[0] = (sbyte)(e[v[p] - s] + 16 + 64);
                        r[2] = d[v[p++] - s];
                    }
                    f = 1 << k - w;
                    for (j = SharedUtils.URShift(i, w); j < z; j += f)
                    {
                        Array.Copy(r, 0, hp, (q + j) * 3, 3);
                    }
                    j = 1 << k - 1;
                    while ((i & j) != 0)
                    {
                        i ^= j;
                        j  = SharedUtils.URShift(j, 1);
                    }
                    i ^= j;
                    int mask = (1 << w) - 1;
                    while ((i & mask) != x[h])
                    {
                        h--;
                        w   -= l;
                        mask = (1 << w) - 1;
                    }
                }
            }
            if (y == 0 || g == 1)
            {
                return(0);
            }
            return(-5);
        }
Beispiel #11
0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int num  = 0;
            int num2 = n;

            do
            {
                c[b[bindex + num]]++;
                num++;
                num2--;
            }while (num2 != 0);
            if (c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num3 = m[0];
            int i;

            for (i = 1; i <= 15 && c[i] == 0; i++)
            {
            }
            int j = i;

            if (num3 < i)
            {
                num3 = i;
            }
            num2 = 15;
            while (num2 != 0 && c[num2] == 0)
            {
                num2--;
            }
            int num4 = num2;

            if (num3 > num2)
            {
                num3 = num2;
            }
            m[0] = num3;
            int num5 = 1 << i;

            while (i < num2)
            {
                if ((num5 -= c[i]) < 0)
                {
                    return(-3);
                }
                i++;
                num5 <<= 1;
            }
            if ((num5 -= c[num2]) < 0)
            {
                return(-3);
            }
            c[num2] += num5;
            i        = (x[1] = 0);
            num      = 1;
            int num6 = 2;

            while (--num2 != 0)
            {
                i = (x[num6] = i + c[num]);
                num6++;
                num++;
            }
            num2 = 0;
            num  = 0;
            do
            {
                if ((i = b[bindex + num]) != 0)
                {
                    v[x[i]++] = num2;
                }
                num++;
            }while (++num2 < n);
            n    = x[num4];
            num2 = (x[0] = 0);
            num  = 0;
            int num7 = -1;
            int num8 = -num3;

            u[0] = 0;
            int num9  = 0;
            int num10 = 0;

            for (; j <= num4; j++)
            {
                int num11 = c[j];
                while (num11-- != 0)
                {
                    int num12;
                    while (j > num8 + num3)
                    {
                        num7++;
                        num8 += num3;
                        num10 = num4 - num8;
                        num10 = ((num10 > num3) ? num3 : num10);
                        if ((num12 = 1 << (i = j - num8)) > num11 + 1)
                        {
                            num12 -= num11 + 1;
                            num6   = j;
                            if (i < num10)
                            {
                                while (++i < num10 && (num12 <<= 1) > c[++num6])
                                {
                                    num12 -= c[num6];
                                }
                            }
                        }
                        num10 = 1 << i;
                        if (hn[0] + num10 > 1440)
                        {
                            return(-3);
                        }
                        num9   = (u[num7] = hn[0]);
                        hn[0] += num10;
                        if (num7 != 0)
                        {
                            x[num7] = num2;
                            r[0]    = (sbyte)i;
                            r[1]    = (sbyte)num3;
                            i       = SharedUtils.URShift(num2, num8 - num3);
                            r[2]    = num9 - u[num7 - 1] - i;
                            Array.Copy(r, 0, hp, (u[num7 - 1] + i) * 3, 3);
                        }
                        else
                        {
                            t[0] = num9;
                        }
                    }
                    r[1] = (sbyte)(j - num8);
                    if (num >= n)
                    {
                        r[0] = 192;
                    }
                    else if (v[num] < s)
                    {
                        r[0] = (sbyte)((v[num] >= 256) ? 96 : 0);
                        r[2] = v[num++];
                    }
                    else
                    {
                        r[0] = (sbyte)(e[v[num] - s] + 16 + 64);
                        r[2] = d[v[num++] - s];
                    }
                    num12 = 1 << j - num8;
                    for (i = SharedUtils.URShift(num2, num8); i < num10; i += num12)
                    {
                        Array.Copy(r, 0, hp, (num9 + i) * 3, 3);
                    }
                    i = 1 << j - 1;
                    while ((num2 & i) != 0)
                    {
                        num2 ^= i;
                        i     = SharedUtils.URShift(i, 1);
                    }
                    num2 ^= i;
                    int num13 = (1 << num8) - 1;
                    while ((num2 & num13) != x[num7])
                    {
                        num7--;
                        num8 -= num3;
                        num13 = (1 << num8) - 1;
                    }
                }
            }
            return((num5 != 0 && num4 != 1) ? (-5) : 0);
        }
Beispiel #12
0
 internal static int DistanceCode(int dist)
 {
     return((int)((dist >= 256) ? Tree._dist_code[256 + SharedUtils.URShift(dist, 7)] : Tree._dist_code[dist]));
 }
Beispiel #13
0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int p2 = 0;
            int i4 = n;

            do
            {
                c[b[bindex + p2]]++;
                p2++;
                i4--;
            }while (i4 != 0);
            if (c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int l2 = m[0];
            int j4;

            for (j4 = 1; j4 <= 15 && c[j4] == 0; j4++)
            {
            }
            int k2 = j4;

            if (l2 < j4)
            {
                l2 = j4;
            }
            i4 = 15;
            while (i4 != 0 && c[i4] == 0)
            {
                i4--;
            }
            int g = i4;

            if (l2 > i4)
            {
                l2 = i4;
            }
            m[0] = l2;
            int y3 = 1 << j4;

            while (j4 < i4)
            {
                if ((y3 -= c[j4]) < 0)
                {
                    return(-3);
                }
                j4++;
                y3 <<= 1;
            }
            if ((y3 -= c[i4]) < 0)
            {
                return(-3);
            }
            c[i4] += y3;
            j4     = (x[1] = 0);
            p2     = 1;
            int xp2 = 2;

            while (--i4 != 0)
            {
                j4 = (x[xp2] = j4 + c[p2]);
                xp2++;
                p2++;
            }
            i4 = 0;
            p2 = 0;
            do
            {
                if ((j4 = b[bindex + p2]) != 0)
                {
                    v[x[j4]++] = i4;
                }
                p2++;
            }while (++i4 < n);
            n  = x[g];
            i4 = (x[0] = 0);
            p2 = 0;
            int h = -1;
            int w = -l2;

            u[0] = 0;
            int q  = 0;
            int z3 = 0;

            for (; k2 <= g; k2++)
            {
                int a = c[k2];
                while (a-- != 0)
                {
                    int f3;
                    while (k2 > w + l2)
                    {
                        h++;
                        w += l2;
                        z3 = g - w;
                        z3 = ((z3 > l2) ? l2 : z3);
                        if ((f3 = 1 << (j4 = k2 - w)) > a + 1)
                        {
                            f3 -= a + 1;
                            xp2 = k2;
                            if (j4 < z3)
                            {
                                while (++j4 < z3 && (f3 <<= 1) > c[++xp2])
                                {
                                    f3 -= c[xp2];
                                }
                            }
                        }
                        z3 = 1 << j4;
                        if (hn[0] + z3 > 1440)
                        {
                            return(-3);
                        }
                        q      = (u[h] = hn[0]);
                        hn[0] += z3;
                        if (h != 0)
                        {
                            x[h] = i4;
                            r[0] = (sbyte)j4;
                            r[1] = (sbyte)l2;
                            j4   = SharedUtils.URShift(i4, w - l2);
                            r[2] = q - u[h - 1] - j4;
                            Array.Copy(r, 0, hp, (u[h - 1] + j4) * 3, 3);
                        }
                        else
                        {
                            t[0] = q;
                        }
                    }
                    r[1] = (sbyte)(k2 - w);
                    if (p2 >= n)
                    {
                        r[0] = 192;
                    }
                    else if (v[p2] < s)
                    {
                        r[0] = (sbyte)((v[p2] >= 256) ? 96 : 0);
                        r[2] = v[p2++];
                    }
                    else
                    {
                        r[0] = (sbyte)(e[v[p2] - s] + 16 + 64);
                        r[2] = d[v[p2++] - s];
                    }
                    f3 = 1 << k2 - w;
                    for (j4 = SharedUtils.URShift(i4, w); j4 < z3; j4 += f3)
                    {
                        Array.Copy(r, 0, hp, (q + j4) * 3, 3);
                    }
                    j4 = 1 << k2 - 1;
                    while ((i4 & j4) != 0)
                    {
                        i4 ^= j4;
                        j4  = SharedUtils.URShift(j4, 1);
                    }
                    i4 ^= j4;
                    int mask = (1 << w) - 1;
                    while ((i4 & mask) != x[h])
                    {
                        h--;
                        w   -= l2;
                        mask = (1 << w) - 1;
                    }
                }
            }
            if (y3 == 0 || g == 1)
            {
                return(0);
            }
            return(-5);
        }
        internal int[] x  = null;        // bit offsets, then code stack

        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            // Given a list of code lengths and a maximum table size, make a set of
            // tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
            // if the given code set is incomplete (the tables are still built in this
            // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
            // lengths), or Z_MEM_ERROR if not enough memory.

            int a;             // counter for codes of length k
            int f;             // i repeats in table every f entries
            int g;             // maximum code length
            int h;             // table level
            int i;             // counter, current code
            int j;             // counter
            int k;             // number of bits in current code
            int l;             // bits per table (returned in m)
            int mask;          // (1 << w) - 1, to avoid cc -O bug on HP
            int p;             // pointer into c[], b[], or v[]
            int q;             // points to current table
            int w;             // bits before this table == (l * h)
            int xp;            // pointer into x
            int y;             // number of dummy codes added
            int z;             // number of entries in current table

            // Generate counts for each bit length

            p = 0; i = n;
            do
            {
                c[b[bindex + p]]++; p++; i--;                 // assume all entries <= BMAX
            }while (i != 0);

            if (c[0] == n)
            {
                // null input--all zero length codes
                t[0] = -1;
                m[0] = 0;
                return(Z_OK);
            }

            // Find minimum and maximum length, bound *m by those
            l = m[0];
            for (j = 1; j <= BMAX; j++)
            {
                if (c[j] != 0)
                {
                    break;
                }
            }
            k = j;             // minimum code length
            if (l < j)
            {
                l = j;
            }
            for (i = BMAX; i != 0; i--)
            {
                if (c[i] != 0)
                {
                    break;
                }
            }
            g = i;             // maximum code length
            if (l > i)
            {
                l = i;
            }
            m[0] = l;

            // Adjust last length count to fill out codes, if needed
            for (y = 1 << j; j < i; j++, y <<= 1)
            {
                if ((y -= c[j]) < 0)
                {
                    return(Z_DATA_ERROR);
                }
            }
            if ((y -= c[i]) < 0)
            {
                return(Z_DATA_ERROR);
            }
            c[i] += y;

            // Generate starting offsets into the value table for each length
            x[1] = j = 0;
            p    = 1; xp = 2;
            while (--i != 0)
            {
                // note that i == g from above
                x[xp] = (j += c[p]);
                xp++;
                p++;
            }

            // Make a table of values in order of bit lengths
            i = 0; p = 0;
            do
            {
                if ((j = b[bindex + p]) != 0)
                {
                    v[x[j]++] = i;
                }
                p++;
            }while (++i < n);
            n = x[g];             // set n to length of v

            // Generate the Huffman codes and for each, make the table entries
            x[0] = i = 0;      // first Huffman code is zero
            p    = 0;          // grab values in bit order
            h    = -1;         // no tables yet--level -1
            w    = -l;         // bits decoded == (l * h)
            u[0] = 0;          // just to keep compilers happy
            q    = 0;          // ditto
            z    = 0;          // ditto

            // go through the bit lengths (k already is bits in shortest code)
            for (; k <= g; k++)
            {
                a = c[k];
                while (a-- != 0)
                {
                    // here i is the Huffman code of length k bits for value *p
                    // make tables up to required level
                    while (k > w + l)
                    {
                        h++;
                        w += l;                         // previous table always l bits
                        // compute minimum size table less than or equal to l bits
                        z = g - w;
                        z = (z > l)?l:z;                         // table size upper limit
                        if ((f = 1 << (j = k - w)) > a + 1)
                        {
                            // try a k-w bit table
                            // too few codes for k-w bit table
                            f -= (a + 1);                             // deduct codes from patterns left
                            xp = k;
                            if (j < z)
                            {
                                while (++j < z)
                                {
                                    // try smaller tables up to z bits
                                    if ((f <<= 1) <= c[++xp])
                                    {
                                        break;                                      // enough codes to use up j bits
                                    }
                                    f -= c[xp];                                     // else deduct codes from patterns
                                }
                            }
                        }
                        z = 1 << j;                         // table entries for j-bit table

                        // allocate new table
                        if (hn[0] + z > MANY)
                        {
                            // (note: doesn't matter for fixed)
                            return(Z_DATA_ERROR);                 // overflow of MANY
                        }
                        u[h]   = q = hn[0];                       // DEBUG
                        hn[0] += z;

                        // connect to last table, if there is one
                        if (h != 0)
                        {
                            x[h] = i;                                    // save pattern for backing up
                            r[0] = (sbyte)j;                             // bits in this table
                            r[1] = (sbyte)l;                             // bits to dump before this table
                            j    = SharedUtils.URShift(i, (w - l));
                            r[2] = (int)(q - u[h - 1] - j);              // offset to this table
                            Array.Copy(r, 0, hp, (u[h - 1] + j) * 3, 3); // connect to last table
                        }
                        else
                        {
                            t[0] = q;                             // first table is returned result
                        }
                    }

                    // set up table entry in r
                    r[1] = (sbyte)(k - w);
                    if (p >= n)
                    {
                        r[0] = 128 + 64;                         // out of values--invalid code
                    }
                    else if (v[p] < s)
                    {
                        r[0] = (sbyte)(v[p] < 256?0:32 + 64);  // 256 is end-of-block
                        r[2] = v[p++];                         // simple code is just the value
                    }
                    else
                    {
                        r[0] = (sbyte)(e[v[p] - s] + 16 + 64);                          // non-simple--look up in lists
                        r[2] = d[v[p++] - s];
                    }

                    // fill code-like entries with r
                    f = 1 << (k - w);
                    for (j = SharedUtils.URShift(i, w); j < z; j += f)
                    {
                        Array.Copy(r, 0, hp, (q + j) * 3, 3);
                    }

                    // backwards increment the k-bit code i
                    for (j = 1 << (k - 1); (i & j) != 0; j = SharedUtils.URShift(j, 1))
                    {
                        i ^= j;
                    }
                    i ^= j;

                    // backup over finished tables
                    mask = (1 << w) - 1;                     // needed on HP, cc -O bug
                    while ((i & mask) != x[h])
                    {
                        h--;                         // don't need to update q
                        w   -= l;
                        mask = (1 << w) - 1;
                    }
                }
            }
            // Return Z_BUF_ERROR if we were given an incomplete table
            return(y != 0 && g != 1?Z_BUF_ERROR:Z_OK);
        }
Beispiel #15
0
 // Mapping from a distance to a distance code. dist is the distance - 1 and
 // must not have side effects. _dist_code[256] and _dist_code[257] are never
 // used.
 internal static int d_code(int dist)
 {
     return((dist) < 256?_dist_code[dist]:_dist_code[256 + (SharedUtils.URShift((dist), 7))]);
 }
Beispiel #16
0
 internal void put_short(int w)
 {
     this.put_byte((byte)w);
     this.put_byte((byte)SharedUtils.URShift(w, 8));
 }
Beispiel #17
0
        internal int Deflate(FlushType flush)
        {
            if (((this._codec.OutputBuffer == null) || ((this._codec.InputBuffer == null) && (this._codec.AvailableBytesIn != 0))) || ((this.status == 0x29a) && (flush != FlushType.Finish)))
            {
                this._codec.Message = z_errmsg[4];
                throw new ZlibException(string.Format("Something is fishy. [{0}]", this._codec.Message));
            }
            if (this._codec.AvailableBytesOut == 0)
            {
                this._codec.Message = z_errmsg[7];
                throw new ZlibException("OutputBuffer is full (AvailableBytesOut == 0)");
            }
            int num = this.last_flush;

            this.last_flush = (int)flush;
            if (this.status == 0x2a)
            {
                int b    = (8 + ((this.w_bits - 8) << 4)) << 8;
                int num3 = ((int)((int)(this.compressionLevel - 1) & 0xff)) >> 1;
                if (num3 > 3)
                {
                    num3 = 3;
                }
                b |= num3 << 6;
                if (this.strstart != 0)
                {
                    b |= 0x20;
                }
                b          += 0x1f - (b % 0x1f);
                this.status = 0x71;
                this.putShortMSB(b);
                if (this.strstart != 0)
                {
                    this.putShortMSB((int)SharedUtils.URShift(this._codec._Adler32, 0x10));
                    this.putShortMSB((int)(this._codec._Adler32 & 0xffffL));
                }
                this._codec._Adler32 = Adler.Adler32(0L, null, 0, 0);
            }
            if (this.pendingCount != 0)
            {
                this._codec.flush_pending();
                if (this._codec.AvailableBytesOut == 0)
                {
                    this.last_flush = -1;
                    return(0);
                }
            }
            else if (((this._codec.AvailableBytesIn == 0) && ((int)flush <= num)) && (flush != FlushType.Finish))
            {
                return(0);
            }
            if ((this.status == 0x29a) && (this._codec.AvailableBytesIn != 0))
            {
                this._codec.Message = z_errmsg[7];
                throw new ZlibException("status == FINISH_STATE && _codec.AvailableBytesIn != 0");
            }
            if (((this._codec.AvailableBytesIn != 0) || (this.lookahead != 0)) || ((flush != FlushType.None) && (this.status != 0x29a)))
            {
                BlockState state = this.DeflateFunction(flush);
                switch (state)
                {
                case BlockState.FinishStarted:
                case BlockState.FinishDone:
                    this.status = 0x29a;
                    break;
                }
                if ((state == BlockState.NeedMore) || (state == BlockState.FinishStarted))
                {
                    if (this._codec.AvailableBytesOut == 0)
                    {
                        this.last_flush = -1;
                    }
                    return(0);
                }
                if (state == BlockState.BlockDone)
                {
                    if (flush == FlushType.Partial)
                    {
                        this._tr_align();
                    }
                    else
                    {
                        this._tr_stored_block(0, 0, false);
                        if (flush == FlushType.Full)
                        {
                            for (int i = 0; i < this.hash_size; i++)
                            {
                                this.head[i] = 0;
                            }
                        }
                    }
                    this._codec.flush_pending();
                    if (this._codec.AvailableBytesOut == 0)
                    {
                        this.last_flush = -1;
                        return(0);
                    }
                }
            }
            if (flush != FlushType.Finish)
            {
                return(0);
            }
            if (!(this.WantRfc1950HeaderBytes && !this.Rfc1950BytesEmitted))
            {
                return(1);
            }
            this.putShortMSB((int)SharedUtils.URShift(this._codec._Adler32, 0x10));
            this.putShortMSB((int)(this._codec._Adler32 & 0xffffL));
            this._codec.flush_pending();
            this.Rfc1950BytesEmitted = true;
            return((this.pendingCount != 0) ? 0 : 1);
        }
Beispiel #18
0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int num  = 0;
            int num2 = n;

            while (true)
            {
                this.c[b[bindex + num]]++;
                num++;
                num2--;
                if (num2 == 0)
                {
                    break;
                }
            }
            if (this.c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num3 = m[0];
            int num4 = 1;

            while (num4 <= 15 && this.c[num4] == 0)
            {
                num4++;
            }
            int i = num4;

            if (num3 < num4)
            {
                num3 = num4;
            }
            num2 = 15;
            while (num2 != 0 && this.c[num2] == 0)
            {
                num2--;
            }
            int num5 = num2;

            if (num3 > num2)
            {
                num3 = num2;
            }
            m[0] = num3;
            int num6 = 1 << num4;

            while (num4 < num2)
            {
                if ((num6 -= this.c[num4]) < 0)
                {
                    return(-3);
                }
                num4++;
                num6 <<= 1;
            }
            if ((num6 -= this.c[num2]) < 0)
            {
                return(-3);
            }
            this.c[num2] += num6;
            num4          = (this.x[1] = 0);
            num           = 1;
            int num7 = 2;

            while (--num2 != 0)
            {
                num4 = (this.x[num7] = num4 + this.c[num]);
                num7++;
                num++;
            }
            num2 = 0;
            num  = 0;
            while (true)
            {
                if ((num4 = b[bindex + num]) != 0)
                {
                    v[this.x[num4]++] = num2;
                }
                num++;
                if (++num2 >= n)
                {
                    break;
                }
            }
            n    = this.x[num5];
            num2 = (this.x[0] = 0);
            num  = 0;
            int num8 = -1;
            int num9 = -num3;

            this.u[0] = 0;
            int num10 = 0;
            int num11 = 0;

            for (; i <= num5; i++)
            {
                int num12 = this.c[i];
                while (num12-- != 0)
                {
                    int num14;
                    while (i > num9 + num3)
                    {
                        num8++;
                        num9 += num3;
                        num11 = num5 - num9;
                        num11 = ((num11 <= num3) ? num11 : num3);
                        if ((num14 = 1 << (num4 = i - num9)) > num12 + 1)
                        {
                            num14 -= num12 + 1;
                            num7   = i;
                            if (num4 < num11)
                            {
                                while (++num4 < num11 && (num14 <<= 1) > this.c[++num7])
                                {
                                    num14 -= this.c[num7];
                                }
                            }
                        }
                        num11 = 1 << num4;
                        if (hn[0] + num11 > 1440)
                        {
                            return(-3);
                        }
                        num10  = (this.u[num8] = hn[0]);
                        hn[0] += num11;
                        if (num8 != 0)
                        {
                            this.x[num8] = num2;
                            this.r[0]    = (sbyte)num4;
                            this.r[1]    = (sbyte)num3;
                            num4         = SharedUtils.URShift(num2, num9 - num3);
                            this.r[2]    = num10 - this.u[num8 - 1] - num4;
                            Array.Copy(this.r, 0, hp, (this.u[num8 - 1] + num4) * 3, 3);
                        }
                        else
                        {
                            t[0] = num10;
                        }
                    }
                    this.r[1] = (sbyte)(i - num9);
                    if (num >= n)
                    {
                        this.r[0] = 192;
                    }
                    else if (v[num] < s)
                    {
                        this.r[0] = (sbyte)((v[num] >= 256) ? 96 : 0);
                        this.r[2] = v[num++];
                    }
                    else
                    {
                        this.r[0] = (sbyte)(e[v[num] - s] + 16 + 64);
                        this.r[2] = d[v[num++] - s];
                    }
                    num14 = 1 << i - num9;
                    for (num4 = SharedUtils.URShift(num2, num9); num4 < num11; num4 += num14)
                    {
                        Array.Copy(this.r, 0, hp, (num10 + num4) * 3, 3);
                    }
                    num4 = 1 << i - 1;
                    while ((num2 & num4) != 0)
                    {
                        num2 ^= num4;
                        num4  = SharedUtils.URShift(num4, 1);
                    }
                    num2 ^= num4;
                    int num17 = (1 << num9) - 1;
                    while ((num2 & num17) != this.x[num8])
                    {
                        num8--;
                        num9 -= num3;
                        num17 = (1 << num9) - 1;
                    }
                }
            }
            return((num6 != 0 && num5 != 1) ? (-5) : 0);
        }
Beispiel #19
0
 internal static int d_code(int dist)
 {
     return((dist < 0x100) ? _dist_code[dist] : _dist_code[0x100 + SharedUtils.URShift(dist, 7)]);
 }
Beispiel #20
0
 /// <summary>
 /// Map from a distanceCameraToPoint to a distanceCameraToPoint code.
 /// </summary>
 /// <remarks>
 /// No side effects. _dist_code[256] and _dist_code[257] are never used.
 /// </remarks>
 internal static int DistanceCode(int dist)
 {
     return((dist < 256)
         ? _dist_code[dist]
         : _dist_code[256 + SharedUtils.URShift(dist, 7)]);
 }
Beispiel #21
0
 internal static int DistanceCode(int dist)
 {
     return(dist < 256 ? (int)Tree._dist_code[dist] : (int)Tree._dist_code[256 + SharedUtils.URShift(dist, 7)]);
 }
Beispiel #22
0
        internal int Process(InflateBlocks blocks, int r)
        {
            int       num;
            int       num10;
            bool      flag;
            int       number = 0;
            int       bitk   = 0;
            int       nextIn = 0;
            ZlibCodec z      = blocks._codec;

            nextIn = z.NextIn;
            int availableBytesIn = z.AvailableBytesIn;

            number = blocks.bitb;
            bitk   = blocks.bitk;
            int write = blocks.write;
            int num9  = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);

            goto Label_0C3A;
Label_0196:
            this.need       = this.lbits;
            this.tree       = this.ltree;
            this.tree_index = this.ltree_index;
            this.mode       = 1;
Label_01C3:
            num = this.need;
            while (bitk < num)
            {
                if (availableBytesIn != 0)
                {
                    r = 0;
                }
                else
                {
                    blocks.bitb        = number;
                    blocks.bitk        = bitk;
                    z.AvailableBytesIn = availableBytesIn;
                    z.TotalBytesIn    += nextIn - z.NextIn;
                    z.NextIn           = nextIn;
                    blocks.write       = write;
                    return(blocks.Flush(r));
                }
                availableBytesIn--;
                number |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                bitk   += 8;
            }
            int index = (this.tree_index + (number & inflate_mask[num])) * 3;

            number = SharedUtils.URShift(number, this.tree[index + 1]);
            bitk  -= this.tree[index + 1];
            int num3 = this.tree[index];

            if (num3 == 0)
            {
                this.lit  = this.tree[index + 2];
                this.mode = 6;
                goto Label_0C3A;
            }
            if ((num3 & 0x10) != 0)
            {
                this.get_Renamed = num3 & 15;
                this.len         = this.tree[index + 2];
                this.mode        = 2;
                goto Label_0C3A;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0C3A;
            }
            if ((num3 & 0x20) != 0)
            {
                this.mode = 7;
                goto Label_0C3A;
            }
            this.mode          = 9;
            z.Message          = "invalid literal/length code";
            r                  = -3;
            blocks.bitb        = number;
            blocks.bitk        = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            blocks.write       = write;
            return(blocks.Flush(r));

Label_04AE:
            num = this.need;
            while (bitk < num)
            {
                if (availableBytesIn != 0)
                {
                    r = 0;
                }
                else
                {
                    blocks.bitb        = number;
                    blocks.bitk        = bitk;
                    z.AvailableBytesIn = availableBytesIn;
                    z.TotalBytesIn    += nextIn - z.NextIn;
                    z.NextIn           = nextIn;
                    blocks.write       = write;
                    return(blocks.Flush(r));
                }
                availableBytesIn--;
                number |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                bitk   += 8;
            }
            index  = (this.tree_index + (number & inflate_mask[num])) * 3;
            number = number >> this.tree[index + 1];
            bitk  -= this.tree[index + 1];
            num3   = this.tree[index];
            if ((num3 & 0x10) != 0)
            {
                this.get_Renamed = num3 & 15;
                this.dist        = this.tree[index + 2];
                this.mode        = 4;
                goto Label_0C3A;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0C3A;
            }
            this.mode          = 9;
            z.Message          = "invalid distance code";
            r                  = -3;
            blocks.bitb        = number;
            blocks.bitk        = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            blocks.write       = write;
            return(blocks.Flush(r));

Label_0730:
            num10 = write - this.dist;
            while (num10 < 0)
            {
                num10 += blocks.end;
            }
            while (this.len != 0)
            {
                if (num9 == 0)
                {
                    if ((write == blocks.end) && (blocks.read != 0))
                    {
                        write = 0;
                        num9  = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                    }
                    if (num9 == 0)
                    {
                        blocks.write = write;
                        r            = blocks.Flush(r);
                        write        = blocks.write;
                        num9         = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                        if ((write == blocks.end) && (blocks.read != 0))
                        {
                            write = 0;
                            num9  = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                        }
                        if (num9 == 0)
                        {
                            blocks.bitb        = number;
                            blocks.bitk        = bitk;
                            z.AvailableBytesIn = availableBytesIn;
                            z.TotalBytesIn    += nextIn - z.NextIn;
                            z.NextIn           = nextIn;
                            blocks.write       = write;
                            return(blocks.Flush(r));
                        }
                    }
                }
                blocks.window[write++] = blocks.window[num10++];
                num9--;
                if (num10 == blocks.end)
                {
                    num10 = 0;
                }
                this.len--;
            }
            this.mode = 0;
            goto Label_0C3A;
Label_0B44:
            r                  = 1;
            blocks.bitb        = number;
            blocks.bitk        = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            blocks.write       = write;
            return(blocks.Flush(r));

Label_0C3A:
            flag = true;
            switch (this.mode)
            {
            case 0:
                if ((num9 < 0x102) || (availableBytesIn < 10))
                {
                    goto Label_0196;
                }
                blocks.bitb        = number;
                blocks.bitk        = bitk;
                z.AvailableBytesIn = availableBytesIn;
                z.TotalBytesIn    += nextIn - z.NextIn;
                z.NextIn           = nextIn;
                blocks.write       = write;
                r                = this.InflateFast(this.lbits, this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, z);
                nextIn           = z.NextIn;
                availableBytesIn = z.AvailableBytesIn;
                number           = blocks.bitb;
                bitk             = blocks.bitk;
                write            = blocks.write;
                num9             = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                if (r == 0)
                {
                    goto Label_0196;
                }
                this.mode = (r == 1) ? 7 : 9;
                goto Label_0C3A;

            case 1:
                goto Label_01C3;

            case 2:
                num = this.get_Renamed;
                while (bitk < num)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        blocks.bitb        = number;
                        blocks.bitk        = bitk;
                        z.AvailableBytesIn = availableBytesIn;
                        z.TotalBytesIn    += nextIn - z.NextIn;
                        z.NextIn           = nextIn;
                        blocks.write       = write;
                        return(blocks.Flush(r));
                    }
                    availableBytesIn--;
                    number |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk   += 8;
                }
                this.len       += number & inflate_mask[num];
                number          = number >> num;
                bitk           -= num;
                this.need       = this.dbits;
                this.tree       = this.dtree;
                this.tree_index = this.dtree_index;
                this.mode       = 3;
                goto Label_04AE;

            case 3:
                goto Label_04AE;

            case 4:
                num = this.get_Renamed;
                while (bitk < num)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        blocks.bitb        = number;
                        blocks.bitk        = bitk;
                        z.AvailableBytesIn = availableBytesIn;
                        z.TotalBytesIn    += nextIn - z.NextIn;
                        z.NextIn           = nextIn;
                        blocks.write       = write;
                        return(blocks.Flush(r));
                    }
                    availableBytesIn--;
                    number |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk   += 8;
                }
                this.dist += number & inflate_mask[num];
                number     = number >> num;
                bitk      -= num;
                this.mode  = 5;
                goto Label_0730;

            case 5:
                goto Label_0730;

            case 6:
                if (num9 == 0)
                {
                    if ((write == blocks.end) && (blocks.read != 0))
                    {
                        write = 0;
                        num9  = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                    }
                    if (num9 == 0)
                    {
                        blocks.write = write;
                        r            = blocks.Flush(r);
                        write        = blocks.write;
                        num9         = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                        if ((write == blocks.end) && (blocks.read != 0))
                        {
                            write = 0;
                            num9  = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                        }
                        if (num9 == 0)
                        {
                            blocks.bitb        = number;
                            blocks.bitk        = bitk;
                            z.AvailableBytesIn = availableBytesIn;
                            z.TotalBytesIn    += nextIn - z.NextIn;
                            z.NextIn           = nextIn;
                            blocks.write       = write;
                            return(blocks.Flush(r));
                        }
                    }
                }
                r = 0;
                blocks.window[write++] = (byte)this.lit;
                num9--;
                this.mode = 0;
                goto Label_0C3A;

            case 7:
                if (bitk > 7)
                {
                    bitk -= 8;
                    availableBytesIn++;
                    nextIn--;
                }
                blocks.write = write;
                r            = blocks.Flush(r);
                write        = blocks.write;
                num9         = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write);
                if (blocks.read != blocks.write)
                {
                    blocks.bitb        = number;
                    blocks.bitk        = bitk;
                    z.AvailableBytesIn = availableBytesIn;
                    z.TotalBytesIn    += nextIn - z.NextIn;
                    z.NextIn           = nextIn;
                    blocks.write       = write;
                    return(blocks.Flush(r));
                }
                this.mode = 8;
                goto Label_0B44;

            case 8:
                goto Label_0B44;

            case 9:
                r                  = -3;
                blocks.bitb        = number;
                blocks.bitk        = bitk;
                z.AvailableBytesIn = availableBytesIn;
                z.TotalBytesIn    += nextIn - z.NextIn;
                z.NextIn           = nextIn;
                blocks.write       = write;
                return(blocks.Flush(r));
            }
            r                  = -2;
            blocks.bitb        = number;
            blocks.bitk        = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            blocks.write       = write;
            return(blocks.Flush(r));
        }
Beispiel #23
0
        internal int Process(int r)
        {
            int[] numArray;
            int[] numArray2;
            int   num8;
            bool  flag;
            int   nextIn           = this._codec.NextIn;
            int   availableBytesIn = this._codec.AvailableBytesIn;
            int   bitb             = this.bitb;
            int   bitk             = this.bitk;
            int   write            = this.write;
            int   num7             = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);

            goto Label_11DA;
Label_0933:
            while (this.index < (4 + SharedUtils.URShift(this.table, 10)))
            {
                while (bitk < 3)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                    availableBytesIn--;
                    bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.blens[border[this.index++]] = bitb & 7;
                bitb  = SharedUtils.URShift(bitb, 3);
                bitk -= 3;
            }
            while (this.index < 0x13)
            {
                this.blens[border[this.index++]] = 0;
            }
            this.bb[0] = 7;
            int index = this.inftree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, this._codec);

            if (index != 0)
            {
                r = index;
                if (r == -3)
                {
                    this.blens = null;
                    this.mode  = 9;
                }
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));
            }
            this.index = 0;
            this.mode  = 5;
Label_0DD2:
            flag  = true;
            index = this.table;
            if (this.index >= ((0x102 + (index & 0x1f)) + ((index >> 5) & 0x1f)))
            {
                this.tb[0] = -1;
                numArray   = new int[] { 9 };
                numArray2  = new int[] { 6 };
                int[] tl = new int[1];
                int[] td = new int[1];
                index = this.table;
                index = this.inftree.inflate_trees_dynamic(0x101 + (index & 0x1f), 1 + ((index >> 5) & 0x1f), this.blens, numArray, numArray2, tl, td, this.hufts, this._codec);
                if (index != 0)
                {
                    if (index == -3)
                    {
                        this.blens = null;
                        this.mode  = 9;
                    }
                    r         = index;
                    this.bitb = bitb;
                    this.bitk = bitk;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                this.codes.Init(numArray[0], numArray2[0], this.hufts, tl[0], this.hufts, td[0]);
                this.mode = 6;
            }
            else
            {
                index = this.bb[0];
                while (bitk < index)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                    availableBytesIn--;
                    bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                if (this.tb[0] == -1)
                {
                }
                index = this.hufts[((this.tb[0] + (bitb & inflate_mask[index])) * 3) + 1];
                int num10 = this.hufts[((this.tb[0] + (bitb & inflate_mask[index])) * 3) + 2];
                if (num10 < 0x10)
                {
                    bitb  = SharedUtils.URShift(bitb, index);
                    bitk -= index;
                    this.blens[this.index++] = num10;
                }
                else
                {
                    num8 = (num10 == 0x12) ? 7 : (num10 - 14);
                    int num9 = (num10 == 0x12) ? 11 : 3;
                    while (bitk < (index + num8))
                    {
                        if (availableBytesIn != 0)
                        {
                            r = 0;
                        }
                        else
                        {
                            this.bitb = bitb;
                            this.bitk = bitk;
                            this._codec.AvailableBytesIn = availableBytesIn;
                            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                            this._codec.NextIn           = nextIn;
                            this.write = write;
                            return(this.Flush(r));
                        }
                        availableBytesIn--;
                        bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    bitb  = SharedUtils.URShift(bitb, index);
                    bitk -= index;
                    num9 += bitb & inflate_mask[num8];
                    bitb  = SharedUtils.URShift(bitb, num8);
                    bitk -= num8;
                    num8  = this.index;
                    index = this.table;
                    if (((num8 + num9) > ((0x102 + (index & 0x1f)) + ((index >> 5) & 0x1f))) || ((num10 == 0x10) && (num8 < 1)))
                    {
                        this.blens          = null;
                        this.mode           = 9;
                        this._codec.Message = "invalid bit length repeat";
                        r         = -3;
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                    num10 = (num10 == 0x10) ? this.blens[num8 - 1] : 0;
                    do
                    {
                        this.blens[num8++] = num10;
                    }while (--num9 != 0);
                    this.index = num8;
                }
                goto Label_0DD2;
            }
Label_0F15:
            this.bitb = bitb;
            this.bitk = bitk;
            this._codec.AvailableBytesIn = availableBytesIn;
            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
            this._codec.NextIn           = nextIn;
            this.write = write;
            if ((r = this.codes.Process(this, r)) != 1)
            {
                return(this.Flush(r));
            }
            r                = 0;
            nextIn           = this._codec.NextIn;
            availableBytesIn = this._codec.AvailableBytesIn;
            bitb             = this.bitb;
            bitk             = this.bitk;
            write            = this.write;
            num7             = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
            if (this.last == 0)
            {
                this.mode = 0;
                goto Label_11DA;
            }
            this.mode = 7;
Label_1007:
            this.write = write;
            r          = this.Flush(r);
            write      = this.write;
            num7       = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
            if (this.read != this.write)
            {
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));
            }
            this.mode = 8;
Label_10BD:
            r         = 1;
            this.bitb = bitb;
            this.bitk = bitk;
            this._codec.AvailableBytesIn = availableBytesIn;
            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
            this._codec.NextIn           = nextIn;
            this.write = write;
            return(this.Flush(r));

Label_11DA:
            flag = true;
            switch (this.mode)
            {
            case 0:
                while (bitk < 3)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                    availableBytesIn--;
                    bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                index     = bitb & 7;
                this.last = index & 1;
                switch (SharedUtils.URShift(index, 1))
                {
                case 0:
                    bitb      = SharedUtils.URShift(bitb, 3);
                    bitk     -= 3;
                    index     = bitk & 7;
                    bitb      = SharedUtils.URShift(bitb, index);
                    bitk     -= index;
                    this.mode = 1;
                    goto Label_11DA;

                case 1:
                {
                    numArray  = new int[1];
                    numArray2 = new int[1];
                    int[][] numArray3 = new int[1][];
                    int[][] numArray4 = new int[1][];
                    InfTree.inflate_trees_fixed(numArray, numArray2, numArray3, numArray4, this._codec);
                    this.codes.Init(numArray[0], numArray2[0], numArray3[0], 0, numArray4[0], 0);
                    bitb      = SharedUtils.URShift(bitb, 3);
                    bitk     -= 3;
                    this.mode = 6;
                    goto Label_11DA;
                }

                case 2:
                    bitb      = SharedUtils.URShift(bitb, 3);
                    bitk     -= 3;
                    this.mode = 3;
                    goto Label_11DA;

                case 3:
                    bitb                = SharedUtils.URShift(bitb, 3);
                    bitk               -= 3;
                    this.mode           = 9;
                    this._codec.Message = "invalid block type";
                    r         = -3;
                    this.bitb = bitb;
                    this.bitk = bitk;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                goto Label_11DA;

            case 1:
                while (bitk < 0x20)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                    availableBytesIn--;
                    bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                if ((SharedUtils.URShift(~bitb, 0x10) & 0xffff) != (bitb & 0xffff))
                {
                    this.mode           = 9;
                    this._codec.Message = "invalid stored block lengths";
                    r         = -3;
                    this.bitb = bitb;
                    this.bitk = bitk;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                this.left = bitb & 0xffff;
                bitb      = bitk = 0;
                this.mode = (this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0);
                goto Label_11DA;

            case 2:
                if (availableBytesIn != 0)
                {
                    if (num7 == 0)
                    {
                        if ((write == this.end) && (this.read != 0))
                        {
                            write = 0;
                            num7  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                        }
                        if (num7 == 0)
                        {
                            this.write = write;
                            r          = this.Flush(r);
                            write      = this.write;
                            num7       = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                            if ((write == this.end) && (this.read != 0))
                            {
                                write = 0;
                                num7  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                            }
                            if (num7 == 0)
                            {
                                this.bitb = bitb;
                                this.bitk = bitk;
                                this._codec.AvailableBytesIn = availableBytesIn;
                                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                                this._codec.NextIn           = nextIn;
                                this.write = write;
                                return(this.Flush(r));
                            }
                        }
                    }
                    r     = 0;
                    index = this.left;
                    if (index > availableBytesIn)
                    {
                        index = availableBytesIn;
                    }
                    if (index > num7)
                    {
                        index = num7;
                    }
                    Array.Copy(this._codec.InputBuffer, nextIn, this.window, write, index);
                    nextIn           += index;
                    availableBytesIn -= index;
                    write            += index;
                    num7             -= index;
                    this.left        -= index;
                    if (this.left == 0)
                    {
                        this.mode = (this.last != 0) ? 7 : 0;
                    }
                    goto Label_11DA;
                }
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));

            case 3:
                while (bitk < 14)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                    availableBytesIn--;
                    bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.table = index = bitb & 0x3fff;
                if (((index & 0x1f) > 0x1d) || (((index >> 5) & 0x1f) > 0x1d))
                {
                    this.mode           = 9;
                    this._codec.Message = "too many length or distance symbols";
                    r         = -3;
                    this.bitb = bitb;
                    this.bitk = bitk;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                index = (0x102 + (index & 0x1f)) + ((index >> 5) & 0x1f);
                if ((this.blens == null) || (this.blens.Length < index))
                {
                    this.blens = new int[index];
                }
                else
                {
                    for (num8 = 0; num8 < index; num8++)
                    {
                        this.blens[num8] = 0;
                    }
                }
                bitb       = SharedUtils.URShift(bitb, 14);
                bitk      -= 14;
                this.index = 0;
                this.mode  = 4;
                goto Label_0933;

            case 4:
                goto Label_0933;

            case 5:
                goto Label_0DD2;

            case 6:
                goto Label_0F15;

            case 7:
                goto Label_1007;

            case 8:
                goto Label_10BD;

            case 9:
                r         = -3;
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));
            }
            r         = -2;
            this.bitb = bitb;
            this.bitk = bitk;
            this._codec.AvailableBytesIn = availableBytesIn;
            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
            this._codec.NextIn           = nextIn;
            this.write = write;
            return(this.Flush(r));
        }
Beispiel #24
0
        internal StaticTree staticTree; // the corresponding static tree


        /// <summary>
        ///     Map from a distance to a distance code.
        /// </summary>
        /// <remarks>
        ///     No side effects. _dist_code[256] and _dist_code[257] are never used.
        /// </remarks>
        internal static int DistanceCode(int dist) => dist < 256
                        ? _dist_code[dist]
                        : _dist_code[256 + SharedUtils.URShift(dist, 7)];
Beispiel #25
0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int index = 0;
            int num5  = n;

            do
            {
                this.c[b[bindex + index]]++;
                index++;
                num5--;
            }while (num5 != 0);
            if (this.c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num8 = m[0];
            int num6 = 1;

            while (num6 <= 15)
            {
                if (this.c[num6] != 0)
                {
                    break;
                }
                num6++;
            }
            int num7 = num6;

            if (num8 < num6)
            {
                num8 = num6;
            }
            num5 = 15;
            while (num5 != 0)
            {
                if (this.c[num5] != 0)
                {
                    break;
                }
                num5--;
            }
            int num3 = num5;

            if (num8 > num5)
            {
                num8 = num5;
            }
            m[0] = num8;
            int num14 = ((int)1) << num6;

            while (num6 < num5)
            {
                num14 -= this.c[num6];
                if (num14 < 0)
                {
                    return(-3);
                }
                num6++;
                num14 = num14 << 1;
            }
            num14 -= this.c[num5];
            if (num14 < 0)
            {
                return(-3);
            }
            this.c[num5] += num14;
            this.x[1]     = num6 = 0;
            index         = 1;
            int num13 = 2;

            while (--num5 != 0)
            {
                this.x[num13] = num6 += this.c[index];
                num13++;
                index++;
            }
            num5  = 0;
            index = 0;
            do
            {
                num6 = b[bindex + index];
                if (num6 != 0)
                {
                    v[this.x[num6]++] = num5;
                }
                index++;
            }while (++num5 < n);
            n         = this.x[num3];
            this.x[0] = num5 = 0;
            index     = 0;
            int num4 = -1;
            int bits = -num8;

            this.u[0] = 0;
            int num11 = 0;
            int num15 = 0;

            while (num7 <= num3)
            {
                int num = this.c[num7];
                while (num-- != 0)
                {
                    int num2;
                    while (num7 > (bits + num8))
                    {
                        num4++;
                        bits += num8;
                        num15 = num3 - bits;
                        num15 = (num15 > num8) ? num8 : num15;
                        if ((num2 = ((int)1) << (num6 = num7 - bits)) > (num + 1))
                        {
                            num2 -= num + 1;
                            num13 = num7;
                            if (num6 < num15)
                            {
                                while (++num6 < num15)
                                {
                                    if ((num2 = num2 << 1) <= this.c[++num13])
                                    {
                                        break;
                                    }
                                    num2 -= this.c[num13];
                                }
                            }
                        }
                        num15 = ((int)1) << num6;
                        if ((hn[0] + num15) > 0x5a0)
                        {
                            return(-3);
                        }
                        this.u[num4] = num11 = hn[0];
                        hn[0]       += num15;
                        if (num4 != 0)
                        {
                            this.x[num4] = num5;
                            this.r[0]    = (sbyte)num6;
                            this.r[1]    = (sbyte)num8;
                            num6         = SharedUtils.URShift(num5, bits - num8);
                            this.r[2]    = (num11 - this.u[num4 - 1]) - num6;
                            Array.Copy(this.r, 0, hp, (this.u[num4 - 1] + num6) * 3, 3);
                        }
                        else
                        {
                            t[0] = num11;
                        }
                    }
                    this.r[1] = (sbyte)(num7 - bits);
                    if (index >= n)
                    {
                        this.r[0] = 0xc0;
                    }
                    else if (v[index] < s)
                    {
                        this.r[0] = (v[index] < 0x100) ? ((sbyte)0) : ((sbyte)0x60);
                        this.r[2] = v[index++];
                    }
                    else
                    {
                        this.r[0] = (sbyte)((e[v[index] - s] + 0x10) + 0x40);
                        this.r[2] = d[v[index++] - s];
                    }
                    num2 = ((int)1) << (num7 - bits);
                    num6 = SharedUtils.URShift(num5, bits);
                    while (num6 < num15)
                    {
                        Array.Copy(this.r, 0, hp, (num11 + num6) * 3, 3);
                        num6 += num2;
                    }
                    num6 = ((int)1) << (num7 - 1);
                    while ((num5 & num6) != 0)
                    {
                        num5 ^= num6;
                        num6  = SharedUtils.URShift(num6, 1);
                    }
                    num5 ^= num6;
                    for (int i = (((int)1) << bits) - 1; (num5 & i) != this.x[num4]; i = (((int)1) << bits) - 1)
                    {
                        num4--;
                        bits -= num8;
                    }
                }
                num7++;
            }
            return(((num14 != 0) && (num3 != 1)) ? -5 : 0);
        }
Beispiel #26
0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int num1 = 0;
            int num2 = n;

            do
            {
                ++this.c[b[bindex + num1]];
                ++num1;
                --num2;
            }while (num2 != 0);
            if (this.c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num3   = m[0];
            int index1 = 1;

            while (index1 <= 15 && this.c[index1] == 0)
            {
                ++index1;
            }
            int index2 = index1;

            if (num3 < index1)
            {
                num3 = index1;
            }
            int index3 = 15;

            while (index3 != 0 && this.c[index3] == 0)
            {
                --index3;
            }
            int index4 = index3;

            if (num3 > index3)
            {
                num3 = index3;
            }
            m[0] = num3;
            int num4 = 1 << index1;

            while (index1 < index3)
            {
                int num5;
                if ((num5 = num4 - this.c[index1]) < 0)
                {
                    return(-3);
                }
                ++index1;
                num4 = num5 << 1;
            }
            int num6;

            if ((num6 = num4 - this.c[index3]) < 0)
            {
                return(-3);
            }
            this.c[index3] += num6;
            int num7;

            this.x[1] = num7 = 0;
            int index5 = 1;
            int index6 = 2;

            while (--index3 != 0)
            {
                this.x[index6] = (num7 += this.c[index5]);
                ++index6;
                ++index5;
            }
            int num8 = 0;
            int num9 = 0;

            do
            {
                int index7;
                if ((index7 = b[bindex + num9]) != 0)
                {
                    v[this.x[index7]++] = num8;
                }
                ++num9;
            }while (++num8 < n);
            n = this.x[index4];
            int number1;

            this.x[0] = number1 = 0;
            int index8 = 0;
            int index9 = -1;
            int bits   = -num3;

            this.u[0] = 0;
            int num10 = 0;
            int num11 = 0;

            for (; index2 <= index4; ++index2)
            {
                int num5 = this.c[index2];
                while (num5-- != 0)
                {
                    while (index2 > bits + num3)
                    {
                        ++index9;
                        bits += num3;
                        int num12 = index4 - bits;
                        int num13 = num12 > num3 ? num3 : num12;
                        int num14;
                        int num15;
                        if ((num15 = 1 << (num14 = index2 - bits)) > num5 + 1)
                        {
                            int num16  = num15 - (num5 + 1);
                            int index7 = index2;
                            if (num14 < num13)
                            {
                                int num17;
                                while (++num14 < num13 && (num17 = num16 << 1) > this.c[++index7])
                                {
                                    num16 = num17 - this.c[index7];
                                }
                            }
                        }
                        num11 = 1 << num14;
                        if (hn[0] + num11 > 1440)
                        {
                            return(-3);
                        }
                        this.u[index9] = num10 = hn[0];
                        hn[0]         += num11;
                        if (index9 != 0)
                        {
                            this.x[index9] = number1;
                            this.r[0]      = (int)(sbyte)num14;
                            this.r[1]      = (int)(sbyte)num3;
                            int num16 = SharedUtils.URShift(number1, bits - num3);
                            this.r[2] = num10 - this.u[index9 - 1] - num16;
                            Array.Copy((Array)this.r, 0, (Array)hp, (this.u[index9 - 1] + num16) * 3, 3);
                        }
                        else
                        {
                            t[0] = num10;
                        }
                    }
                    this.r[1] = (int)(sbyte)(index2 - bits);
                    if (index8 >= n)
                    {
                        this.r[0] = 192;
                    }
                    else if (v[index8] < s)
                    {
                        this.r[0] = v[index8] < 256 ? 0 : 96;
                        this.r[2] = v[index8++];
                    }
                    else
                    {
                        this.r[0] = (int)(sbyte)(e[v[index8] - s] + 16 + 64);
                        this.r[2] = d[v[index8++] - s];
                    }
                    int num18 = 1 << index2 - bits;
                    int num19 = SharedUtils.URShift(number1, bits);
                    while (num19 < num11)
                    {
                        Array.Copy((Array)this.r, 0, (Array)hp, (num10 + num19) * 3, 3);
                        num19 += num18;
                    }
                    int number2;
                    for (number2 = 1 << index2 - 1; (number1 & number2) != 0; number2 = SharedUtils.URShift(number2, 1))
                    {
                        number1 ^= number2;
                    }
                    number1 ^= number2;
                    for (int index7 = (1 << bits) - 1; (number1 & index7) != this.x[index9]; index7 = (1 << bits) - 1)
                    {
                        --index9;
                        bits -= num3;
                    }
                }
            }
            return(num6 == 0 || index4 == 1 ? 0 : -5);
        }
Beispiel #27
0
        // Token: 0x060007A9 RID: 1961 RVA: 0x000447C0 File Offset: 0x000429C0
        private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int num  = 0;
            int num2 = n;

            do
            {
                this.c[b[bindex + num]]++;
                num++;
                num2--;
            }while (num2 != 0);
            if (this.c[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num3 = m[0];
            int i    = 1;

            while (i <= 15 && this.c[i] == 0)
            {
                i++;
            }
            int j = i;

            if (num3 < i)
            {
                num3 = i;
            }
            num2 = 15;
            while (num2 != 0 && this.c[num2] == 0)
            {
                num2--;
            }
            int num4 = num2;

            if (num3 > num2)
            {
                num3 = num2;
            }
            m[0] = num3;
            int num5 = 1 << i;

            while (i < num2)
            {
                if ((num5 -= this.c[i]) < 0)
                {
                    return(-3);
                }
                i++;
                num5 <<= 1;
            }
            if ((num5 -= this.c[num2]) < 0)
            {
                return(-3);
            }
            this.c[num2] += num5;
            int[] array = this.x;
            int   num6  = 1;
            int   num7  = 0;

            i           = 0;
            array[num6] = num7;
            num         = 1;
            int num8 = 2;

            while (--num2 != 0)
            {
                i = (this.x[num8] = i + this.c[num]);
                num8++;
                num++;
            }
            num2 = 0;
            num  = 0;
            do
            {
                if ((i = b[bindex + num]) != 0)
                {
                    v[this.x[i]++] = num2;
                }
                num++;
            }while (++num2 < n);
            n = this.x[num4];
            int[] array2 = this.x;
            int   num9   = 0;
            int   num10  = 0;

            num2         = 0;
            array2[num9] = num10;
            num          = 0;
            int num11 = -1;
            int num12 = -num3;

            this.u[0] = 0;
            int num13 = 0;
            int num14 = 0;

            while (j <= num4)
            {
                int num15 = this.c[j];
                while (num15-- != 0)
                {
                    int num16;
                    while (j > num12 + num3)
                    {
                        num11++;
                        num12 += num3;
                        num14  = num4 - num12;
                        num14  = ((num14 > num3) ? num3 : num14);
                        if ((num16 = 1 << ((i = j - num12) & 31)) > num15 + 1)
                        {
                            num16 -= num15 + 1;
                            num8   = j;
                            if (i < num14)
                            {
                                while (++i < num14 && (num16 <<= 1) > this.c[++num8])
                                {
                                    num16 -= this.c[num8];
                                }
                            }
                        }
                        num14 = 1 << i;
                        if (hn[0] + num14 > 1440)
                        {
                            return(-3);
                        }
                        num13  = (this.u[num11] = hn[0]);
                        hn[0] += num14;
                        if (num11 != 0)
                        {
                            this.x[num11] = num2;
                            this.r[0]     = (int)((sbyte)i);
                            this.r[1]     = (int)((sbyte)num3);
                            i             = SharedUtils.URShift(num2, num12 - num3);
                            this.r[2]     = num13 - this.u[num11 - 1] - i;
                            Array.Copy(this.r, 0, hp, (this.u[num11 - 1] + i) * 3, 3);
                        }
                        else
                        {
                            t[0] = num13;
                        }
                    }
                    this.r[1] = (int)((sbyte)(j - num12));
                    if (num >= n)
                    {
                        this.r[0] = 192;
                    }
                    else if (v[num] < s)
                    {
                        this.r[0] = (int)((v[num] < 256) ? 0 : 96);
                        this.r[2] = v[num++];
                    }
                    else
                    {
                        this.r[0] = (int)((sbyte)(e[v[num] - s] + 16 + 64));
                        this.r[2] = d[v[num++] - s];
                    }
                    num16 = 1 << j - num12;
                    for (i = SharedUtils.URShift(num2, num12); i < num14; i += num16)
                    {
                        Array.Copy(this.r, 0, hp, (num13 + i) * 3, 3);
                    }
                    i = 1 << j - 1;
                    while ((num2 & i) != 0)
                    {
                        num2 ^= i;
                        i     = SharedUtils.URShift(i, 1);
                    }
                    num2 ^= i;
                    int num17 = (1 << num12) - 1;
                    while ((num2 & num17) != this.x[num11])
                    {
                        num11--;
                        num12 -= num3;
                        num17  = (1 << num12) - 1;
                    }
                }
                j++;
            }
            if (num5 != 0)
            {
                if (num4 != 1)
                {
                    return(-5);
                }
            }
            return(0);
        }