Skip to main content

DecodeImage

Trait DecodeImage 

Source
pub trait DecodeImage<P: Pixel> {
    // Required method
    fn decode_image(&self, data: &[u8]) -> Result<ImageBuf<P>>;

    // Provided method
    fn decode_image_into(
        &self,
        data: &[u8],
        dst: &mut ImageBuf<P>,
    ) -> Result<()> { ... }
}
Expand description

Decodes a compressed byte stream into an owned ImageBuf of pixel layout P.

P selects the layout the caller wants back; a codec implements this for each layout it can present (converting internally as needed, e.g. grayscale → Rgb8). Returning an owned ImageBuf keeps the dimensions, samples, and layout brand together so the result can’t be misinterpreted.

Required Methods§

Source

fn decode_image(&self, data: &[u8]) -> Result<ImageBuf<P>>

Decode data into a fresh ImageBuf.

§Errors

Returns Error::InvalidInput if data is malformed, or Error::Unsupported if it uses a feature that is not implemented or cannot be presented as P.

Provided Methods§

Source

fn decode_image_into(&self, data: &[u8], dst: &mut ImageBuf<P>) -> Result<()>

Decode data into dst, reusing its allocation where possible.

The default forwards to DecodeImage::decode_image; a codec may override it to refill dst’s backing storage in place across repeated calls.

§Errors

As DecodeImage::decode_image.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§