2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/BitStream.hh>
|
|
|
|
|
|
|
|
// See comments in bits.cc
|
|
|
|
#define BITS_READ 1
|
|
|
|
#include "bits.icc"
|
|
|
|
|
|
|
|
BitStream::BitStream(unsigned char const* p, int nbytes) :
|
|
|
|
start(p),
|
|
|
|
nbytes(nbytes)
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BitStream::reset()
|
|
|
|
{
|
|
|
|
p = start;
|
|
|
|
bit_offset = 7;
|
|
|
|
bits_available = 8 * nbytes;
|
|
|
|
}
|
|
|
|
|
2012-06-24 19:26:28 +00:00
|
|
|
unsigned long long
|
2008-04-29 12:55:25 +00:00
|
|
|
BitStream::getBits(int nbits)
|
|
|
|
{
|
|
|
|
return read_bits(this->p, this->bit_offset,
|
|
|
|
this->bits_available, nbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BitStream::skipToNextByte()
|
|
|
|
{
|
|
|
|
if (bit_offset != 7)
|
|
|
|
{
|
|
|
|
unsigned int bits_to_skip = bit_offset + 1;
|
|
|
|
if (bits_available < bits_to_skip)
|
|
|
|
{
|
2009-09-26 18:36:04 +00:00
|
|
|
throw std::logic_error(
|
|
|
|
"INTERNAL ERROR: overflow skipping to next byte in bitstream");
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
bit_offset = 7;
|
|
|
|
++p;
|
|
|
|
bits_available -= bits_to_skip;
|
|
|
|
}
|
|
|
|
}
|