/********************************************************************************
    LibVideoGfx - video processing library
    Copyright (C) 2002  Dirk Farin

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ********************************************************************************/


inline uint32 BitReader::GetBits (int n)
{
  if (n>d_bitsleft)
    Refill();

  uint32 val = d_buffer>>(64-n);
  d_buffer <<= n;
  d_bitsleft -= n;

  return val;
}


inline uint32 BitReader::PeekBits(int n)
{
  if (n>d_bitsleft)
    Refill();

  uint32 val = d_buffer>>(64-n);

  return val;
}


inline void   BitReader::SkipBits(int nbits)
{
  if (nbits>d_bitsleft)
    Refill();

  d_buffer<<=nbits;
  d_bitsleft-=nbits;
}

inline void   BitReader::SkipBitsFast(int nbits)
{
  d_buffer<<=nbits;
  d_bitsleft-=nbits;
}


inline void   BitReader::SkipToByteBoundary()
{
  int nskip = (d_bitsleft & 7);
  if (nskip) SkipBits(nskip);
}

inline bool   BitReader::IsEOF() const
{
  return d_ptr >= d_endptr;
}


inline int32 BitReader::AskBitsLeft() const
{
  return ((d_endptr-d_ptr)*8) + d_bitsleft;
}

