jxl_bitstream

Struct Bitstream

Source
pub struct Bitstream<'buf> { /* private fields */ }
Expand description

Bitstream reader with borrowed in-memory buffer.

Implementation is mostly from jxl-rs.

Implementations§

Source§

impl<'buf> Bitstream<'buf>

Source

pub fn new(bytes: &'buf [u8]) -> Self

Create a new bitstream reader.

Source

pub fn num_read_bits(&self) -> usize

Returns the number of bits that are read or skipped.

Source§

impl Bitstream<'_>

Source

pub fn peek_bits(&mut self, n: usize) -> u32

Peeks bits from bitstream, without consuming them.

This method refills the bit buffer.

Source

pub fn peek_bits_const<const N: usize>(&mut self) -> u32

Peeks bits from bitstream, without consuming them.

This method refills the bit buffer.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn read_bits(&mut self, n: usize) -> Result<u32>

Read and consume bits from bitstream.

Source

pub fn skip_bits(&mut self, n: usize) -> Result<()>

Source

pub fn zero_pad_to_byte(&mut self) -> Result<()>

Performs ZeroPadToByte as defined in the JPEG XL specification.

Source§

impl Bitstream<'_>

Source

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);
Source

pub fn read_u64(&mut self) -> Result<u64>

Reads an U64 as defined in the JPEG XL specification.

Source

pub fn read_bool(&mut self) -> Result<bool>

Reads a Bool as defined in the JPEG XL specification.

Source

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.

Source

pub fn read_enum<E: TryFrom<u32>>(&mut self) -> Result<E>

Reads an enum as defined in the JPEG XL specification.

Trait Implementations§

Source§

impl<'buf> Clone for Bitstream<'buf>

Source§

fn clone(&self) -> Bitstream<'buf>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bitstream<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'buf> Freeze for Bitstream<'buf>

§

impl<'buf> RefUnwindSafe for Bitstream<'buf>

§

impl<'buf> Send for Bitstream<'buf>

§

impl<'buf> Sync for Bitstream<'buf>

§

impl<'buf> Unpin for Bitstream<'buf>

§

impl<'buf> UnwindSafe for Bitstream<'buf>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more