Exemplo n.º 1
0
        private static int DecodeDistance(BitStreamReader bitStream, int length, int dictSizeBits)
        {
            Contract.Requires(bitStream != null);
            Contract.Requires(length >= 0);
            Contract.Requires(dictSizeBits >= 0);
            Contract.Requires(dictSizeBits < BitStreamReader.MaxBitCount);

            if (bitStream.EnsureBits(8) == false)
            {
                return(0);
            }

            var pos  = (int)_sPosition1[bitStream.PeekByte()];
            var skip = _sDistBits[pos]; // Number of bits to skip.

            // Skip the appropriate number of bits
            Contract.Assume(skip < BitStreamReader.MaxBitCount);
            if (bitStream.ReadBits(skip) == -1)
            {
                return(0);
            }

            if (length == 2)
            {
                if (bitStream.EnsureBits(2) == false)
                {
                    return(0);
                }

                pos = (pos << 2) | bitStream.ReadBits(2);
            }
            else
            {
                if (bitStream.EnsureBits(dictSizeBits) == false)
                {
                    return(0);
                }

                pos = ((pos << dictSizeBits)) | bitStream.ReadBits(dictSizeBits);
            }

            return(pos + 1);
        }
Exemplo n.º 2
0
        private static int DecodeDistance(BitStreamReader bitStream, int length, int dictSizeBits)
        {
            Contract.Requires(bitStream != null);
            Contract.Requires(length >= 0);
            Contract.Requires(dictSizeBits >= 0);
            Contract.Requires(dictSizeBits < BitStreamReader.MaxBitCount);

            if (bitStream.EnsureBits(8) == false)
                return 0;

            var pos = (int)_sPosition1[bitStream.PeekByte()];
            var skip = _sDistBits[pos]; // Number of bits to skip.

            // Skip the appropriate number of bits
            Contract.Assume(skip < BitStreamReader.MaxBitCount);
            if (bitStream.ReadBits(skip) == -1)
                return 0;

            if (length == 2)
            {
                if (bitStream.EnsureBits(2) == false)
                    return 0;

                pos = (pos << 2) | bitStream.ReadBits(2);
            }
            else
            {
                if (bitStream.EnsureBits(dictSizeBits) == false)
                    return 0;

                pos = ((pos << dictSizeBits)) | bitStream.ReadBits(dictSizeBits);
            }

            return pos + 1;
        }