Struct BitStream

Source
pub(crate) struct BitStream {
    pub buffer: u64,
    aligned_buffer: u64,
    pub(crate) bits_left: u8,
    pub marker: Option<Marker>,
    pub successive_high: u8,
    pub successive_low: u8,
    spec_start: u8,
    spec_end: u8,
    pub eob_run: i32,
    pub overread_by: usize,
    pub seen_eoi: bool,
}
Expand description

A BitStream struct, a bit by bit reader with super powers

Fields§

§buffer: u64

A MSB type buffer that is used for some certain operations

§aligned_buffer: u64

A TOP aligned MSB type buffer that is used to accelerate some operations like peek_bits and get_bits.

By top aligned, I mean the top bit (63) represents the top bit in the buffer.

§bits_left: u8

Tell us the bits left the two buffer

§marker: Option<Marker>

Did we find a marker(RST/EOF) during decoding?

§successive_high: u8

Progressive decoding

§successive_low: u8§spec_start: u8§spec_end: u8§eob_run: i32§overread_by: usize§seen_eoi: bool

True if we have seen end of image marker. Don’t read anything after that.

Implementations§

Source§

impl BitStream

Source

pub(crate) const fn new() -> BitStream

Create a new BitStream

Source

pub(crate) fn new_progressive( ah: u8, al: u8, spec_start: u8, spec_end: u8, ) -> BitStream

Create a new Bitstream for progressive decoding

Source

pub(crate) fn refill<T>( &mut self, reader: &mut ZByteReader<T>, ) -> Result<bool, DecodeErrors>
where T: ZReaderTrait,

Refill the bit buffer by (a maximum of) 32 bits

§Arguments
  • reader:&mut BufReader<R>: A mutable reference to an underlying File/Memory buffer containing a valid JPEG stream

This function will only refill if self.count is less than 32

Source

fn decode_dc<T>( &mut self, reader: &mut ZByteReader<T>, dc_table: &HuffmanTable, dc_prediction: &mut i32, ) -> Result<bool, DecodeErrors>
where T: ZReaderTrait,

Decode the DC coefficient in a MCU block.

The decoded coefficient is written to dc_prediction

Source

pub fn decode_mcu_block<T>( &mut self, reader: &mut ZByteReader<T>, dc_table: &HuffmanTable, ac_table: &HuffmanTable, qt_table: &[i32; 64], block: &mut [i32; 64], dc_prediction: &mut i32, ) -> Result<(), DecodeErrors>
where T: ZReaderTrait,

Decode a Minimum Code Unit(MCU) as quickly as possible

§Arguments
  • reader: The bitstream from where we read more bits.
  • dc_table: The Huffman table used to decode the DC coefficient
  • ac_table: The Huffman table used to decode AC values
  • block: A memory region where we will write out the decoded values
  • DC prediction: Last DC value for this component
Source

const fn peek_bits<const LOOKAHEAD: u8>(&self) -> i32

Peek look_ahead bits ahead without discarding them from the buffer

Source

fn drop_bits(&mut self, n: u8)

Discard the next N bits without checking

Source

fn get_bits(&mut self, n_bits: u8) -> i32

Read n_bits from the buffer and discard them

Source

pub(crate) fn decode_prog_dc_first<T>( &mut self, reader: &mut ZByteReader<T>, dc_table: &HuffmanTable, block: &mut i16, dc_prediction: &mut i32, ) -> Result<(), DecodeErrors>
where T: ZReaderTrait,

Decode a DC block

Source

pub(crate) fn decode_prog_dc_refine<T>( &mut self, reader: &mut ZByteReader<T>, block: &mut i16, ) -> Result<(), DecodeErrors>
where T: ZReaderTrait,

Source

fn get_bit(&mut self) -> u8

Get a single bit from the bitstream

Source

pub(crate) fn decode_mcu_ac_first<T>( &mut self, reader: &mut ZByteReader<T>, ac_table: &HuffmanTable, block: &mut [i16; 64], ) -> Result<bool, DecodeErrors>
where T: ZReaderTrait,

Source

pub(crate) fn decode_mcu_ac_refine<T>( &mut self, reader: &mut ZByteReader<T>, table: &HuffmanTable, block: &mut [i16; 64], ) -> Result<bool, DecodeErrors>
where T: ZReaderTrait,

Source

pub fn update_progressive_params( &mut self, ah: u8, al: u8, spec_start: u8, spec_end: u8, )

Source

pub fn reset(&mut self)

Reset the stream if we have a restart marker

Restart markers indicate drop those bits in the stream and zero out everything

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.