Struct Decoder

pub struct Decoder<R> { /* private fields */ }

Decode QOI images from slices or from streams.

Implementations

impl<'a> Decoder<Bytes<'a>>

fn new(data: &'a impl AsRef<[u8]> + ?Sized) -> Result<Self>

Creates a new decoder from a slice of bytes.

The header will be decoded immediately upon construction.

Note: this provides the most efficient decoding, but requires the source data to be loaded in memory in order to decode it. In order to decode from a generic stream, use Decoder::from_stream instead.

const fn data(&self) -> &[u8]

Returns the undecoded tail of the input slice of bytes.

impl<R: Read> Decoder<R>

fn from_stream(reader: R) -> Result<Self>

Creates a new decoder from a generic reader that implements Read.

The header will be decoded immediately upon construction.

Note: while it's possible to pass a &[u8] slice here since it implements Read, it would be more efficient to use a specialized constructor instead: Decoder::new.

const fn reader(&self) -> &R

Returns an immutable reference to the underlying reader.

fn into_reader(self) -> R

Consumes the decoder and returns the underlying reader back.

impl<R: Reader> Decoder<R>

const fn with_channels(self, channels: Channels) -> Self

Returns a new decoder with modified number of channels.

By default, the number of channels in the decoded image will be equal to whatever is specified in the header. However, it is also possible to decode RGB into RGBA (in which case the alpha channel will be set to 255), and vice versa (in which case the alpha channel will be ignored).

const fn channels(&self) -> Channels

Returns the number of channels in the decoded image.

Note: this may differ from the number of channels specified in the header.

const fn header(&self) -> &Header

Returns the decoded image header.

const fn required_buf_len(&self) -> usize

The number of bytes the decoded image will take.

Can be used to pre-allocate the buffer to decode the image into.

fn decode_to_buf(&mut self, buf: impl AsMut<[u8]>) -> Result<usize>

Decodes the image to a pre-allocated buffer and returns the number of bytes written.

The minimum size of the buffer can be found via Decoder::required_buf_len.

fn decode_to_vec(&mut self) -> Result<Vec<u8>>

Decodes the image into a newly allocated vector of bytes and returns it.

Trait Implementations

impl<R: Clone> Clone for Decoder<R>

fn clone(&self) -> Decoder<R>

Auto Trait Implementations

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

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

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

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

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

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

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

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> CloneToUninit for Decoder<R> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Decoder<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Decoder<R> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

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

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

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