[libav-devel] [PATCH] bitstream: Add bitstream_apply_sign() helper function
Diego Biurrun
diego at biurrun.de
Thu Jun 23 15:54:40 CEST 2016
This reads a sign bit from the bitstream and flips the sign of the
provided value accordingly.
---
.. as suggested by Anton ..
libavcodec/bitstream.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h
index 539b721..180bf66 100644
--- a/libavcodec/bitstream.h
+++ b/libavcodec/bitstream.h
@@ -377,4 +377,11 @@ static inline int bitstream_decode210(BitstreamContext *bc)
return 2 - bitstream_read_bit(bc);
}
+/* Read sign bit and flip the sign of the provided value accordingly. */
+static inline int bitstream_apply_sign(BitstreamContext *bc, int val)
+{
+ int sign = bitstream_read_signed(bc, 1);
+ return (val ^ sign) - sign;
+}
+
#endif /* AVCODEC_BITSTREAM_H */
--
2.7.3
More information about the libav-devel
mailing list