aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/BitStream.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-01-14 00:13:18 +0100
committerJay Berkenbilt <ejb@ql.org>2018-01-14 01:49:42 +0100
commitd9c90497089ae5cf00891d6febfa7f486f021833 (patch)
tree37ff785d288aa4433eba89230ab7c877b573bc91 /libqpdf/BitStream.cc
parentbf2fb239d7a39255fe122db50dd5d03f9baa25ae (diff)
downloadqpdf-d9c90497089ae5cf00891d6febfa7f486f021833.tar.zst
Add signed support to BitStream and BitWriter
Diffstat (limited to 'libqpdf/BitStream.cc')
-rw-r--r--libqpdf/BitStream.cc17
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()
{