Encoder

Struct Encoder 

Source
pub struct Encoder<'a> { /* private fields */ }
Expand description

Encode QOI images into buffers or into streams.

Implementations§

Source§

impl<'a> Encoder<'a>

Source

pub 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 data must be in RGB(A) order, without fill borders (extra stride).

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.

Source

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

Source

pub const fn channels(&self) -> Channels

Returns the inferred number of channels.

Source

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

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

Source

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

Source

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

Source

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

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

Source

pub 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> UnwindSafe for Encoder<'a>

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