Struct png::StreamingDecoder

source ·
pub struct StreamingDecoder {
    state: Option<State>,
    current_chunk: ChunkState,
    inflater: ZlibStream,
    pub(crate) info: Option<Info<'static>>,
    current_seq_no: Option<u32>,
    have_idat: bool,
    ready_for_idat_chunks: bool,
    ready_for_fdat_chunks: bool,
    have_iccp: bool,
    decode_options: DecodeOptions,
    pub(crate) limits: Limits,
}
Expand description

PNG StreamingDecoder (low-level interface)

By default, the decoder does not verify Adler-32 checksum computation. To enable checksum verification, set it with StreamingDecoder::set_ignore_adler32 before starting decompression.

Fields§

§state: Option<State>§current_chunk: ChunkState§inflater: ZlibStream

The inflater state handling consecutive IDAT and fdAT chunks.

§info: Option<Info<'static>>

The complete image info read from all prior chunks.

§current_seq_no: Option<u32>

The animation chunk sequence number.

§have_idat: bool

Whether we have already seen a start of an IDAT chunk. (Used to validate chunk ordering - some chunk types can only appear before or after an IDAT chunk.)

§ready_for_idat_chunks: bool

Whether we are ready for a start of an IDAT chunk sequence. Initially true and set to false when the first sequence of consecutive IDAT chunks ends.

§ready_for_fdat_chunks: bool

Whether we are ready for a start of an fdAT chunk sequence. Initially false. Set to true after encountering an fcTL chunk. Set to false when a sequence of consecutive fdAT chunks ends.

§have_iccp: bool

Whether we have already seen an iCCP chunk. Used to prevent parsing of duplicate iCCP chunks.

§decode_options: DecodeOptions§limits: Limits

Implementations§

source§

impl StreamingDecoder

source

pub fn new() -> StreamingDecoder

Creates a new StreamingDecoder

Allocates the internal buffers.

source

pub fn new_with_options(decode_options: DecodeOptions) -> StreamingDecoder

source

pub fn reset(&mut self)

Resets the StreamingDecoder

source

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

Provides access to the inner info field

source

pub fn set_ignore_text_chunk(&mut self, ignore_text_chunk: bool)

source

pub fn set_ignore_iccp_chunk(&mut self, ignore_iccp_chunk: bool)

source

pub fn ignore_adler32(&self) -> bool

Return whether the decoder is set to ignore the Adler-32 checksum.

source

pub fn set_ignore_adler32(&mut self, ignore_adler32: bool) -> bool

Set whether to compute and verify the Adler-32 checksum during decompression. Return true if the flag was successfully set.

The decoder defaults to true.

This flag cannot be modified after decompression has started until the StreamingDecoder is reset.

source

pub fn set_ignore_crc(&mut self, ignore_crc: bool)

Set whether to compute and verify the Adler-32 checksum during decompression.

The decoder defaults to false.

source

pub fn set_skip_ancillary_crc_failures( &mut self, skip_ancillary_crc_failures: bool, )

Ignore ancillary chunks if CRC fails

Defaults to true

source

pub fn update( &mut self, buf: &[u8], image_data: &mut Vec<u8>, ) -> Result<(usize, Decoded), DecodingError>

Low level StreamingDecoder interface.

Allows to stream partial data to the encoder. Returns a tuple containing the bytes that have been consumed from the input buffer and the current decoding result. If the decoded chunk was an image data chunk, it also appends the read data to image_data.

source

fn next_state( &mut self, buf: &[u8], image_data: &mut Vec<u8>, ) -> Result<(usize, Decoded), DecodingError>

source

fn parse_u32( &mut self, kind: U32ValueKind, u32_be_bytes: &[u8], image_data: &mut Vec<u8>, ) -> Result<Decoded, DecodingError>

source

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

source

fn parse_chunk(&mut self, type_str: ChunkType) -> Result<Decoded, DecodingError>

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

fn split_keyword(buf: &[u8]) -> Result<(&[u8], &[u8]), DecodingError>

source

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

source

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

source

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

Trait Implementations§

source§

impl Default for StreamingDecoder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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>,

§

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>,

§

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.