pub struct Encoder<'a> {
data: &'a [u8],
header: Header,
}
Expand description
Encode QOI images into buffers or into streams.
Fields§
§data: &'a [u8]
§header: Header
Implementations§
source§impl<'a> Encoder<'a>
impl<'a> Encoder<'a>
sourcepub fn new(
data: &'a (impl AsRef<[u8]> + ?Sized),
width: u32,
height: u32,
) -> Result<Self>
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 number of channels will be inferred automatically (the valid values are 3 or 4). The color space will be set to sRGB by default.
sourcepub const fn with_colorspace(self, colorspace: ColorSpace) -> Self
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.
sourcepub const fn header(&self) -> &Header
pub const fn header(&self) -> &Header
Returns the header that will be stored in the encoded image.
sourcepub fn required_buf_len(&self) -> usize
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.
sourcepub fn encode_to_buf(&self, buf: impl AsMut<[u8]>) -> Result<usize>
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
.
sourcepub fn encode_to_vec(&self) -> Result<Vec<u8>>
pub fn encode_to_vec(&self) -> Result<Vec<u8>>
Encodes the image into a newly allocated vector of bytes and returns it.
sourcepub fn encode_to_stream<W: Write>(&self, writer: &mut W) -> Result<usize>
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
.