Struct Reader

pub struct Reader<R: BufRead + Seek> { /* private fields */ }

PNG reader (mostly high-level interface)

Provides a high level that iterates over lines or whole images.

Implementations

impl<R: BufRead + Seek> Reader<R>

fn next_frame_info(&mut self) -> Result<&FrameControl, DecodingError>

Advances to the start of the next animation frame and returns a reference to the FrameControl info that describes it. Skips and discards the image data of the previous frame if necessary.

Returns a ParameterError when there are no more animation frames. To avoid this the caller can check if Info::animation_control exists and consult AnimationControl::num_frames.

fn info(&self) -> &Info<'static>

Get information on the image.

The structure will change as new frames of an animated image are decoded.

fn next_frame(&mut self, buf: &mut [u8]) -> Result<OutputInfo, DecodingError>

Decodes the next frame into buf.

Note that this decodes raw subframes that need to be mixed according to blend-op and dispose-op by the caller.

The caller must always provide a buffer large enough to hold a complete frame (the APNG specification restricts subframes to the dimensions given in the image header). The region that has been written be checked afterwards by calling Reader::info after a successful call and inspecting the frame_control data. This requirement may be lifted in a later version of png.

Output lines will be written in row-major, packed matrix with width and height of the read frame (or subframe), all samples are in big endian byte order where this matters.

fn next_row(&mut self) -> Result<Option<Row<'_>>, DecodingError>

Returns the next processed row of the image (discarding InterlaceInfo).

See also Reader::read_row, which reads into a caller-provided buffer.

fn next_interlaced_row(&mut self) -> Result<Option<InterlacedRow<'_>>, DecodingError>

Returns the next processed row of the image.

See also Reader::read_row, which reads into a caller-provided buffer.

fn read_row(&mut self, output_buffer: &mut [u8]) -> Result<Option<InterlaceInfo>, DecodingError>

Reads the next row of the image into the provided output_buffer. Ok(None) will be returned if the current image frame has no more rows.

output_buffer needs to be long enough to accommodate Reader::output_line_size for Info::width (initial interlaced rows may need less than that).

See also Reader::next_row and Reader::next_interlaced_row, which read into a Reader-owned buffer.

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

Read the rest of the image and chunks and finish up, including text chunks or others This will discard the rest of the image if the image is not read already with Reader::next_frame, Reader::next_row or Reader::next_interlaced_row

fn output_color_type(&self) -> (ColorType, BitDepth)

Returns the color type and the number of bits per sample of the data returned by Reader::next_row and Reader::next_frame.

fn output_buffer_size(&self) -> Option<usize>

Return the number of bytes required to hold a deinterlaced image frame that is decoded using the given input transformations.

Returns None if the output buffer does not fit into the memory space of the machine, otherwise returns the byte length in Some. The length is smaller than isize::MAX.

fn output_line_size(&self, width: u32) -> Option<usize>

Returns the number of bytes required to hold a deinterlaced row.

Returns None if the output buffer does not fit into the memory space of the machine, otherwise returns the byte length in Some. The length is smaller than isize::MAX.

Auto Trait Implementations

impl<R> !RefUnwindSafe for Reader<R>

impl<R> !UnwindSafe for Reader<R>

impl<R> Freeze for Reader<R> where ReadDecoder<R>: Freeze,

impl<R> Send for Reader<R> where ReadDecoder<R>: Send,

impl<R> Sync for Reader<R> where ReadDecoder<R>: Sync,

impl<R> Unpin for Reader<R> where ReadDecoder<R>: Unpin,

impl<R> UnsafeUnpin for Reader<R> where ReadDecoder<R>: UnsafeUnpin,

Blanket Implementations

impl<T> Any for Reader<R> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Reader<R> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Reader<R> where T: ?Sized,

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

impl<T> From<T> for Reader<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for Reader<R> 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 Reader<R> where U: Into<T>,

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

impl<T, U> TryInto<U> for Reader<R> where U: TryFrom<T>,

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