Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder {
    // Required methods
    fn probe(
        &self,
        bytes: &[u8],
        ext: &str,
    ) -> Result<MediaMetadata, MediaError>;
    fn decode(
        &self,
        bytes: &[u8],
        ext: &str,
    ) -> Result<DecodedImage, MediaError>;
}
Expand description

The still-decode seam.

A trait with exactly one production implementation (RawshiftDecoder), and that is the point: the failure modes worth testing — a panicking decoder, a decoder that reports dimensions its buffer does not match — cannot be produced from real bytes on demand, so they are injected.

Required Methods§

Source

fn probe(&self, bytes: &[u8], ext: &str) -> Result<MediaMetadata, MediaError>

Read the format, dimensions and orientation from the header without decoding pixels.

§Errors

MediaError::NotAStillImage when nothing recognisable is there, MediaError::UnsupportedFormat when the format has no decoder in this build, and MediaError::PixelBudgetExceeded when the header claims more than MAX_DECODE_PIXELS.

Source

fn decode(&self, bytes: &[u8], ext: &str) -> Result<DecodedImage, MediaError>

Decode to upright, packed RGBA8. Probes first, so every probe error is also a decode error.

§Errors

As probe, plus MediaError::Decode when a supported format’s bytes do not decode and MediaError::BufferLengthMismatch / MediaError::ZeroDimension when the decoder’s own output is inconsistent.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§