Struct gif::Decoder

source ·
pub struct Decoder<R: Read> {
    decoder: ReadDecoder<R>,
    pixel_converter: PixelConverter,
    bg_color: Option<u8>,
    repeat: Repeat,
    current_frame: Frame<'static>,
    current_frame_data_type: FrameDataType,
}
Expand description

GIF decoder. Create DecodeOptions to get started, and call DecodeOptions::read_info.

Fields§

§decoder: ReadDecoder<R>§pixel_converter: PixelConverter§bg_color: Option<u8>§repeat: Repeat§current_frame: Frame<'static>§current_frame_data_type: FrameDataType

Implementations§

source§

impl<R> Decoder<R>
where R: Read,

source

pub fn new(reader: R) -> Result<Self, DecodingError>

Create a new decoder with default options.

source

pub fn build() -> DecodeOptions

Return a builder that allows configuring limits etc.

source

fn with_no_init( reader: R, decoder: StreamingDecoder, options: DecodeOptions, ) -> Decoder<R>

source

fn init(self) -> Result<Self, DecodingError>

source

pub fn next_frame_info( &mut self, ) -> Result<Option<&Frame<'static>>, DecodingError>

Returns the next frame info

source

pub fn read_next_frame( &mut self, ) -> Result<Option<&Frame<'static>>, DecodingError>

Reads the next frame from the image.

Do not call Self::next_frame_info beforehand. Deinterlaces the result.

You can also call .into_iter() on the decoder to use it as a regular iterator.

source

fn take_current_frame(&mut self) -> Option<Frame<'static>>

This is private for iterator’s use

source

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

Reads the data of the current frame into a pre-allocated buffer.

Self::next_frame_info needs to be called beforehand. The length of buf must be at least Self::buffer_size. Deinterlaces the result.

source

fn copy_lzw_into_buffer( &mut self, min_code_size: u8, buf: &mut Vec<u8>, ) -> Result<(), DecodingError>

source

pub fn fill_buffer(&mut self, buf: &mut [u8]) -> Result<bool, DecodingError>

Reads data of the current frame into a pre-allocated buffer until the buffer has been filled completely.

The buffer length must be an even number of pixels (multiple of 4 if decoding RGBA).

Self::next_frame_info needs to be called beforehand. Returns true if the supplied buffer could be filled completely. Should not be called after false had been returned.

source

pub fn buffer_size(&self) -> usize

Output buffer size

source

pub fn line_length(&self) -> usize

Line length of the current frame

source

pub fn palette(&self) -> Result<&[u8], DecodingError>

Returns the color palette relevant for the frame that has been decoded

source

pub fn global_palette(&self) -> Option<&[u8]>

The global color palette

source

pub fn width(&self) -> u16

Width of the image

source

pub fn height(&self) -> u16

Height of the image

source

pub fn into_inner(self) -> BufReader<R>

Abort decoding and recover the io::Read instance

source

pub fn bg_color(&self) -> Option<usize>

Index of the background color in the global palette

In practice this is not used, and the background is always transparent

source

pub fn repeat(&self) -> Repeat

Number of loop repetitions

Trait Implementations§

source§

impl<R: Read> IntoIterator for Decoder<R>

source§

type Item = Result<Frame<'static>, DecodingError>

The type of the elements being iterated over.
source§

type IntoIter = DecoderIter<R>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

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

§

impl<R> !RefUnwindSafe for Decoder<R>

§

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

§

impl<R> !Sync for Decoder<R>

§

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

§

impl<R> !UnwindSafe for Decoder<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.