Skip to main content

EncodeImage

Trait EncodeImage 

Source
pub trait EncodeImage<P: Pixel> {
    // Required method
    fn encode_image(
        &self,
        image: ImageRef<'_, P>,
        out: &mut Vec<u8>,
    ) -> Result<usize>;
}
Expand description

Encodes an ImageRef of a specific pixel layout P into a compressed byte stream.

A codec implements this once per pixel layout it supports (impl EncodeImage<Rgb8> for …, impl EncodeImage<Cmyk8> for …, …), so asking it to encode an unsupported layout is a compile error rather than a runtime Unsupported. The input is pre-validated by ImageRef::new, so an implementation never re-checks the buffer length. Bytes are appended to out to keep callers that reuse a scratch buffer allocation-conscious.

Required Methods§

Source

fn encode_image( &self, image: ImageRef<'_, P>, out: &mut Vec<u8>, ) -> Result<usize>

Encode image into out (appended), returning the number of bytes written.

§Errors

Returns Error::Unsupported if the requested encoder configuration is not implemented, or Error::InvalidInput if the image violates a format constraint (e.g. a dimension limit).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§