Struct Encoder
pub struct Encoder<'a> { /* private fields */ }
Encode QOI images into buffers or into streams.
Implementations
impl<'a> Encoder<'a>
fn new(data: &'a impl AsRef<[u8]> + ?Sized, width: u32, height: u32) -> Result<Self>Creates a new encoder from a given array of pixel data and image dimensions.
The number of channels will be inferred automatically (the valid values are 3 or 4). The color space will be set to sRGB by default.
const fn with_colorspace(self, colorspace: ColorSpace) -> SelfReturns a new encoder with modified color space.
Note: the color space doesn't affect encoding or decoding in any way, it's a purely informative field that's stored in the image header.
const fn channels(&self) -> ChannelsReturns the inferred number of channels.
const fn header(&self) -> &HeaderReturns the header that will be stored in the encoded image.
fn required_buf_len(&self) -> usizeThe maximum number of bytes the encoded image will take.
Can be used to pre-allocate the buffer to encode the image into.
fn encode_to_buf(&self, buf: impl AsMut<[u8]>) -> Result<usize>Encodes the image to a pre-allocated buffer and returns the number of bytes written.
The minimum size of the buffer can be found via
Encoder::required_buf_len.fn encode_to_vec(&self) -> Result<Vec<u8>>Encodes the image into a newly allocated vector of bytes and returns it.
fn encode_to_stream<W: Write>(&self, writer: &mut W) -> Result<usize>Encodes the image directly to a generic writer that implements
Write.Note: while it's possible to pass a
&mut [u8]slice here since it implementsWrite, it would more effficient to use a specialized method instead:Encoder::encode_to_buf.