diff options
author | Jay Berkenbilt <ejb@ql.org> | 2018-01-14 00:13:18 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2018-01-14 01:49:42 +0100 |
commit | d9c90497089ae5cf00891d6febfa7f486f021833 (patch) | |
tree | 37ff785d288aa4433eba89230ab7c877b573bc91 /libqpdf/BitStream.cc | |
parent | bf2fb239d7a39255fe122db50dd5d03f9baa25ae (diff) | |
download | qpdf-d9c90497089ae5cf00891d6febfa7f486f021833.tar.zst |
Add signed support to BitStream and BitWriter
Diffstat (limited to 'libqpdf/BitStream.cc')
-rw-r--r-- | libqpdf/BitStream.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libqpdf/BitStream.cc b/libqpdf/BitStream.cc index 14eae55d..bb52af31 100644 --- a/libqpdf/BitStream.cc +++ b/libqpdf/BitStream.cc @@ -30,6 +30,23 @@ BitStream::getBits(int nbits) this->bits_available, nbits); } +long long +BitStream::getBitsSigned(int nbits) +{ + unsigned long long bits = read_bits(this->p, this->bit_offset, + this->bits_available, nbits); + long long result = 0; + if (static_cast<long long>(bits) > 1 << (nbits - 1)) + { + result = static_cast<long long>(bits - (1 << nbits)); + } + else + { + result = static_cast<long long>(bits); + } + return result; +} + void BitStream::skipToNextByte() { |