ReadBit() public abstract method

public abstract ReadBit ( ) : int
return int
Example #1
0
        public int ReadCode(BitStream bitStream)
        {
            int code = 0;

            switch (Mode)
            {
            case 1:
                code = bitStream.ReadBits6();
                break;

            case 2:
                if (bitStream.ReadBit() == 1)
                {
                    code = Mode2_1;
                }
                else
                {
                    code = bitStream.ReadBits6();
                }
                break;

            case 3:
                if (bitStream.ReadBit() == 1)
                {
                    code = Mode3_1;
                }
                else if (bitStream.ReadBit() == 1)
                {
                    code = Mode3_01;
                }
                else
                {
                    code = bitStream.ReadBits6();
                }
                break;

            case 4:
                if (bitStream.ReadBit() == 1)
                {
                    code = Mode4_1;
                }
                else if (bitStream.ReadBit() == 1)
                {
                    code = Mode4_01;
                }
                else if (bitStream.ReadBit() == 1)
                {
                    code = Mode4_001;
                }
                else
                {
                    code = bitStream.ReadBits6();
                }
                break;

            default:
                throw new Exception("Unsupported compression mode");
            }
            m_commandStats[code]++;
            m_commandsSentSinceLastChange++;

            if (m_startupMode == 0 && m_commandsSentSinceLastChange > 5)
            {
                m_startupMode++;
                AdaptCommands2();
            }
            else if (m_startupMode == 1 && m_commandsSentSinceLastChange > 20)
            {
                m_startupMode++;
                AdaptCommands2();
            }
            else if (m_startupMode == 2 && m_commandsSentSinceLastChange > 100)
            {
                AdaptCommands2();
            }
            return(code);
        }
        public int ReadCode(BitStream bitStream)
        {
            int code = 0;
            switch (Mode)
            {
                case 1:
                    code = bitStream.ReadBits6();
                    break;
                case 2:
                    if (bitStream.ReadBit() == 1)
                    {
                        code = Mode2_1;
                    }
                    else
                    {
                        code = bitStream.ReadBits6();
                    }
                    break;
                case 3:
                    if (bitStream.ReadBit() == 1)
                    {
                        code = Mode3_1;
                    }
                    else if (bitStream.ReadBit() == 1)
                    {
                        code = Mode3_01;
                    }
                    else
                    {
                        code = bitStream.ReadBits6();
                    }
                    break;
                case 4:
                    if (bitStream.ReadBit() == 1)
                    {
                        code = Mode4_1;
                    }
                    else if (bitStream.ReadBit() == 1)
                    {
                        code = Mode4_01;
                    }
                    else if (bitStream.ReadBit() == 1)
                    {
                        code = Mode4_001;
                    }
                    else
                    {
                        code = bitStream.ReadBits6();
                    }
                    break;
                default:
                    throw new Exception("Unsupported compression mode");
            }
            m_commandStats[code]++;
            m_commandsSentSinceLastChange++;

            if (m_startupMode == 0 && m_commandsSentSinceLastChange > 5)
            {
                m_startupMode++;
                AdaptCommands2();
            }
            else if (m_startupMode == 1 && m_commandsSentSinceLastChange > 20)
            {
                m_startupMode++;
                AdaptCommands2();
            }
            else if (m_startupMode == 2 && m_commandsSentSinceLastChange > 100)
            {
                AdaptCommands2();
            }
            return code;
        }