예제 #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));
        }
예제 #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));
        }
예제 #3
0
        public static unsafe int GetDecompressedLength(byte[] sourceBytes, int sourceIndex)
        {
            if (sourceBytes == null)
            {
                AcedMCException.ThrowArgumentNullException("sourceBytes");
                fixed(byte *pSrcBytes = &sourceBytes[sourceIndex])
                {
                    int result = *((int *)pSrcBytes);

                    if (result >= 0)
                    {
                        return(result);
                    }
                    return(-result);
                }
        }
예제 #4
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);
        }
예제 #5
0
        public unsafe byte[] Decompress(byte[] sourceBytes, int sourceIndex, int beforeGap, int afterGap)
        {
            if (sourceBytes == null)
            {
                AcedMCException.ThrowArgumentNullException("sourceBytes");
            }
            int byteCount;

            fixed(byte *pSrcBytes = &sourceBytes[sourceIndex])
            byteCount = *((int *)pSrcBytes);

            if (byteCount < 0)
            {
                byteCount = -byteCount;
            }
            byte[] result = new byte[byteCount + beforeGap + afterGap];
            if (byteCount != 0)
            {
                Decompress(sourceBytes, sourceIndex, result, beforeGap);
            }
            return(result);
        }
예제 #6
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;
        }
예제 #7
0
 public unsafe int Decompress(byte[] sourceBytes, int sourceIndex, byte[] destinationBytes, int destinationIndex)
 {
     if (sourceBytes == null)
         AcedMCException.ThrowArgumentNullException("sourceBytes"); }