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) -> Self

Returns 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) -> Channels

Returns the inferred number of channels.

const fn header(&self) -> &Header

Returns the header that will be stored in the encoded image.

fn required_buf_len(&self) -> usize

The 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 implements Write, it would more effficient to use a specialized method instead: Encoder::encode_to_buf.

Auto Trait Implementations

impl<'a> Freeze for Encoder<'a>

impl<'a> RefUnwindSafe for Encoder<'a>

impl<'a> Send for Encoder<'a>

impl<'a> Sync for Encoder<'a>

impl<'a> Unpin for Encoder<'a>

impl<'a> UnsafeUnpin for Encoder<'a>

impl<'a> UnwindSafe for Encoder<'a>

Blanket Implementations

impl<T> Any for Encoder<'a> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Encoder<'a> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Encoder<'a> where T: ?Sized,

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

impl<T> From<T> for Encoder<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for Encoder<'a> 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 Encoder<'a> where U: Into<T>,

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

impl<T, U> TryInto<U> for Encoder<'a> where U: TryFrom<T>,

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