QoiEncoder

Struct QoiEncoder 

Source
pub struct QoiEncoder { /* private fields */ }
Expand description

A streaming encoder for the QOI image format.

To generate a QoiEncoder and retrieve a QoiHeader you must input the pixel data as a slice of bytes.
To encode the image you must process the pixels by inputting an array to be used as a buffer.
You can then match on QoiEncoderProgress to retrieve your buffer and either the encoder (to continue processing more pixels) or the amount of bytes that are considered free space in your buffer.

Implementations§

Source§

impl QoiEncoder

Source

pub const fn new( input: &[u8], width: u32, height: u32, channels: u8, colorspace: u8, ) -> Result<(Self, QoiHeader), QoiError>

Generates a QoiEncoder and a QoiHeader from the input bytes of pixel data.

The channels and colorspace values are purely informative and will be used to populate the returned header.

The channels value is meant to specify whether the input data is 3 byte pixels (RGB) or 4 byte pixels (RGBA). The encoder will compare the specified width and height with the length of the input data to determine whether the input data represents 3 or 4 byte pixels. This means you can input a valid but incorrect value for channels and it will be used for the returned header but the encoder will process the input bytes correctly.

§Errors

Will return Err if the following is true:

1: The width or height values are 0.
2: The channels value is not 3 (RGB) or 4 (RGBA).
3: The colorspace value is not 0 (sRGB with linear alpha) or 1 (all channels linear).
4: The amount of bytes in input are not divisible by the specified channels value.
5: The specified width and height calculate to a different amount of pixels compared to the input bytes.

Source

pub const fn process_pixels<const N: usize>( self, input: &[u8], output: [u8; N], ) -> Result<QoiEncoderProgress<N>, QoiError>

Processes the input bytes as pixel data and fills the output buffer with bytes representing QOI data chunks.

The minimum size buffer required is 5 bytes. This is equivalent to the largest returnable QOI data chunk.

§Errors

Will return Err if output buffer is less than 5 bytes.

Auto Trait Implementations§

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.