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: usizeIndex 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: usizeLogical length of data that must be preserved.
available: usizeLength of data that can be modified.
shift_back_limit: usizeThe number of bytes before we shift the buffer back.
remaining_bytes: u64How 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
impl UnfilteringBuffer
pub const GROWTH_BYTES: usize
fn debug_assert_invariants(&self)
Sourcepub fn new(info: &Info<'_>) -> Self
pub fn new(info: &Info<'_>) -> Self
Create a buffer tuned for filtering rows of the image type.
Sourcepub fn reset_prev_row(&mut self)
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).
pub fn start_frame(&mut self, frame_bytes: u64)
pub fn remaining_bytes(&self) -> u64
Sourcepub fn mutable_len_of_curr_row(&self) -> usize
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.
Sourcepub fn readable_len_of_curr_row(&self) -> usize
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.
Sourcepub fn with_unfilled_buffer<F, T>(&mut self, f: F) -> Twhere
F: FnOnce(&mut UnfilterBuf<'_>) -> T,
pub fn with_unfilled_buffer<F, T>(&mut self, f: F) -> Twhere
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???).
Sourcefn shift_buffer_left(&mut self, discard_size: usize)
fn shift_buffer_left(&mut self, discard_size: usize)
Shifts the contents of self.data_stream left,
discarding the first discard_size bytes.
fn curr_row_filter(&self) -> Result<RowFilter, DecodingError>
Sourcepub fn unfilter_curr_row_in_place(
&mut self,
rowlen: usize,
bpp: BytesPerPixel,
) -> Result<(), DecodingError>
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.
Sourcepub fn unfilter_curr_row_using_scratch_buffer(
&mut self,
rowlen: usize,
bpp: BytesPerPixel,
) -> Result<(), DecodingError>
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).