Struct qoi::Encoder

source ·
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>

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