pub struct Bitstream<'buf> { /* private fields */ }
Expand description
Bitstream reader with borrowed in-memory buffer.
Implementation is mostly from jxl-rs.
Implementations§
Source§impl Bitstream<'_>
impl Bitstream<'_>
Sourcepub fn peek_bits(&mut self, n: usize) -> u32
pub fn peek_bits(&mut self, n: usize) -> u32
Peeks bits from bitstream, without consuming them.
This method refills the bit buffer.
Sourcepub fn peek_bits_const<const N: usize>(&mut self) -> u32
pub fn peek_bits_const<const N: usize>(&mut self) -> u32
Peeks bits from bitstream, without consuming them.
This method refills the bit buffer.
Sourcepub fn peek_bits_prefilled(&mut self, n: usize) -> u32
pub fn peek_bits_prefilled(&mut self, n: usize) -> u32
Peeks bits from already filled bitstream, without consuming them.
This method does not refill the bit buffer.
Sourcepub fn peek_bits_prefilled_const<const N: usize>(&mut self) -> u32
pub fn peek_bits_prefilled_const<const N: usize>(&mut self) -> u32
Peeks bits from already filled bitstream, without consuming them.
This method does not refill the bit buffer.
Sourcepub fn consume_bits(&mut self, n: usize) -> Result<()>
pub fn consume_bits(&mut self, n: usize) -> Result<()>
Consumes bits in bit buffer.
§Errors
This method returns Err(Io(std::io::ErrorKind::UnexpectedEof))
when there are not enough
bits in the bit buffer.
Sourcepub fn consume_bits_const<const N: usize>(&mut self) -> Result<()>
pub fn consume_bits_const<const N: usize>(&mut self) -> Result<()>
Consumes bits in bit buffer.
§Errors
This method returns Err(Io(std::io::ErrorKind::UnexpectedEof))
when there are not enough
bits in the bit buffer.
pub fn skip_bits(&mut self, n: usize) -> Result<()>
Sourcepub fn zero_pad_to_byte(&mut self) -> Result<()>
pub fn zero_pad_to_byte(&mut self) -> Result<()>
Performs ZeroPadToByte
as defined in the JPEG XL specification.
Source§impl Bitstream<'_>
impl Bitstream<'_>
Sourcepub fn read_u32(
&mut self,
d0: impl Into<U32Specifier>,
d1: impl Into<U32Specifier>,
d2: impl Into<U32Specifier>,
d3: impl Into<U32Specifier>,
) -> Result<u32>
pub fn read_u32( &mut self, d0: impl Into<U32Specifier>, d1: impl Into<U32Specifier>, d2: impl Into<U32Specifier>, d3: impl Into<U32Specifier>, ) -> Result<u32>
Reads an U32
as defined in the JPEG XL specification.
§Example
use jxl_bitstream::{Bitstream, U};
let buf = [0b110010];
let mut bitstream = Bitstream::new(&buf);
let val = bitstream.read_u32(1, U(2), 3 + U(4), 19 + U(8)).expect("failed to read data");
assert_eq!(val, 15);
Sourcepub fn read_u64(&mut self) -> Result<u64>
pub fn read_u64(&mut self) -> Result<u64>
Reads an U64
as defined in the JPEG XL specification.
Sourcepub fn read_bool(&mut self) -> Result<bool>
pub fn read_bool(&mut self) -> Result<bool>
Reads a Bool
as defined in the JPEG XL specification.
Sourcepub fn read_f16_as_f32(&mut self) -> Result<f32>
pub fn read_f16_as_f32(&mut self) -> Result<f32>
Reads an F16
as defined in the JPEG XL specification, and convert it to f32
.
§Errors
Returns Error::InvalidFloat
if the value is NaN
or Infinity
.