Struct Writer

pub struct Writer<W: Write> { /* private fields */ }

PNG writer

Progresses through the image by writing images, frames, or raw individual chunks. This is constructed through [Encoder::write_header()].

FIXME: Writing of animated chunks might be clearer if we had an adapter that you would call to guarantee the next image to be prefaced with a fcTL-chunk, and all other chunks would be guaranteed to be IDAT/not affected by APNG's frame control.

Implementations

impl<W: Write> Writer<W>

fn write_chunk(&mut self, name: ChunkType, data: &[u8]) -> Result<(), EncodingError>

Write a raw chunk of PNG data.

This function calculates the required CRC sum so this should not be included in the input data, otherwise the data is not filtered in any way. This function returns an error if the length of data can't be parsed as a u32 though the length of the chunk data should not exceed i32::MAX or 2,147,483,647.

fn write_text_chunk<T: EncodableTextChunk>(&mut self, text_chunk: &T) -> Result<(), EncodingError>
fn write_image_data(&mut self, data: &[u8]) -> Result<(), EncodingError>

Writes the next image data.

fn set_filter(&mut self, filter: Filter)

Set the used filter type.

The default filter is Filter::Adaptive which automatically selects the best filter for each row of the image.

You should only change this if you are after very fast compression, and either don't care about compression ratio or know exactly what works best for your images.

fn set_frame_delay(&mut self, numerator: u16, denominator: u16) -> Result<(), EncodingError>

Set the fraction of time the following frames are going to be displayed, in seconds

If the denominator is 0, it is to be treated as if it were 100 (that is, the numerator then specifies 1/100ths of a second). If the value of the numerator is 0 the decoder should render the next frame as quickly as possible, though viewers may impose a reasonable lower bound.

This method will return an error if the image is not animated.

fn set_frame_dimension(&mut self, width: u32, height: u32) -> Result<(), EncodingError>

Set the dimension of the following frames.

This function will return an error when:

  • The image is not an animated;

  • The selected dimension, considering also the current frame position, goes outside the image boundaries;

  • One or both the width and height are 0;

fn set_frame_position(&mut self, x: u32, y: u32) -> Result<(), EncodingError>

Set the position of the following frames.

An error will be returned if:

  • The image is not animated;

  • The selected position, considering also the current frame dimension, goes outside the image boundaries;

fn reset_frame_dimension(&mut self) -> Result<(), EncodingError>

Set the frame dimension to occupy all the image, starting from the current position.

To reset the frame to the full image size reset_frame_position should be called first.

This method will return an error if the image is not animated.

fn reset_frame_position(&mut self) -> Result<(), EncodingError>

Set the frame position to (0, 0).

Equivalent to calling set_frame_position(0, 0).

This method will return an error if the image is not animated.

fn set_blend_op(&mut self, op: BlendOp) -> Result<(), EncodingError>

Set the blend operation for the following frames.

The blend operation specifies whether the frame is to be alpha blended into the current output buffer content, or whether it should completely replace its region in the output buffer.

See the BlendOp documentation for the possible values and their effects.

Note that for the first frame the two blend modes are functionally equivalent due to the clearing of the output buffer at the beginning of each play.

This method will return an error if the image is not animated.

fn set_dispose_op(&mut self, op: DisposeOp) -> Result<(), EncodingError>

Set the dispose operation for the following frames.

The dispose operation specifies how the output buffer should be changed at the end of the delay (before rendering the next frame)

See the DisposeOp documentation for the possible values and their effects.

Note that if the first frame uses DisposeOp::Previous it will be treated as DisposeOp::Background.

This method will return an error if the image is not animated.

fn stream_writer(&mut self) -> Result<StreamWriter<'_, W>, EncodingError>

Create a stream writer.

This allows you to create images that do not fit in memory. The default chunk size is 4K, use stream_writer_with_size to set another chunk size.

This borrows the writer which allows for manually appending additional chunks after the image data has been written.

fn stream_writer_with_size(&mut self, size: usize) -> Result<StreamWriter<'_, W>, EncodingError>

Create a stream writer with custom buffer size.

See stream_writer.

fn into_stream_writer(self) -> Result<StreamWriter<'static, W>, EncodingError>

Turn this into a stream writer for image data.

This allows you to create images that do not fit in memory. The default chunk size is 4K, use stream_writer_with_size to set another chunk size.

fn into_stream_writer_with_size(self, size: usize) -> Result<StreamWriter<'static, W>, EncodingError>

Turn this into a stream writer with custom buffer size.

See into_stream_writer.

fn finish(self) -> Result<(), EncodingError>

Consume the stream writer with validation.

Unlike a simple drop this ensures that the final chunk was written correctly. When other validation options (chunk sequencing) had been turned on in the configuration then it will also do a check on their correctness before writing the final chunk.

Trait Implementations

impl<W: Write> Drop for Writer<W>

fn drop(&mut self)

Auto Trait Implementations

impl<W> Freeze for Writer<W> where W: Freeze,

impl<W> RefUnwindSafe for Writer<W> where W: RefUnwindSafe,

impl<W> Send for Writer<W> where W: Send,

impl<W> Sync for Writer<W> where W: Sync,

impl<W> Unpin for Writer<W> where W: Unpin,

impl<W> UnsafeUnpin for Writer<W> where W: UnsafeUnpin,

impl<W> UnwindSafe for Writer<W> where W: UnwindSafe,

Blanket Implementations

impl<T> Any for Writer<W> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Writer<W> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Writer<W> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for Writer<W>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for Writer<W> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Writer<W> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Writer<W> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>