SkipBits() public méthode

public SkipBits ( int n ) : void
n int
Résultat void
Exemple #1
0
        public int GetNextSymbol(InputBuffer input)
        {
            uint num = input.TryLoad16Bits();

            if (input.AvailableBits == 0)
            {
                return(-1);
            }
            int index = this.table[(num & this.tableMask)];

            if (index < 0)
            {
                uint num3 = ((uint)1) << this.tableBits;
                do
                {
                    index = -index;
                    if ((num & num3) == 0)
                    {
                        index = this.left[index];
                    }
                    else
                    {
                        index = this.right[index];
                    }
                    num3 = num3 << 1;
                }while (index < 0);
            }
            if (this.codeLengthArray[index] > input.AvailableBits)
            {
                return(-1);
            }
            input.SkipBits(this.codeLengthArray[index]);
            return(index);
        }
Exemple #2
0
        //
        // This function will try to get enough bits from input and
        // try to decode the bits.
        // If there are no enought bits in the input, this function will return -1.
        //
        public int GetNextSymbol(InputBuffer input)
        {
            // Try to load 16 bits into input buffer if possible and get the bitBuffer value.
            // If there aren't 16 bits available we will return all we have in the
            // input buffer.
            uint bitBuffer = input.TryLoad16Bits();

            if (input.AvailableBits == 0)
            {    // running out of input.
                return(-1);
            }

            // decode an element
            int symbol = _table[bitBuffer & _tableMask];

            if (symbol < 0)
            {       //  this will be the start of the binary tree
                // navigate the tree
                uint mask = (uint)1 << _tableBits;
                do
                {
                    symbol = -symbol;
                    if ((bitBuffer & mask) == 0)
                    {
                        symbol = _left[symbol];
                    }
                    else
                    {
                        symbol = _right[symbol];
                    }
                    mask <<= 1;
                } while (symbol < 0);
            }

            int codeLength = _codeLengthArray[symbol];

            // huffman code lengths must be at least 1 bit long
            if (codeLength <= 0)
            {
                throw new InvalidDataException(SR.InvalidHuffmanData);
            }

            //
            // If this code is longer than the # bits we had in the bit buffer (i.e.
            // we read only part of the code), we can hit the entry in the table or the tree
            // for another symbol. However the length of another symbol will not match the
            // available bits count.
            if (codeLength > input.AvailableBits)
            {
                // We already tried to load 16 bits and maximum length is 15,
                // so this means we are running out of input.
                return(-1);
            }

            input.SkipBits(codeLength);
            return(symbol);
        }
Exemple #3
0
        public int GetNextSymbol(InputBuffer input)
        {
            uint num = input.TryLoad16Bits();

            if (input.AvailableBits == 0)
            {
                return(-1);
            }
            int index = this.table[(int)((IntPtr)(num & this.tableMask))];

            if (index < 0)
            {
                uint num3 = ((uint)1) << this.tableBits;
                do
                {
                    index = -index;
                    if ((num & num3) == 0)
                    {
                        index = this.left[index];
                    }
                    else
                    {
                        index = this.right[index];
                    }
                    num3 = num3 << 1;
                }while (index < 0);
            }
            int n = this.codeLengthArray[index];

            if (n <= 0)
            {
                throw new InvalidDataException(SR.GetString("InvalidHuffmanData"));
            }
            if (n > input.AvailableBits)
            {
                return(-1);
            }
            input.SkipBits(n);
            return(index);
        }
 public int GetNextSymbol(InputBuffer input) {
     uint num = input.TryLoad16Bits();
     if (input.AvailableBits == 0) {
         return -1;
     }
     int index = this.table[(int)((IntPtr)(num & this.tableMask))];
     if (index < 0) {
         uint num3 = ((uint)1) << this.tableBits;
         do {
             index = -index;
             if ((num & num3) == 0) {
                 index = this.left[index];
             }
             else {
                 index = this.right[index];
             }
             num3 = num3 << 1;
         }
         while (index < 0);
     }
     if (this.codeLengthArray[index] > input.AvailableBits) {
         return -1;
     }
     input.SkipBits(this.codeLengthArray[index]);
     return index;
 }
Exemple #5
0
        //
        // This function will try to get enough bits from input and 
        // try to decode the bits.
        // If there are no enought bits in the input, this function will return -1.
        //
        public int GetNextSymbol(InputBuffer input)
        {
            // Try to load 16 bits into input buffer if possible and get the bitBuffer value.
            // If there aren't 16 bits available we will return all we have in the 
            // input buffer.
            uint bitBuffer = input.TryLoad16Bits();
            if (input.AvailableBits == 0)
            {    // running out of input.
                return -1;
            }

            // decode an element 
            int symbol = _table[bitBuffer & _tableMask];
            if (symbol < 0)
            {       //  this will be the start of the binary tree
                // navigate the tree
                uint mask = (uint)1 << _tableBits;
                do
                {
                    symbol = -symbol;
                    if ((bitBuffer & mask) == 0)
                        symbol = _left[symbol];
                    else
                        symbol = _right[symbol];
                    mask <<= 1;
                } while (symbol < 0);
            }

            int codeLength = _codeLengthArray[symbol];

            // huffman code lengths must be at least 1 bit long
            if (codeLength <= 0)
            {
                throw new InvalidDataException(SR.InvalidHuffmanData);
            }

            //
            // If this code is longer than the # bits we had in the bit buffer (i.e.
            // we read only part of the code), we can hit the entry in the table or the tree
            // for another symbol. However the length of another symbol will not match the 
            // available bits count.
            if (codeLength > input.AvailableBits)
            {
                // We already tried to load 16 bits and maximum length is 15, 
                // so this means we are running out of input. 
                return -1;
            }

            input.SkipBits(codeLength);
            return symbol;
        }
 public int GetNextSymbol(InputBuffer input)
 {
     uint num = input.TryLoad16Bits();
     if (input.AvailableBits == 0)
     {
         return -1;
     }
     int index = this.table[(int) ((IntPtr) (num & this.tableMask))];
     if (index < 0)
     {
         uint num3 = ((uint) 1) << this.tableBits;
         do
         {
             index = -index;
             if ((num & num3) == 0)
             {
                 index = this.left[index];
             }
             else
             {
                 index = this.right[index];
             }
             num3 = num3 << 1;
         }
         while (index < 0);
     }
     int n = this.codeLengthArray[index];
     if (n <= 0)
     {
         throw new InvalidDataException(SR.GetString("InvalidHuffmanData"));
     }
     if (n > input.AvailableBits)
     {
         return -1;
     }
     input.SkipBits(n);
     return index;
 }