Example #1
0
        private unsafe int GetBit()
        {
            uint hold = (uint)_hold;
            int  bits = _bits;

            if (bits != 0)
            {
                bits--;
            }
            else if (_srcIndex < _break32Offset)
            {
                _srcIndex  += 4;
                hold        = *((uint *)_pSrcBytes);
                _pSrcBytes += 4;
                bits        = 31;
            }
            else if (_srcIndex < _breakOffset)
            {
                _srcIndex++;
                hold = (uint)(*_pSrcBytes);
                _pSrcBytes++;
                bits = 7;
            }
            else
            {
                AcedMCException.ThrowReadBeyondTheEndException();
            }
            _hold = (int)(hold >> 1);
            _bits = bits;
            return((int)(hold & 1));
        }
Example #2
0
        private unsafe int GetNBits(int n)
        {
            int hold = _hold;
            int bits = _bits;

            while (bits < n)
            {
                if (bits < 8 && _srcIndex < _break32Offset)
                {
                    _srcIndex  += 3;
                    hold       |= (_pSrcBytes[0] | (_pSrcBytes[1] << 8) | (_pSrcBytes[2] << 16)) << bits;
                    _pSrcBytes += 3;
                    bits       += 24;
                }
                else if (_srcIndex < _breakOffset)
                {
                    _srcIndex++;
                    hold |= (*_pSrcBytes) << bits;
                    _pSrcBytes++;
                    bits += 8;
                }
                else
                {
                    AcedMCException.ThrowReadBeyondTheEndException();
                }
            }
            _hold = hold >> n;
            _bits = bits - n;
            return(hold & ((1 << n) - 1));
        }
Example #3
0
        private unsafe int GetCode(int *tree)
        {
            int code = 1;
            int hold = _hold;

            do
            {
                while (_bits != 0)
                {
                    code   = tree[code + (hold & 1)];
                    hold >>= 1;
                    _bits--;
                    if (code <= 0)
                    {
                        goto CodeFound;
                    }
                }
                if (_srcIndex < _break32Offset)
                {
                    _srcIndex  += 4;
                    hold        = *((int *)_pSrcBytes);
                    _pSrcBytes += 4;
                    code        = tree[code + (hold & 1)];
                    hold        = (int)((uint)hold >> 1);
                    _bits       = 31;
                }
                else if (_srcIndex < _breakOffset)
                {
                    _srcIndex++;
                    hold = (int)(*_pSrcBytes);
                    _pSrcBytes++;
                    code   = tree[code + (hold & 1)];
                    hold >>= 1;
                    _bits  = 7;
                }
                else
                {
                    AcedMCException.ThrowReadBeyondTheEndException();
                }
            } while (code > 0);
CodeFound:
            _hold = hold;
            return(-code);
        }
Example #4
0
        private unsafe void ReadNonCompressedBlock()
        {
            _inCounter += GetNBits(8);
            int bits = _bits;

            while (_inCounter > 0 && _outCounter > 0)
            {
                int hold = _hold;
                if (bits < 8)
                {
                    if (_srcIndex < _break32Offset)
                    {
                        _srcIndex  += 3;
                        hold       |= (_pSrcBytes[0] | (_pSrcBytes[1] << 8) | (_pSrcBytes[2] << 16)) << bits;
                        _pSrcBytes += 3;
                        bits       += 24;
                    }
                    else if (_srcIndex < _breakOffset)
                    {
                        _srcIndex++;
                        hold |= (*_pSrcBytes) << bits;
                        _pSrcBytes++;
                        bits += 8;
                    }
                    else
                    {
                        AcedMCException.ThrowReadBeyondTheEndException();
                    }
                }
                _hold = hold >> 8;
                bits -= 8;
                *_pDstBytes = (byte)hold;
                _inCounter--;
                _outCounter--;
                _pDstBytes++;
            }
            _bits = bits;
        }