Skip to main content

decode_image

Function decode_image 

Source
pub fn decode_image(
    doc: &Document,
    dict: &Dict,
    raw: &[u8],
    inline: bool,
) -> Result<CodedImage, ImageCodecError>
Expand description

Decode an image stream through its /Filter chain.

Runs the byte-stream prefix of the chain through pdfcer_model::filters, then dispatches the single terminal image codec. A chain with no terminal codec still succeeds — it yields a CodedImage with codec: None and CodecColorModel::Unspecified, so the caller has one entry point for every image rather than two code paths that can drift.

  • doc resolves indirect values in the image and parameter dictionaries, and will resolve /JBIG2Globals (Table 12) and the /Height fallback for CCITT’s absent /Rows when those codecs land.
  • dict is the image dictionary (Table 89) or an inline image’s already-normalized parameter dictionary.
  • raw is the still-encoded stream data.
  • inline selects §8.9.7’s stricter filter rules.

This is the base-revision entry point, kept with its original &Document signature so that every existing caller — the four image_codec_* fuzz targets, this module’s own tests, the cmyk_variants acceptance test — is untouched by decision 018. It is a thin wrapper over decode_image_view; a caller that must decode an image as an editing session currently has it calls that directly.

§Errors

ImageCodecError — every failure is structured and names the codec, and the specific unsupported feature where one applies (rule R27). This function does not panic on any input; the image_codec_dct fuzz target asserts it.