Struct png::Reader

source ·
pub struct Reader<R: Read> {
    decoder: ReadDecoder<R>,
    bpp: BytesPerPixel,
    subframe: SubframeInfo,
    remaining_frames: usize,
    unfiltering_buffer: UnfilteringBuffer,
    transform: Transformations,
    transform_fn: Option<Box<dyn Fn(&[u8], &mut [u8], &Info<'_>) + Send + Sync>>,
    scratch_buffer: Vec<u8>,
    finished: bool,
}
Expand description

PNG reader (mostly high-level interface)

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

Fields§

§decoder: ReadDecoder<R>§bpp: BytesPerPixel§subframe: SubframeInfo§remaining_frames: usize

How many frames remain to be decoded. Decremented after each IDAT or fdAT sequence.

§unfiltering_buffer: UnfilteringBuffer

Buffer with not-yet-unfilter-ed image rows

§transform: Transformations

Output transformations

§transform_fn: Option<Box<dyn Fn(&[u8], &mut [u8], &Info<'_>) + Send + Sync>>

Function that can transform decompressed, unfiltered rows into final output. See the transform.rs module for more details.

§scratch_buffer: Vec<u8>

This buffer is only used so that next_row and next_interlaced_row can return reference to a byte slice. In a future version of this library, this buffer will be removed and next_row and next_interlaced_row will write directly into a user provided output buffer.

§finished: bool

Whether ImageEnd was already reached by fn finish.

Implementations§

source§

impl<R: Read> Reader<R>

source

pub 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].

source

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

Reads all meta data until the next frame data starts. Requires IHDR before the IDAT and fcTL before fdAT.

source

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

Get information on the image.

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

source

pub 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 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.

source

fn mark_subframe_as_consumed_and_flushed(&mut self)

source

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

Advance over the rest of data for this (sub-)frame. Called after decoding the last row of a frame.

source

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

Returns the next processed row of the image

source

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

Returns the next processed row of the image

source

pub 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

source

fn next_interlaced_row_impl( &mut self, rowlen: usize, output_buffer: &mut [u8], ) -> Result<(), DecodingError>

Fetch the next interlaced row and filter it according to our own transformations.

source

pub 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::frames`.

source

pub fn output_buffer_size(&self) -> usize

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

source

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

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

source

fn next_raw_interlaced_row( &mut self, rowlen: usize, ) -> Result<(), DecodingError>

Unfilter the next raw interlaced row into self.unfiltering_buffer.

Auto Trait Implementations§

§

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

§

impl<R> !RefUnwindSafe for Reader<R>

§

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

§

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

§

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

§

impl<R> !UnwindSafe for Reader<R>

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.