Skip to main content

Crate denise_image

Crate denise_image 

Source
Expand description

Image decoding for Denise: bytes in, premultiplied pixels out.

let bytes = std::fs::read("logo.png")?;
let picture = denise_image::decode(&bytes)?;
let (pixels, size) = picture.into_parts();
// denise_ui::widgets::Image::new(pixels, size)

decode recognises the format from the bytes; the per-format functions exist for callers that already know. Every decoder produces the same thing: tightly packed rows of premultiplied 0xAARRGGBB, which is exactly what Canvas::blit and the Image widget in denise-ui consume. The multiply by alpha happens here, once, so drawing never pays it.

§Formats, and what each costs

FormatDecoderFeature
PNG (including APNG’s first frame)the png cratepng, default
JPEGthe zune-jpeg cratejpeg, default
GIF (first frame)the gif crategif, default
BMP, uncompressed 24/32-bitthis crate, ~100 linesalways

Each decoder is a cargo feature so a panel pays binary size only for the formats it ships — the same arrangement as truetype/shaping in denise-text. The measured costs are in the README. BMP is not gated because the hand-rolled decoder is smaller than the gate would be.

Animated GIFs decode to their first frame — deliberately. Playback is a frame cache times the animation clock, and belongs to a later issue; the gif crate underneath streams frames, so nothing here forecloses it.

§What this crate refuses to do

No file I/O — the application reads bytes and passes them, because a decoder that opens paths is unusable over the FFI and wrong in an embedded toolkit. No scaling — that is the rasteriser’s job, at draw time. And nothing decodes to more than MAX_PIXELS pixels: a panel toolkit has no business allocating a third of a small board’s RAM because a file’s header asked it to.

Structs§

Picture
Decoded pixels: tightly packed premultiplied 0xAARRGGBB rows.

Enums§

DecodeError
Why a decode failed.

Constants§

MAX_PIXELS
The most pixels a decode is willing to produce: 32 megapixels, which is 128 MiB of u32 — past every real panel asset and comfortably inside what a header lying about its dimensions could otherwise make decode allocate.

Functions§

decode
Decodes an image, recognising the format from the bytes themselves.
decode_bmp
Decodes an uncompressed 24- or 32-bit BMP — which is virtually every BMP actually in circulation. Bottom-up and top-down rows both handled.
decode_gifgif
Decodes a GIF to its first frame, composed at the file’s full logical size — a frame smaller than the screen lands at its offset on transparent pixels, exactly as a viewer would show it.
decode_jpegjpeg
Decodes a JPEG. Greyscale and CMYK files come out as the colour they show.
decode_pngpng
Decodes a PNG. Palette, greyscale and 16-bit files are expanded to 8-bit colour by the decoder; an APNG decodes to its first frame.