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>>
impl<'a> Decoder<Bytes<'a>>
sourcepub fn new(data: &'a (impl AsRef<[u8]> + ?Sized)) -> Result<Self>
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§impl<R: Read> Decoder<R>
impl<R: Read> Decoder<R>
sourcepub fn from_stream(reader: R) -> Result<Self>
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
.
sourcepub fn into_reader(self) -> R
pub fn into_reader(self) -> R
Consumes the decoder and returns the underlying reader back.
source§impl<R: Reader> Decoder<R>
impl<R: Reader> Decoder<R>
fn new_impl(reader: R) -> Result<Self>
sourcepub const fn with_channels(self, channels: Channels) -> Self
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).
sourcepub const fn channels(&self) -> Channels
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.
sourcepub const fn required_buf_len(&self) -> usize
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.
sourcepub fn decode_to_buf(&mut self, buf: impl AsMut<[u8]>) -> Result<usize>
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
.
sourcepub fn decode_to_vec(&mut self) -> Result<Vec<u8>>
pub fn decode_to_vec(&mut self) -> Result<Vec<u8>>
Decodes the image into a newly allocated vector of bytes and returns it.