Skip to main content

UnfilteringBuffer

Struct UnfilteringBuffer 

Source
pub(crate) struct UnfilteringBuffer {
    data_stream: Vec<u8>,
    prev_row: PrevRow,
    current_start: usize,
    filled: usize,
    available: usize,
    shift_back_limit: usize,
    remaining_bytes: u64,
    scratch_buffer: Vec<u8>,
}

Fields§

§data_stream: Vec<u8>

Vec containing the uncompressed image data currently being processed.

§prev_row: PrevRow§current_start: usize

Index in data_stream where the current row starts. This points at the filter type byte of the current row (i.e. the actual pixel data starts at current_start + 1) The pixel data is not-yet-unfilter-ed.

current_start can wrap around the length.

§filled: usize

Logical length of data that must be preserved.

§available: usize

Length of data that can be modified.

§shift_back_limit: usize

The number of bytes before we shift the buffer back.

§remaining_bytes: u64

How many bytes are left to decompress into this buffer for the current frame.

§scratch_buffer: Vec<u8>

To avoid always allocating a new vector in fn unfilter_curr_row_using_scratch_buffer.

Implementations§

Source§

impl UnfilteringBuffer

Source

pub const GROWTH_BYTES: usize

Source

fn debug_assert_invariants(&self)

Source

pub fn new(info: &Info<'_>) -> Self

Create a buffer tuned for filtering rows of the image type.

Source

pub fn reset_prev_row(&mut self)

Called to indicate that there is no previous row (e.g. when the current row is the first scanline of a given Adam7 pass).

Source

pub fn start_frame(&mut self, frame_bytes: u64)

Source

pub fn remaining_bytes(&self) -> u64

Source

pub fn prev_row(&self) -> &[u8]

Returns the previous (already unfilter-ed) row.

Source

pub fn mutable_len_of_curr_row(&self) -> usize

Returns how many bytes of the current row are present in the mutable part of the buffer (32kB most recently decompressed bytes are read-only to retain the “lookback” window as needed for inflate algorithm). If a full row is mutable, then it may be unfiltered using unfilter_curr_row_in_place.

See also readable_len_of_curr_row.

Source

pub fn readable_len_of_curr_row(&self) -> usize

Returns how many bytes of the current row have been already decompressed. If a full row is available, then it may be unfiltered using unfilter_curr_row_using_scratch_buffer.

See also mutable_len_of_curr_row.

Source

pub fn with_unfilled_buffer<F, T>(&mut self, f: F) -> T
where F: FnOnce(&mut UnfilterBuf<'_>) -> T,

Runs f on the underlying buffer.

Invariants of self depend on the assumption that the caller will only append new bytes to the returned vector (which is indeed the behavior of ReadDecoder and StreamingDecoder). TODO: Consider protecting the invariants by returning an append-only view of the vector (FnMut(&[u8])??? or maybe std::io::Write???).

Source

fn shift_buffer_left(&mut self, discard_size: usize)

Shifts the contents of self.data_stream left, discarding the first discard_size bytes.

Source

fn curr_row_filter(&self) -> Result<RowFilter, DecodingError>

Source

pub fn unfilter_curr_row_in_place( &mut self, rowlen: usize, bpp: BytesPerPixel, ) -> Result<(), DecodingError>

Runs unfilter on the current row, and then shifts rows so that the current row becomes the previous row.

unfilter will mutate the current row in-place, and therefore the caller should first consult mutable_len_of_curr_row to check if all bytes of the current row are indeed mutable.

Source

pub fn unfilter_curr_row_using_scratch_buffer( &mut self, rowlen: usize, bpp: BytesPerPixel, ) -> Result<(), DecodingError>

Runs unfilter on the current row, and then shifts rows so that the current row becomes the previous row.

Before running unfilter, the contents of the current row will be copied into a scratch buffer. This allows unfiltering to happen even if mutable_len_of_curr_row < rowlen (e.g. when handling partial or not-yet-complete input streams).

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.