Exemple #1
0
        private bool ReadTables20()
        {
            byte[] BitLength = new byte[Compress.BC20];
            byte[] Table = new byte[Compress.MC20 * 4];
            int    TableSize, N, I;

            if (inAddr > readTop - 25)
            {
                if (!unpReadBuf())
                {
                    return(false);
                }
            }
            int BitField = GetBits();

            UnpAudioBlock = (BitField & 0x8000);

            if (0 == (BitField & 0x4000))
            {
                // memset(UnpOldTable20,0,sizeof(UnpOldTable20));
                Utility.Fill(UnpOldTable20, (byte)0);
            }
            AddBits(2);

            if (UnpAudioBlock != 0)
            {
                UnpChannels = ((Utility.URShift(BitField, 12)) & 3) + 1;
                if (UnpCurChannel >= UnpChannels)
                {
                    UnpCurChannel = 0;
                }
                AddBits(2);
                TableSize = Compress.MC20 * UnpChannels;
            }
            else
            {
                TableSize = Compress.NC20 + Compress.DC20 + Compress.RC20;
            }
            for (I = 0; I < Compress.BC20; I++)
            {
                BitLength[I] = (byte)(Utility.URShift(GetBits(), 12));
                AddBits(4);
            }
            UnpackUtility.makeDecodeTables(BitLength, 0, BD, Compress.BC20);
            I = 0;
            while (I < TableSize)
            {
                if (inAddr > readTop - 5)
                {
                    if (!unpReadBuf())
                    {
                        return(false);
                    }
                }
                int Number = this.decodeNumber(BD);
                if (Number < 16)
                {
                    Table[I] = (byte)((Number + UnpOldTable20[I]) & 0xf);
                    I++;
                }
                else if (Number == 16)
                {
                    N = (Utility.URShift(GetBits(), 14)) + 3;
                    AddBits(2);
                    while (N-- > 0 && I < TableSize)
                    {
                        Table[I] = Table[I - 1];
                        I++;
                    }
                }
                else
                {
                    if (Number == 17)
                    {
                        N = (Utility.URShift(GetBits(), 13)) + 3;
                        AddBits(3);
                    }
                    else
                    {
                        N = (Utility.URShift(GetBits(), 9)) + 11;
                        AddBits(7);
                    }
                    while (N-- > 0 && I < TableSize)
                    {
                        Table[I++] = 0;
                    }
                }
            }
            if (inAddr > readTop)
            {
                return(true);
            }
            if (UnpAudioBlock != 0)
            {
                for (I = 0; I < UnpChannels; I++)
                {
                    UnpackUtility.makeDecodeTables(Table, I * Compress.MC20, MD[I], Compress.MC20);
                }
            }
            else
            {
                UnpackUtility.makeDecodeTables(Table, 0, LD, Compress.NC20);
                UnpackUtility.makeDecodeTables(Table, Compress.NC20, DD, Compress.DC20);
                UnpackUtility.makeDecodeTables(Table, Compress.NC20 + Compress.DC20, RD, Compress.RC20);
            }
            // memcpy(UnpOldTable20,Table,sizeof(UnpOldTable20));
            for (int i = 0; i < UnpOldTable20.Length; i++)
            {
                UnpOldTable20[i] = Table[i];
            }
            return(true);
        }
Exemple #2
0
        private bool readTables()
        {
            byte[] bitLength = new byte[Compress.BC];

            byte[] table = new byte[Compress.HUFF_TABLE_SIZE];
            if (inAddr > readTop - 25)
            {
                if (!unpReadBuf())
                {
                    return(false);
                }
            }
            AddBits((8 - inBit) & 7);
            long bitField = GetBits() & unchecked ((int)0xffFFffFF);

            if ((bitField & 0x8000) != 0)
            {
                unpBlockType = BlockTypes.BLOCK_PPM;
                return(ppm.decodeInit(this, ppmEscChar));
            }
            unpBlockType = BlockTypes.BLOCK_LZ;

            prevLowDist     = 0;
            lowDistRepCount = 0;

            if ((bitField & 0x4000) == 0)
            {
                Utility.Fill(unpOldTable, (byte)0); // memset(UnpOldTable,0,sizeof(UnpOldTable));
            }
            AddBits(2);

            for (int i = 0; i < Compress.BC; i++)
            {
                int length = (Utility.URShift(GetBits(), 12)) & 0xFF;
                AddBits(4);
                if (length == 15)
                {
                    int zeroCount = (Utility.URShift(GetBits(), 12)) & 0xFF;
                    AddBits(4);
                    if (zeroCount == 0)
                    {
                        bitLength[i] = 15;
                    }
                    else
                    {
                        zeroCount += 2;
                        while (zeroCount-- > 0 && i < bitLength.Length)
                        {
                            bitLength[i++] = 0;
                        }
                        i--;
                    }
                }
                else
                {
                    bitLength[i] = (byte)length;
                }
            }

            UnpackUtility.makeDecodeTables(bitLength, 0, BD, Compress.BC);

            int TableSize = Compress.HUFF_TABLE_SIZE;

            for (int i = 0; i < TableSize;)
            {
                if (inAddr > readTop - 5)
                {
                    if (!unpReadBuf())
                    {
                        return(false);
                    }
                }
                int Number = this.decodeNumber(BD);
                if (Number < 16)
                {
                    table[i] = (byte)((Number + unpOldTable[i]) & 0xf);
                    i++;
                }
                else if (Number < 18)
                {
                    int N;
                    if (Number == 16)
                    {
                        N = (Utility.URShift(GetBits(), 13)) + 3;
                        AddBits(3);
                    }
                    else
                    {
                        N = (Utility.URShift(GetBits(), 9)) + 11;
                        AddBits(7);
                    }
                    while (N-- > 0 && i < TableSize)
                    {
                        table[i] = table[i - 1];
                        i++;
                    }
                }
                else
                {
                    int N;
                    if (Number == 18)
                    {
                        N = (Utility.URShift(GetBits(), 13)) + 3;
                        AddBits(3);
                    }
                    else
                    {
                        N = (Utility.URShift(GetBits(), 9)) + 11;
                        AddBits(7);
                    }
                    while (N-- > 0 && i < TableSize)
                    {
                        table[i++] = 0;
                    }
                }
            }
            tablesRead = true;
            if (inAddr > readTop)
            {
                return(false);
            }
            UnpackUtility.makeDecodeTables(table, 0, LD, Compress.NC);
            UnpackUtility.makeDecodeTables(table, Compress.NC, DD, Compress.DC);
            UnpackUtility.makeDecodeTables(table, Compress.NC + Compress.DC, LDD, Compress.LDC);
            UnpackUtility.makeDecodeTables(table, Compress.NC + Compress.DC + Compress.LDC, RD, Compress.RC);

            // memcpy(unpOldTable,table,sizeof(unpOldTable));

            Array.Copy(table, 0, unpOldTable, 0, unpOldTable.Length);
            return(true);
        }
Exemple #3
0
        private bool ReadTables20()
        {
            int num;
            int num3;

            byte[] lenTab  = new byte[0x13];
            byte[] buffer2 = new byte[0x404];
            if ((base.inAddr > (base.readTop - 0x19)) && !base.unpReadBuf())
            {
                return(false);
            }
            int bits = base.GetBits();

            this.UnpAudioBlock = bits & 0x8000;
            if (0 == (bits & 0x4000))
            {
                Utility.Fill <byte>(this.UnpOldTable20, 0);
            }
            base.AddBits(2);
            if (this.UnpAudioBlock != 0)
            {
                this.UnpChannels = (Utility.URShift(bits, 12) & 3) + 1;
                if (this.UnpCurChannel >= this.UnpChannels)
                {
                    this.UnpCurChannel = 0;
                }
                base.AddBits(2);
                num = 0x101 * this.UnpChannels;
            }
            else
            {
                num = 0x176;
            }
            for (num3 = 0; num3 < 0x13; num3++)
            {
                lenTab[num3] = (byte)Utility.URShift(base.GetBits(), 12);
                base.AddBits(4);
            }
            UnpackUtility.makeDecodeTables(lenTab, 0, this.BD, 0x13);
            num3 = 0;
            while (num3 < num)
            {
                if ((base.inAddr > (base.readTop - 5)) && !base.unpReadBuf())
                {
                    return(false);
                }
                int num5 = this.decodeNumber(this.BD);
                if (num5 < 0x10)
                {
                    buffer2[num3] = (byte)((num5 + this.UnpOldTable20[num3]) & 15);
                    num3++;
                }
                else
                {
                    int num2;
                    if (num5 == 0x10)
                    {
                        num2 = Utility.URShift(base.GetBits(), 14) + 3;
                        base.AddBits(2);
                        while ((num2-- > 0) && (num3 < num))
                        {
                            buffer2[num3] = buffer2[num3 - 1];
                            num3++;
                        }
                    }
                    else
                    {
                        if (num5 == 0x11)
                        {
                            num2 = Utility.URShift(base.GetBits(), 13) + 3;
                            base.AddBits(3);
                        }
                        else
                        {
                            num2 = Utility.URShift(base.GetBits(), 9) + 11;
                            base.AddBits(7);
                        }
                        while ((num2-- > 0) && (num3 < num))
                        {
                            buffer2[num3++] = 0;
                        }
                    }
                }
            }
            if (base.inAddr <= base.readTop)
            {
                if (this.UnpAudioBlock != 0)
                {
                    for (num3 = 0; num3 < this.UnpChannels; num3++)
                    {
                        UnpackUtility.makeDecodeTables(buffer2, num3 * 0x101, this.MD[num3], 0x101);
                    }
                }
                else
                {
                    UnpackUtility.makeDecodeTables(buffer2, 0, this.LD, 0x12a);
                    UnpackUtility.makeDecodeTables(buffer2, 0x12a, this.DD, 0x30);
                    UnpackUtility.makeDecodeTables(buffer2, 0x15a, this.RD, 0x1c);
                }
                for (int i = 0; i < this.UnpOldTable20.Length; i++)
                {
                    this.UnpOldTable20[i] = buffer2[i];
                }
            }
            return(true);
        }
Exemple #4
0
        private bool readTables()
        {
            int num2;

            byte[] lenTab  = new byte[20];
            byte[] buffer2 = new byte[Compress.HUFF_TABLE_SIZE];
            if ((base.inAddr > (base.readTop - 0x19)) && !base.unpReadBuf())
            {
                return(false);
            }
            base.AddBits((8 - base.inBit) & 7);
            long num = base.GetBits() & -1;

            if ((num & 0x8000L) != 0L)
            {
                this.unpBlockType = BlockTypes.BLOCK_PPM;
                return(this.ppm.decodeInit(this, this.ppmEscChar));
            }
            this.unpBlockType    = BlockTypes.BLOCK_LZ;
            this.prevLowDist     = 0;
            this.lowDistRepCount = 0;
            if ((num & 0x4000L) == 0L)
            {
                Utility.Fill <byte>(this.unpOldTable, 0);
            }
            base.AddBits(2);
            for (num2 = 0; num2 < 20; num2++)
            {
                int num3 = Utility.URShift(base.GetBits(), 12) & 0xff;
                base.AddBits(4);
                if (num3 == 15)
                {
                    int num4 = Utility.URShift(base.GetBits(), 12) & 0xff;
                    base.AddBits(4);
                    if (num4 == 0)
                    {
                        lenTab[num2] = 15;
                    }
                    else
                    {
                        num4 += 2;
                        while ((num4-- > 0) && (num2 < lenTab.Length))
                        {
                            lenTab[num2++] = 0;
                        }
                        num2--;
                    }
                }
                else
                {
                    lenTab[num2] = (byte)num3;
                }
            }
            UnpackUtility.makeDecodeTables(lenTab, 0, base.BD, 20);
            int num5 = Compress.HUFF_TABLE_SIZE;

            num2 = 0;
            while (num2 < num5)
            {
                if ((base.inAddr > (base.readTop - 5)) && !base.unpReadBuf())
                {
                    return(false);
                }
                int num6 = this.decodeNumber(base.BD);
                if (num6 < 0x10)
                {
                    buffer2[num2] = (byte)((num6 + this.unpOldTable[num2]) & 15);
                    num2++;
                }
                else
                {
                    int num7;
                    if (num6 < 0x12)
                    {
                        if (num6 == 0x10)
                        {
                            num7 = Utility.URShift(base.GetBits(), 13) + 3;
                            base.AddBits(3);
                        }
                        else
                        {
                            num7 = Utility.URShift(base.GetBits(), 9) + 11;
                            base.AddBits(7);
                        }
                        while ((num7-- > 0) && (num2 < num5))
                        {
                            buffer2[num2] = buffer2[num2 - 1];
                            num2++;
                        }
                    }
                    else
                    {
                        if (num6 == 0x12)
                        {
                            num7 = Utility.URShift(base.GetBits(), 13) + 3;
                            base.AddBits(3);
                        }
                        else
                        {
                            num7 = Utility.URShift(base.GetBits(), 9) + 11;
                            base.AddBits(7);
                        }
                        while ((num7-- > 0) && (num2 < num5))
                        {
                            buffer2[num2++] = 0;
                        }
                    }
                }
            }
            this.tablesRead = true;
            if (base.inAddr > base.readTop)
            {
                return(false);
            }
            UnpackUtility.makeDecodeTables(buffer2, 0, base.LD, 0x12b);
            UnpackUtility.makeDecodeTables(buffer2, 0x12b, base.DD, 60);
            UnpackUtility.makeDecodeTables(buffer2, 0x167, base.LDD, 0x11);
            UnpackUtility.makeDecodeTables(buffer2, 0x178, base.RD, 0x1c);
            Buffer.BlockCopy(buffer2, 0, this.unpOldTable, 0, this.unpOldTable.Length);
            return(true);
        }