Skip to main content

EncoderSink

Struct EncoderSink 

Source
pub struct EncoderSink<E> { /* private fields */ }
Expand description

DecodeRowSink that feeds an Encoder.

begin declares the image to the encoder (Encoder::begin); an encoder that answers with a streaming OutputTiming writes its header at once and makes bytes available as rows arrive. output_timing reports that answer. provide_next_buffer returns the sink’s own strip buffer, so the decoder writes straight into the bytes the encoder reads; the strip is pushed on the next provide_next_buffer or on finish. No pixel is copied by this handoff; the encoder may copy or retain its own input/state.

Drain encoded bytes between decode steps with pending_output and consume_output to keep output memory bounded. That bounds queued encoded bytes only. Awaiting a slow writer can keep much larger raw/intermediate allocations alive; output timing alone does not establish when those allocations are released. Encoder errors reach the decoder’s caller as the sink error, typed, so they can be told apart from malformed input.

Implementations§

Source§

impl<E: Encoder> EncoderSink<E>
where E::Error: Send + Sync,

Source

pub fn new(encoder: E) -> Self

Wrap encoder; rows go to its push_rows.

Source

pub fn output_timing(&self) -> Option<OutputTiming>

What the encoder’s begin reported: whether its bytes stream and how many rows it holds back. None until the decoder has declared the image.

The sink pushes each strip when the decoder asks for the next one, so one strip more than the encoder’s lag_rows can wait here.

Source

pub fn rows_pushed(&self) -> u64

Rows pushed into the encoder so far.

Source

pub fn encoder(&self) -> &E

The encoder.

Source

pub fn pending_output(&self) -> &[u8] ⓘ

Encoded bytes ready to send; see Encoder::pending_output.

Source

pub fn consume_output(&mut self, n: usize)

Mark the first n pending bytes as sent.

Source

pub fn take_output(&mut self, into: &mut Vec<u8>)

Append every pending byte to into and consume it; see Encoder::take_output.

Source

pub fn write_pending(&mut self, w: &mut impl Write) -> Result<usize>

Write every pending byte to w. Returns how many were written.

Source

pub fn finish(self) -> Result<EncodeOutput, EncoderSinkError<E::Error>>

Push any pending strip and finish the encoder. Returns the bytes not already taken through consume_output.

Trait Implementations§

Source§

impl<E: Encoder> Debug for EncoderSink<E>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<E: Encoder> DecodeRowSink for EncoderSink<E>
where E::Error: Send + Sync,

Source§

fn begin( &mut self, width: u32, height: u32, descriptor: PixelDescriptor, ) -> Result<(), SinkError>

Called once before the first strip with total output dimensions and pixel format. Read more
Source§

fn provide_next_buffer( &mut self, _y: u32, height: u32, width: u32, descriptor: PixelDescriptor, ) -> Result<PixelSliceMut<'_>, SinkError>

Provide a mutable pixel buffer for decoded rows y .. y + height. Read more
Source§

fn finish(&mut self) -> Result<(), SinkError>

Called once after the last strip has been fully written. Read more
Source§

fn max_buffer_rows(&self) -> NonZero<u32>

Largest strip the sink can lend without growing its admitted storage. Read more
Source§

fn accepts_provisional(&self) -> bool

Whether this sink wants provisional rows from progressive passes. Read more
Source§

fn provide_pass_buffer( &mut self, meta: BatchMeta, height: u32, width: u32, descriptor: PixelDescriptor, ) -> Result<PixelSliceMut<'_>, Box<dyn Error + Send + Sync>>

Provide a buffer for provisional rows meta.y .. meta.y + height of pass meta.pass: an approximation a later pass replaces. Called only on sinks whose accepts_provisional returned true, never for final rows (meta.is_final is false), and in any order relative to other provisional rows. The final rows for the same region still arrive through provide_next_buffer. Read more

Auto Trait Implementations§

§

impl<E> Freeze for EncoderSink<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for EncoderSink<E>
where E: RefUnwindSafe,

§

impl<E> Send for EncoderSink<E>
where E: Send,

§

impl<E> Sync for EncoderSink<E>
where E: Sync,

§

impl<E> Unpin for EncoderSink<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for EncoderSink<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for EncoderSink<E>
where E: UnwindSafe,

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.