Skip to main content

encode_to_writer

Function encode_to_writer 

Source
pub fn encode_to_writer<E: Encoder>(
    enc: E,
    pixels: PixelSlice<'_>,
    w: &mut impl Write,
) -> Result<EncodeWriteReport, EncodeWriteError<E::Error>>
👎Deprecated:

Use row_encode::encode for policy-controlled rows, or Encoder::encode followed by writing its output for one-shot encoding

Expand description

Encode pixels into w, sending bytes as the encoder produces them.

Declares the image with begin, pushes it in strips, and writes pending output after begin (the header) and after every strip, so an encoder that streams sends its first bytes before it has seen most rows and holds little output. An encoder that reports OutputTiming::AT_FINISH gets the same rows and writes everything at the end. One whose configuration cannot encode from rows (begin declines with UnsupportedOperation::RowLevelEncode) encodes the image in one call instead.

Strips are a multiple of the encoder’s preferred_strip_height, at least 16 rows, so a one-row preference doesn’t turn into one write per row.

On an error after bytes were written, the output is a prefix of a file that will never be finished: abort the transport rather than end it normally.