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
impl QoiEncoder
Sourcepub const fn new(
input: &[u8],
width: u32,
height: u32,
channels: u8,
colorspace: u8,
) -> Result<(Self, QoiHeader), QoiError>
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.
Sourcepub const fn process_pixels<const N: usize>(
self,
input: &[u8],
output: [u8; N],
) -> Result<QoiEncoderProgress<N>, QoiError>
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.