Expand description
Image decoding for Valo: encoded bytes in, drawable Images out.
The engine itself never decodes (hosts upload images); this crate is the optional piece a host
adds when it wants Valo to do that job. It has no codecs of its own. A host registers
Decoders — the platform’s native one first where it exists, a portable software one as
fallback — and an ImageLoader tries them in that order for each image.
Decoders produce pixels or a texture; the loader alone turns those into images through
ImageContext. That split is what lets a native codec deliver a texture
it already decoded into GPU-shared memory, with no readback, while software decoders never
touch the GPU.
Results arrive as Pending values, which are futures. With ImageLoader::new the work
runs inside the first poll, on the polling thread — the shape for a single-threaded host or
the web. With ImageLoader::with_worker (the worker feature) a dedicated thread decodes and
uploads, and the poll wakes when the image is ready.
use valo_codec::{DecodeOptions, ImageLoader};
let loader = ImageLoader::new(context.image_context(), decoders);
let options = DecodeOptions { max_size: Some([512, 512]), mipmaps: true, ..Default::default() };
let image = loader.decode(bytes, options).await?;Structs§
- Codec
- Codec is an opened image whose frames are decoded one at a time, on request.
- Declined
- Declined records one decoder passing on an image.
- Decode
Limits - DecodeLimits bounds what a decode may consume, so hostile bytes cannot exhaust memory.
- Decode
Options - DecodeOptions says how large a decode may be and what the caller wants out of it.
- Decoded
Frame - DecodedFrame is one complete frame as a decoder produced it, before it becomes an image.
- Frame
- Frame is one decoded frame, ready to draw.
- Image
Info - ImageInfo is what is known about an image once it is open, before any frame is decoded.
- Image
Loader - ImageLoader decodes encoded images into drawable
Images with registered decoders. - Open
Request - OpenRequest is everything a decoder needs to open one image.
- Pending
- Pending is a decode result on its way.
Enums§
- Decode
Error - DecodeError is why a decode did not produce an image.
- Frame
Pixels - FramePixels is what a decoder hands back — never an image; the loader makes those.
- Open
Error - OpenError is why a decoder did not open an image.
- Repetition
- Repetition is how an animation continues once it has played through.
Traits§
- Decoder
- Decoder is one codec library, such as Apple’s ImageIO or the portable
imagecrate. - Frame
Reader - FrameReader is one opened image, yielding complete composited frames in order.
Functions§
- fit_
within fit_withinscalessourcedown to fitbounds, keeping its aspect ratio and never returning a zero side. A source that already fits is returned unchanged.
Type Aliases§
- Decoding
- Decoding is an answer a decoder is still working on.