示例#1
0
        private bool ReadTables20()
        {
            byte[] BitLength = new byte[PackDef.BC20];
            byte[] Table = new byte[PackDef.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));
                new Span <byte>(UnpOldTable20).Fill(0);
            }
            AddBits(2);

            if (UnpAudioBlock != 0)
            {
                UnpChannels = ((Utility.URShift(BitField, 12)) & 3) + 1;
                if (UnpCurChannel >= UnpChannels)
                {
                    UnpCurChannel = 0;
                }
                AddBits(2);
                TableSize = PackDef.MC20 * UnpChannels;
            }
            else
            {
                TableSize = PackDef.NC20 + PackDef.DC20 + PackDef.RC20;
            }
            for (I = 0; I < PackDef.BC20; I++)
            {
                BitLength[I] = (byte)(Utility.URShift(GetBits(), 12));
                AddBits(4);
            }
            UnpackUtility.makeDecodeTables(BitLength, 0, BD, PackDef.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 * PackDef.MC20, MD[I], PackDef.MC20);
                }
            }
            else
            {
                UnpackUtility.makeDecodeTables(Table, 0, LD, PackDef.NC20);
                UnpackUtility.makeDecodeTables(Table, PackDef.NC20, DD, PackDef.DC20);
                UnpackUtility.makeDecodeTables(Table, PackDef.NC20 + PackDef.DC20, RD, PackDef.RC20);
            }

            // memcpy(UnpOldTable20,Table,sizeof(UnpOldTable20));
            for (int i = 0; i < UnpOldTable20.Length; i++)
            {
                UnpOldTable20[i] = Table[i];
            }
            return(true);
        }
示例#2
0
        private bool ReadTables()
        {
            byte[] bitLength = new byte[PackDef.BC];

            byte[] table = new byte[PackDef.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 < PackDef.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, PackDef.BC);

            int TableSize = PackDef.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, PackDef.NC);
            UnpackUtility.makeDecodeTables(table, PackDef.NC, DD, PackDef.DC);
            UnpackUtility.makeDecodeTables(table, PackDef.NC + PackDef.DC, LDD, PackDef.LDC);
            UnpackUtility.makeDecodeTables(table, PackDef.NC + PackDef.DC + PackDef.LDC, RD, PackDef.RC);

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

            Buffer.BlockCopy(table, 0, unpOldTable, 0, unpOldTable.Length);
            return(true);
        }