FluxJpeg.Core.IO.JPEGBinaryReader.ReadBits C# (CSharp) Метод

ReadBits() публичный Метод

Places n bits from the stream, where the most-significant bits from the first byte read end up as the most-significant of the returned n bits.
public ReadBits ( int n ) : int
n int Number of bits to return
Результат int
        public int ReadBits(int n)
        {
            int result = 0;

            #region Special case -- included for optimization purposes
            if (_bitsLeft >= n)
            {
                _bitsLeft-=n;
                result = _bitBuffer >> (8 - n);
                _bitBuffer = (byte)(_bitBuffer << n);
                return result;
            }
            #endregion

            while (n > 0)
            {
                if (_bitsLeft == 0)
                {
                    _bitBuffer = ReadJpegByte();
                    _bitsLeft = 8;
                }

                int take = n <= _bitsLeft ? n : _bitsLeft;

                result = result | ((_bitBuffer >> 8 - take) << (n - take));

                _bitBuffer = (byte)(_bitBuffer << take);

                _bitsLeft -= take;
                n -= take;
            }

            return result;
        }

Usage Example

Пример #1
0
 public float decode_dc_coefficient(JPEGBinaryReader JPEGStream)
 {
     int n = this.DCTable.Decode(JPEGStream);
     float num2 = JPEGStream.ReadBits(n);
     num2 = HuffmanTable.Extend((int) num2, n);
     num2 = this.previousDC + num2;
     this.previousDC = num2;
     return num2;
 }
All Usage Examples Of FluxJpeg.Core.IO.JPEGBinaryReader::ReadBits