Struct qoi::decode::Decoder

source ·
pub struct Decoder<R> {
    reader: R,
    header: Header,
    channels: Channels,
}
Expand description

Decode QOI images from slices or from streams.

Fields§

§reader: R§header: Header§channels: Channels

Implementations§

source§

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

source

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

source

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

Returns the undecoded tail of the input slice of bytes.

source§

impl<R: Read> Decoder<R>

source

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

source

pub const fn reader(&self) -> &R

Returns an immutable reference to the underlying reader.

source

pub fn into_reader(self) -> R

Consumes the decoder and returns the underlying reader back.

source§

impl<R: Reader> Decoder<R>

source

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

source

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

source

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

source

pub const fn header(&self) -> &Header

Returns the decoded image header.

source

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

source

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

source

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

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

Trait Implementations§

source§

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

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> UnwindSafe for Decoder<R>
where R: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.